HTML & CSS · Junior · Question 39 of 75
When is it better to use <img> rather than background-image?
- ✓Correct answer: When the image is part of the content (product photo, illustration) and needs
alt - 2When the image is decorative: a background pattern, texture or ornament
- 3Only when the image is an SVG; other formats go in the background
Explanation
<img> is content: it has alt for accessibility, gets indexed by search engines, supports srcset and loading="lazy", and prints. background-image suits decoration: backgrounds, patterns and ornaments that carry no meaning. The file format doesn't affect the choice.