👀 Live Preview
An image with descriptive alt text (inspect or disable images to see the fallback):
alt="A scenic view of a mountain landscape"
The alt attribute is a fundamental feature in HTML that is primarily used with the <img> (image) element. The purpose of the alt attribute is to provide alternative text for browsers to display when the image cannot be loaded. This text also serves as a description for users who may be using screen readers or have images disabled.
Describe images.
Screen reader support.
When images fail.
Use alt=""
Set alt dynamically.
Search-friendly text.
altThe primary purpose of the alt attribute is to enhance web accessibility by ensuring that users with disabilities or those facing slow internet connections can still understand the content conveyed by images on a webpage. Additionally, it serves as a placeholder when the image itself cannot be rendered.
Every meaningful <img> should have an alt attribute. It is not optional for accessible, standards-compliant HTML.
Add alt to an <img> element with a descriptive string (or empty for decorative images):
<img src="photo.jpg" alt="A scenic view of a mountain landscape"><img> elements (use alt="" if decorative).<area> elements in image maps.The alt attribute accepts a string value that represents the alternative text for the image. This text should be descriptive enough to convey the content and purpose of the image. Proper use of the alt attribute is crucial for making websites more accessible and user-friendly.
alt="A scenic view of a mountain landscape" explains what the image shows.alt="Search" on an icon button describes what the control does.alt="" marks a purely decorative image that assistive tech should ignore.<!-- Informative image -->
<img src="chart.png" alt="Sales grew 24% in Q2 2026">
<!-- Decorative image -->
<img src="divider.svg" alt="">
<!-- Image map area -->
<area shape="rect" coords="0,0,100,100" href="/about" alt="About us">| Image Type | alt Value | Notes |
|---|---|---|
| Informative photo | Describe the content | What would you say if you couldn’t see it? |
| Linked image | Describe the link destination | Same as link text purpose |
| Icon button | Action name | e.g. alt="Close" |
| Decorative | alt="" | No meaningful content |
| Complex chart | Summary + long description | Link to detailed text nearby |
| Applicable elements | img, area | Primary use on images |
| Element | Supported? | Notes |
|---|---|---|
<img> | Yes (required) | Primary and most common use |
<area> | Yes | Clickable regions in image maps |
<input type="image"> | Yes | Submit button styled as image |
<video>, <audio> | No | Use captions or transcripts instead |
Descriptive alt text, dynamic JavaScript updates, and decorative images with empty alt.
An image with descriptive alt text (inspect or disable images to see the fallback):
alt="A scenic view of a mountain landscape"Let’s consider a simple example of using the alt attribute with an <img> element:
<img src="example.jpg" alt="A scenic view of a mountain landscape">In this example, the alt attribute is set to “A scenic view of a mountain landscape,” providing a textual description of the image content. If the image fails to load, this text appears in its place.
You can dynamically set the alt attribute using JavaScript. This can be useful when dealing with changing content or user interactions. Here’s a brief example:
<img id="dynamicImage" src="photo.jpg" alt="">
<script>
document.getElementById("dynamicImage").alt = "Sweet red cherry fruit";
</script>In this script, the alt attribute for an image with the id dynamicImage is set to “Sweet red cherry fruit.” This dynamic approach can be helpful when the content of the image changes based on user actions.
If an image is purely decorative and doesn’t convey meaningful content, use an empty alt attribute:
<img src="divider.svg" alt="" role="presentation">An empty alt="" tells assistive technologies to skip the image. Use this only when the image adds no information beyond what surrounding text already provides.
alt="" for decorative images; never omit the attribute.alt="".aria-describedby.Write descriptive text or leave empty for decorative images.
If the image loads, alt is used by assistive technology.
Broken or blocked images show alt text in the page.
Everyone understands your images—visually, technically, or via assistive tech.
The alt attribute is supported in all browsers and has been part of HTML since the earliest image support.
All major browsers honor alt on img and area elements.
Bottom line: Use alt on every img—it works everywhere and is essential for accessibility.
alt on every <img> elementalt="" for purely decorative imagesalt="IMG_4521.jpg")The alt attribute is a crucial element for creating accessible and inclusive web content. By using it appropriately, you contribute to a better user experience for all visitors, regardless of their abilities or technical constraints.
Good alt text helps screen reader users, improves fallback when images fail to load, and gives search engines meaningful context about your visual content.
altBookmark these before adding your next image.
Describe the image.
BasicsScreen readers.
A11ySearch context.
SEOimage.alt
DynamicDecorative only.
Emptyalt="" for decorative images.imageElement.alt = "description" when image content changes dynamically.Practice the alt attribute with descriptive, dynamic, and decorative examples in the Try It editor.
5 people found this page helpful