XHTML is the basis of CSS layout. CuoXIn.com has always emphasized the learning of XHTML knowledge and attaches importance to semantics and document structure. The title and alt attributes give me the most intuitive feeling that they can improve the adaptability of documents and reasonably increase keyword density. In the XHTML standard, the alt attribute of the image is required.
alt attributeFor user agent (UA) that cannot display images, forms, or applets, the alt attribute is used to specify alternative text. The language of the replacement text is specified by the lang attribute. The Alt attribute (note that it is "attribute" instead of "label") includes replacement instructions, which are required for images and image hotspots. It can only be used in img, area and input elements (including applet elements). For input elements, the alt attribute is intended to replace the image of the submit button.
For example: the alt attribute is used to provide text descriptions to viewers who cannot see the images in your document. This includes users who use browsers that do not support image display or image display being turned off, users who are visually impaired and users who use screen readers. Alternative text is used to replace images rather than provide additional caption.
Think carefully before writing replacement text to ensure that those words do provide illustrative information for those who do not see the image and make sense in the context. For decorative images, use empty values (alt="" with no spaces in the middle of quotes) instead of using irrelevant substitutes such as "blue bullet" or "spacer.gif". Don't ignore it. If you ignore it, some screen readers will directly read the file name of the image file, and those text browsers, such as Lynx, will display the file name of the image file, which will be of little use to your browser.
It is easiest to set the replacement text in an image containing text. The text contained in the image can generally be used as the alt attribute value.
title attributeThe title attribute provides suggestions for elements that set this attribute.
The title attribute can be used on all tags except base, basefont, head, html, meta, param, script and title. But it is not necessary. Maybe that's why many people don't understand when to use it.
Use the title attribute to provide non-essential additional information. Most visual browsers display title text as tool tip when the mouse is suspended on a specific element, but this is up to the manufacturer to decide how to render title text. Some browsers will display the title text in the status bar. For example, the earlier version of Safari browser.
The title attribute has a good purpose, which is to add descriptive text to the link, especially when the link itself does not express the purpose of the link very clearly. This allows visitors to know where those links will take them, and they won't load a page that may not be of interest at all. Another potential application is to provide additional illustrative information for images, such as dates or other non-essential information.
The title attribute value can be longer than the alt attribute value. However, it should be noted that some browsers truncate too long text (such as tooltips or other). For example, Mozilla's core browser can only display the first 60 characters. This is considered a Mozilla bug, and it's something you need to pay attention to.