18
When should I use a tag </img>
HTML to display an image?
And background-image
CSS?
Factors such as accessibility and browser support can influence choice?
18
When should I use a tag </img>
HTML to display an image?
And background-image
CSS?
Factors such as accessibility and browser support can influence choice?
16
Recommended uses of tag <img>
:
alt
). This information is important in several cases as: the user is with slow internet connection and the images do not load (displaying only the description) or even visually impaired who access the page can know what the image is about (through software that "speaks" page text including image description).Recommended uses of background-image
(CSS):
I believe that the content vs design factor influences the choice between img
and background-image
. An image that is part of the content used as background-image
can impair accessibility and decrease the chance of a good page indexing in search engines. Regarding the performance, in some initial research I did, I found no differences in the loading time. One difference I found was that the background-image
does not load if not being used, the tag img
always carries.
Reference:
When to use IMG vs. CSS background-image?
Are unused CSS images downloaded?
Thank you so much, you cleared my doubts. Excellent answer!
@Aliciatairini Glad the answer helped you! = D
6
My answer was like this:
The property in CSS background-image
should only be used when an image is decorative, that is, it has no semantic value and only serves to leave the page more "pretty", if the image is really important to understand the text, the tag should be used <img/>
, and add the attribute alt to offer an alternative text to the image (com CSS não é possível fazer isso)
.
0
Hello, responding in a practical and simple way you can use the images in the CSS if you want them at the bottom of your page as the same background. And those with the normal image body img tag, like new products or other sections of html. And don’t forget the img tag always loads the image is the best part
Browser other questions tagged css html5
You are not signed in. Login or sign up in order to post.
Not an answer, just an initial consideration: img is part of the content, CSS is not. That would already be a decision factor. Semantically if the image is part of the content, as a schematic diagram referred to in a text, the IMG makes more sense. Whether it’s a decorative element like a page texture, or a graphic detail, or a complementary image (like a logo in place of the company name in the header) usually makes more sense in CSS. It’s not general or absolute, I just wanted to get to the point.
– Bacco
CSS Transitions, with
background-image
can save us sometimes =]– BrTkCa
@Lucascosta this can be done with IMG too, no problems.
– Bacco
@Bacco Well placed!
– Alicia Tairini