What is alt Text & Why it Matters in HTML?

Images play a significant role in any application. They are used to improve the website’s appeal and attractiveness. What if your internet connection slows down and the desired image fails to upload? Then, what should be displayed on the screen instead of the image? In such a scenario, HTML permits us to use the attribute “alt” in the HTML <img> element.

This study will guide you about what alt text is and why it matters in HTML.

What is an alt text in HTML?

Sometimes when we scroll through a website, a little text appears when the image fails to download. This HTML component is known as “alt” text, description, or alternate text. It is an attribute associated with the <img> tag of HTML.


To utilize the alt text in HTML, follow the given syntax:

<img src="Image_Path" alt="This is an example alt text">

The description of the above-mentioned syntax is listed below:

  • src”: This attribute is used to specify the path of the source image.
  • alt”: is the alternate text.

Why is alt text Important in HTML?

The alt text is important for many reasons. Some of them are listed below:

  • For better accessibility of the web page, it is better to use alt text as it helps users who are visually impaired to hear the image description by using third-party applications.
  • In place of the image, the value of the alt text attribute will be displayed. This is beneficial when the users experience low bandwidth connections.
  • The alt text also contributes to web page rank in Google’s eyes. It not only provides description but also adds meaning to it, which can be helpful for overall website traffic.

What are the Best Practices of alt text in HTML?

Some of the best practices to use alt text for your website are listed below:

  • Don’t begin the alt text with “picture of” or “image of” words.
  • Limit alt text to 130 characters or less.
  • Keep in mind the SEO.
  • Be precise.

Example 1: Good and Bad alt text in HTML

Let’s take an example and check what type of alternate text should be displayed in place of the image:

Here we have stated the bad and good alternate text for the HTML:

  • Bad alt text: Mountain steps purple flowers.
  • Good alt text: Steps surrounded by purple flowers towards the snow-covered mountain.

It can be observed that the bad alt text is not a description; rather, it is just a list of words. In comparison, the good alt text describes the information about the image.

Example 2: How to Add alt text to HTML <img> Element?

Let’s demonstrate the concept of adding alt text with the help of an example.


In the HTML file, first, add a container that holds the <img> element. This element is associated with the src and alt attributes:

<img src="/images/great-wall.jpg" alt="The Great wall of China at sunset">

Save the HTML file, and the web page will show the image as follows:

Let’s say this image has failed to upload, or we have mistakenly added the wrong path of the image in our HTML file. Then, the specified alt text will be displayed instead of the image:

That’s how you can add alt text to our image using the “alt” attribute in the <img> tag.


HTML permits us to use images for our web application. But sometimes, the user experiences a low bandwidth connection, and the image cannot upload to the application. In such a situation, the “alt” attribute with <img> tag shows alternative text when the image has failed to display. This article explained the alt attribute of the HTML <img> element.

About the author

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.