It makes no sense to use the <img
> tag if you intend to use a CSS background for the image. In the <img>
the src
attribute is used to indicate the foreground image and is a required attribute for this tag. Leaving this will have unexpected results, such as the border effect that you see, but it may differ from browser to browser.
If you want to use CSS background-image
, just use another HTML tag (e.g. <div>
).
If you want to use the <img>
, then you need to use the src
attribute and not define it in CSS.
This is about semantics. It is assumed that the image in the <img>
is part of the content of the page, so the image is indicated in HTML code, while when defining the image in CSS, you say that it is part of the design and not the content.
You should use a method that matches the purpose of your image on the site.
source share