What is the function of alt of img tag?

hzc
Release: 2020-06-24 15:01:59
Original
11841 people have browsed it

What is the function of alt of img tag?

The alt attribute is a required attribute of the element. It gives the alternative text of the image, which can be used when the image cannot be displayed.

The alt attribute provides alternative information when the user cannot view the image for some reason (for example: slow opening speed, incorrect src attribute, or the user is using a screen reader).

Note: Internet Explorer handles the alt attribute by displaying the alt attribute value as a tooltip when the mouse cursor stays on the image. But according to the HTML specification, this is not the correct way to handle it. Other browsers are standard-compliant and display the alt attribute value when the image cannot be loaded.

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

Extended information

The correct use of alt and title attributes in the img tag:

The img tag has two attributes, namely alt and title. , for many beginners, they are still confused about the correct use of these two attributes. Of course, part of the reason is also caused by the IE browser. Correct use of these two attributes can not only improve the search ability of images, but also be very helpful in terms of user experience.

alt

The essential function of this attribute is to replace the text when the image cannot be displayed correctly, but it also plays the role of title under IE6 ( The text prompt after the mouse is placed), IE's implementation method is actually wrong.

If you want to display a prompt when the mouse rolls over, you should use the title attribute. Due to wrong guidance, many beginners only add the alt attribute to the img tag.

title

The text prompt displayed when the mouse rolls over is very important in terms of user experience. Of course, it is not necessary to add this attribute to all img tags. For example, if the logo is more important or the image content that users will experience, it is recommended that this attribute be added.

Recommended tutorial: "HTML Tutorial"

The above is the detailed content of What is the function of alt of img tag?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!