HTML & CSS · Junior · Question 39 of 75

When is it better to use <img> rather than background-image?

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.

Further reading

Problem with a question

HTML & CSS · Junior · question 39

Test yourself

Take the HTML & CSS · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz