Images in html or via css

1

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

    
asked by anonymous 29.12.2016 / 20:49

2 answers

3

I see two key issues to consider:

Semantics and Accessibility

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

In addition, some page readers for the visually impaired analyze the images based on this attribute as well, which does not happen with the use of the image as a background in CSS.

Standards

In the use of symbols in a standards library, for example, it is much more beneficial to use backgrounds, since you just have to apply a class or something, so that inside the element has the desired image, be this an icon or a symbol.

    
29.12.2016 / 21:03
3

One advantage that I see is that by CSS the code becomes reusable. If multiple img tags use the same style and you need to change the image path, you would need to change the style that is applied to all. Direct on the element would have to be changed one by one.

    
29.12.2016 / 20:51