alt attribute) in <img>The alt attribute gives a text description of the image.
It might look simple, but it plays a big role in accessibility, usability, and SEO.
Many people use screen readers (software that reads out the text on the screen).
If there is an image, the screen reader reads the alt text aloud.
Example:
<img src="lion.jpg" alt="A lion sitting in the jungle" />
The screen reader will say: “A lion sitting in the jungle”. → This makes the webpage inclusive.
If the image file is missing, broken, or takes too long to load, the alt text is shown instead.
Example:
<img src="unknown.jpg" alt="Beautiful flower in garden" />
If unknown.jpg is not found, the browser shows:
Beautiful flower in garden
alt="Chocolate Cake Recipe", your page might show up when someone searches for “chocolate cake image”.<img src="tajmahal.jpg" alt="The Taj Mahal in Agra, India" width="300" />
👉 If the image loads: You see the Taj Mahal. 👉 If it doesn’t: You see text “The Taj Mahal in Agra, India”.
The alt attribute is important because:
✨ Quick exam line:
The alt attribute in <img> provides alternative text for an image, useful when the image cannot be displayed, for accessibility (screen readers), and for search engines to understand the image.