Performance: Alt text for images
Alt text affects page accessibility and user experience but has minimal impact on page load speed or rendering performance.
<img src="photo.jpg" alt="A smiling person holding a cup of coffee">
<img src="photo.jpg" alt="">
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Image with empty alt attribute | None | 0 | 0 | [OK] OK (but poor accessibility) |
| Image with descriptive alt text | None | 0 | 0 | [OK] Good accessibility, no performance cost |
alt attribute in an <img> tag?alt attribute gives a text description of the image content.alt.<img> tag<img src="flower.jpg" alt="Beautiful red flower"> uses alt="Beautiful red flower", which is correct HTML syntax.<img src="logo.png" alt="Company logo">
alt attribute to describe images to users.<img src="photo.jpg" alt>
alt="description". Here it is empty without ="...".<img> is self-closing in HTML5, so no closing tag needed.img tag for best accessibility?alt="") so screen readers skip them.<img src="decorative.png" alt=""> uses empty alt, which is correct. Omitting alt or using generic text causes confusion.Pass the test and this pattern moves unknown