Images in html or via css

Asked

Viewed 181 times

1

Is there any advantage in loading an image via css with: background: url ('imagem.jpg'); instead of using it normally as: <img src="imagem.jpg">?

2 answers

3

One advantage I see is that by CSS the code becomes reusable. If multiple tags img use the same style and it is necessary to change the image path, just change the style that is applied for everyone. Straight into the element would have to be changed one by one.

3


I see two main issues to be taken into account:

Semantics and Accessibility

The use of tag <img>, through the attribute alt, generates an interpretation of the search engines, which influences the page’s SEO, according to its algorithms.

In addition, some visually impaired page readers analyze images based on this attribute as well, which is not the case with using the image as a background in CSS.

Patterns

In the use of symbols in a pattern library, for example, it is much more useful to use backgrounds, since it is enough to apply a class or something of the type, so that inside the element has the desired image, be it an icon or a symbol.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.