Home >Web Front-end >HTML Tutorial >Talk about the difference between alt and title attributes in HTML tag elements

Talk about the difference between alt and title attributes in HTML tag elements

青灯夜游
青灯夜游forward
2020-10-12 17:53:283004browse

Talk about the difference between alt and title attributes in HTML tag elements

This article will introduce to you the difference between alt and title attributes in HTML tag elements. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Overview

You can probably add a qualifier to this question, but we will exclude the <title> tag from this discussion for the time being.

What is the difference between alt and title attributes?

(Recommended tutorial: html tutorial)

ALT attribute

is most commonly used in <img> tag, let’s first look at the alt attribute of the <img> tag. The

alt attribute is a required attribute that specifies alternative text when the image cannot be displayed.

The alt attribute can provide alternative information for the image if the user is unable to view the image due to the following reasons:

  • The network speed is too slow
  • src Error in attribute
  • Browser disabled image
  • The user is using a screen reader

<img> The alt attribute of the tag specifies the alternative text that is used to replace the content displayed in the browser when the image cannot be displayed or the user disables image display.

It is highly recommended that you use this attribute on every image in your document. This way, even if the image cannot be displayed, the user can still see some information about what is missing. And for people with disabilities, the alt attribute is often the only way they know what the image is about.

Comments and Tips:

Comments: alt The value of the attribute is a string that can contain up to 1024 characters, including spaces and punctuation. This string must be enclosed in quotes. This alt text may contain entity references to special characters, but it is not allowed to contain other categories of markup, and in particular no style tags are allowed.

Note: When the user moves the mouse over the img element, Internet Explorer will display the value of the alt attribute. This behavior is incorrect. All other browsers are moving closer to the specification and will only display alternative text when the image cannot be displayed.

Tip: If you need to create a tooltip for an image, use the title attribute.

Usage and syntax:

Usage: alt Attributes can only be used in img, area and input elements (including applet elements). For the input element, the alt attribute is intended to replace the submit button image. For example:

<input type="image" src="image.gif" alt="Submit" />

Syntax:
Specify the alternative text of the image

alt Principles for using text:

  • If the image contains information - Use alt to describe the image
  • if the image is within a a element - Use alt to describe the target link
  • if the image is only Decoration - Use alt=""
##TITLE attribute

Definition and usage:

title Attributes specify additional information about the element.

This information usually displays a tooltip text when the mouse is moved over the element.

Tip: The

title attribute is often used with the form and a elements to provide information about the input format and link target. It is also a required attribute for the abbr and acronym elements. Of course, the title attribute is widely used and can be used in addition to base, basefont, head, html All tags except , meta, param, script and title. But it's not necessary. The

title attribute has a good use, which is to add descriptive text to the link, especially when the link itself does not clearly express the purpose of the link. This way visitors know where the links will take them, and they won't load a page that they may not be interested in at all. Another potential application is to provide additional descriptive information for images, such as dates or other non-essential information.

TITLE tag

It’s still early to look at it, let’s continue to look at the

<title> tag. The

<title> element defines the title of the document.

Browsers use titles in a special way, and usually place them on the title bar or status bar of the browser window. Likewise, when a document is added to a user's links list or favorites or bookmarks list, the title becomes the default name for the link to the document.

Tip: The

<title> tag is the only thing required to be included in the tag.

Extended reading: What’s in the title?

Be sure to choose a correct title, which is important to define the document and ensure that it can be used effectively on the Web.

Remember that users can access each document in the document set independently, in any order. Therefore, the title of a document should not only be defined in the context of other documents, but also show its own characteristics.

Titles that contain document citation ordering are generally not good titles. For example, a title like "Chapter 16" or "Part 5" does nothing to help the reader understand the content. A more descriptive title, like "Chapter 16: HTML Headings" or "Part 5: How to Use Headings," not only expresses its place within a larger collection, but also explains what the document is about. content, attracting readers to be more interested in reading.

Self-referential titles are also of little use. Titles like "Home Page" have nothing to do with the content, and similar titles include "Feedback Page" or "Frequently Used Links." You should design a title that can convey certain content and purpose so that readers can judge whether it is necessary to visit this page. "What is the difference between alt and title of an element - Issue", this is a descriptive title.

People often spend a lot of time creating web documents, but all of that effort is often wasted just because of an unattractive or meaningless title. When special software that automatically collects links for users became increasingly popular on the Web, only the title of a web page was inserted into the vast database of links as descriptive words related to the page. So we cannot stress this enough: Carefully choose a title for each of your documents that is descriptive, useful, and context-independent.

END.

The above is the detailed content of Talk about the difference between alt and title attributes in HTML tag elements. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete