Performance: Image source and alt attribute
This concept affects page load speed and visual stability by controlling image loading and fallback text.
<img src="optimized-image.webp" alt="Description of image">
<img src="large-image.jpg" alt="">
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Image without alt and large source | 1 node | 1 reflow if image size unknown | High paint cost due to large image | [X] Bad |
| Image with alt and optimized source | 1 node | Single reflow with known size | Lower paint cost with smaller image | [OK] Good |
alt attribute in an <img> tag do?alt attributealt attribute provides alternative text describing the image content.alt describes image content [OK]<img> with attributes src and alt.<img src="photo.jpg" alt="A sunset"> uses correct attribute names and syntax: src="photo.jpg" and alt="A sunset".<img src="photo.jpg" alt="A sunset"> [OK]<img src="logo.png" alt="Company Logo">
<img src="picture.jpg" alt>
<img> is self-closing, so no closing tag needed.<img> tag for accessibility and SEO?<img src="cat-ball.jpg" alt="Cat playing with a ball"> describes the image specifically as "Cat playing with a ball", which is clear and meaningful.Pass the test and this pattern moves unknown