When to use IMG vs. CSS background-image?
Proper uses of IMG
- Use
IMG
if you intend to have
people print your page and you want the image to be included by default.
—JayTee - Use
IMG
(withalt
text) when the image has an important semantic meaning, such as a warning icon. This ensures that the meaning of the image can be communicated in all user-agents, including screen readers.
Pragmatic uses of IMG
- Use
IMG
plus alt attribute if the image
is part of the content such as a logo or diagram or person (real person, not stock photo people).
—sanchothefat - Use
IMG
if you rely on browser scaling to render an image in proportion to text size. - Use
IMG
for multiple overlay images in IE6. UseIMG
with az-index
in order
to stretch a background image to fill its entire window.
Note, this is no longer true with CSS3 background-size; see #6 below.- Using
img
instead ofbackground-image
can dramatically improve performance of animations over a background.
When to use CSS background-image
- Use CSS background images if the
image is not part of the content.
—sanchothefat - Use CSS background images when
doing image-replacement of text eg. paragraphs/headers.
—sanchothefat - Use
background-image
if you intend to have
people print your page and you do not want the image to be included by default.
—JayTee - Use
background-image
if you need to improve download times, as
with CSS sprites. - Use
background-image
if you need for only a portion of the image to be visible, as with CSS sprites. - Use
background-image
withbackground-size:cover
in order to stretch a background image to fill its entire window.
When to use IMG vs. CSS background-image?
Proper uses of IMG
- Use
IMG
if you intend to have
people print your page and you want the image to be included by default.
—JayTee - Use
IMG
(withalt
text) when the image has an important semantic meaning, such as a warning icon. This ensures that the meaning of the image can be communicated in all user-agents, including screen readers.
Pragmatic uses of IMG
- Use
IMG
plus alt attribute if the image
is part of the content such as a logo or diagram or person (real person, not stock photo people).
—sanchothefat - Use
IMG
if you rely on browser scaling to render an image in proportion to text size. - Use
IMG
for multiple overlay images in IE6. UseIMG
with az-index
in order
to stretch a background image to fill its entire window.
Note, this is no longer true with CSS3 background-size; see #6 below.- Using
img
instead ofbackground-image
can dramatically improve performance of animations over a background.
When to use CSS background-image
- Use CSS background images if the
image is not part of the content.
—sanchothefat - Use CSS background images when
doing image-replacement of text eg. paragraphs/headers.
—sanchothefat - Use
background-image
if you intend to have
people print your page and you do not want the image to be included by default.
—JayTee - Use
background-image
if you need to improve download times, as
with CSS sprites. - Use
background-image
if you need for only a portion of the image to be visible, as with CSS sprites. - Use
background-image
withbackground-size:cover
in order to stretch a background image to fill its entire window.
When to use IMG vs. CSS background-image?
Proper uses of IMG
- Use
IMG
if you intend to have
people print your page and you want the image to be included by default.
—JayTee - Use
IMG
(withalt
text) when the image has an important semantic meaning, such as a warning icon. This ensures that the meaning of the image can be communicated in all user-agents, including screen readers.
Pragmatic uses of IMG
- Use
IMG
plus alt attribute if the image
is part of the content such as a logo or diagram or person (real person, not stock photo people).
—sanchothefat - Use
IMG
if you rely on browser scaling to render an image in proportion to text size. - Use
IMG
for multiple overlay images in IE6. UseIMG
with az-index
in order
to stretch a background image to fill its entire window.
Note, this is no longer true with CSS3 background-size; see #6 below.- Using
img
instead ofbackground-image
can dramatically improve performance of animations over a background.
When to use CSS background-image
- Use CSS background images if the
image is not part of the content.
—sanchothefat - Use CSS background images when
doing image-replacement of text eg. paragraphs/headers.
—sanchothefat - Use
background-image
if you intend to have
people print your page and you do not want the image to be included by default.
—JayTee - Use
background-image
if you need to improve download times, as
with CSS sprites. - Use
background-image
if you need for only a portion of the image to be visible, as with CSS sprites. - Use
background-image
withbackground-size:cover
in order to stretch a background image to fill its entire window.
Which is better with HTML/CSS to show an img?
Setting the image through CSS means some browsers will not display the image if the user tries to print your page, and inline CSS styles become hard to manage. You should probably also set the alt, as this helps with accessibility:
<img src="example.png" alt="example image">
There's no sure fire way to prevent someone downloading an image, but if you want to prevent users from right clicking (to save image as), dragging the image etc. you can use some CSS for this:
img {
pointer-events: none;
}
This rule will be applied to all img elements.
When to use IMG vs. CSS background-image?
Proper uses of IMG
- Use
IMG
if you intend to have
people print your page and you want the image to be included by default.
—JayTee - Use
IMG
(withalt
text) when the image has an important semantic meaning, such as a warning icon. This ensures that the meaning of the image can be communicated in all user-agents, including screen readers.
Pragmatic uses of IMG
- Use
IMG
plus alt attribute if the image
is part of the content such as a logo or diagram or person (real person, not stock photo people).
—sanchothefat - Use
IMG
if you rely on browser scaling to render an image in proportion to text size. - Use
IMG
for multiple overlay images in IE6. UseIMG
with az-index
in order
to stretch a background image to fill its entire window.
Note, this is no longer true with CSS3 background-size; see #6 below.- Using
img
instead ofbackground-image
can dramatically improve performance of animations over a background.
When to use CSS background-image
- Use CSS background images if the
image is not part of the content.
—sanchothefat - Use CSS background images when
doing image-replacement of text eg. paragraphs/headers.
—sanchothefat - Use
background-image
if you intend to have
people print your page and you do not want the image to be included by default.
—JayTee - Use
background-image
if you need to improve download times, as
with CSS sprites. - Use
background-image
if you need for only a portion of the image to be visible, as with CSS sprites. - Use
background-image
withbackground-size:cover
in order to stretch a background image to fill its entire window.
Is it better to use an IMG element for a header logo or a background image, why?
Why do this instead of an img element with alt text? Is there some semantic reason? Some accessibility reason? SEO reason?
It's useful when you want to use CSS media queries and display a different logo size depending on the screen resolution.
Regarding accessibility, that would be reasons like permitting users to view alternative text when images are disabled.
html img tag instead of css background-image
You can give the img
a z-index
and everything else a higher z-index
.
img { z-index: -1; }
.banner-options: { z-index: 0 }
This will put img
farther in front, but .banner-options
even farther.
Related Topics
Wrapping Text Inside Input Type="Text" Element Html/Css
Bootstrap Row With Columns of Different Height
Print Page Numbers on Pages When Printing HTML
Want to Make Font Awesome Icons Clickable
What Are the Implications of Using "!Important" in Css
Css Overflow-X: Visible; and Overflow-Y: Hidden; Causing Scrollbar Issue
Is Putting a Div Inside an Anchor Ever Correct
Css - How to Have Swiper Slider Arrows Outside of Slider That Takes Up 12 Column Row
Change Background Color of Iframe Issue
How to Style a ≪Select≫ Dropdown With Only Css
How to Change Input Type="Date" Format
How to Create an HTML Button That Acts Like a Link
Flexbox: Center Horizontally and Vertically
How to Disable a Link Using Only Css
How to Create a Link to a Local File on a Locally-Run Web Page