The alt attribute on the <img /> HTML tag is not mandatory. However, it is considered a good practice to add it as it provides some good benefits, such as:
- Improving accessibility;
- Helping browsers substitute invalid, broken or unsupported images with the
alttext; - Providing context to search engine crawlers (which can in-turn improve SEO).
If you don't add the alt text for images, then the image information would be inaccessible, for example, to:
- People with visual impairments;
- People who have turned off images in their browsers;
- Non-visual browsers (such as screen readers);
- Visual browsers, for example, when the image can't be displayed;
- Search engine crawlers, bots, etc.
There are instances where you can specify an empty alt attribute (i.e. alt=""). This indicates that the image is not an important part of the content. For example, it could be the case when the image is used as a decoration or a tracking pixel. In such instances, for example, a visual browser may choose to hide the broken image icon.
This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.