When to Use Img Vs. CSS Background-Image

When to use IMG vs. CSS background-image?

Proper uses of IMG

  1. Use IMG if you intend to have
    people print your page and you want the image to be included by default.
    —JayTee
  2. Use IMG (with alt 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

  1. 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
  2. Use IMG if you rely on browser scaling to render an image in proportion to text size.
  3. Use IMG
    for multiple overlay images in IE6.
  4. Use IMG with a z-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.
  5. Using img instead of background-image can dramatically improve performance of animations over a background.

When to use CSS background-image

  1. Use CSS background images if the
    image is not part of the content.
    —sanchothefat
  2. Use CSS background images when
    doing image-replacement of text eg. paragraphs/headers.
    —sanchothefat
  3. 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
  4. Use background-image if you need to improve download times, as
    with CSS sprites.
  5. Use background-image if you need for only a portion of the image to be visible, as with CSS sprites.
  6. Use background-image with background-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

  1. Use IMG if you intend to have
    people print your page and you want the image to be included by default.
    —JayTee
  2. Use IMG (with alt 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

  1. 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
  2. Use IMG if you rely on browser scaling to render an image in proportion to text size.
  3. Use IMG
    for multiple overlay images in IE6.
  4. Use IMG with a z-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.
  5. Using img instead of background-image can dramatically improve performance of animations over a background.

When to use CSS background-image

  1. Use CSS background images if the
    image is not part of the content.
    —sanchothefat
  2. Use CSS background images when
    doing image-replacement of text eg. paragraphs/headers.
    —sanchothefat
  3. 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
  4. Use background-image if you need to improve download times, as
    with CSS sprites.
  5. Use background-image if you need for only a portion of the image to be visible, as with CSS sprites.
  6. Use background-image with background-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

  1. Use IMG if you intend to have
    people print your page and you want the image to be included by default.
    —JayTee
  2. Use IMG (with alt 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

  1. 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
  2. Use IMG if you rely on browser scaling to render an image in proportion to text size.
  3. Use IMG
    for multiple overlay images in IE6.
  4. Use IMG with a z-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.
  5. Using img instead of background-image can dramatically improve performance of animations over a background.

When to use CSS background-image

  1. Use CSS background images if the
    image is not part of the content.
    —sanchothefat
  2. Use CSS background images when
    doing image-replacement of text eg. paragraphs/headers.
    —sanchothefat
  3. 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
  4. Use background-image if you need to improve download times, as
    with CSS sprites.
  5. Use background-image if you need for only a portion of the image to be visible, as with CSS sprites.
  6. Use background-image with background-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

  1. Use IMG if you intend to have
    people print your page and you want the image to be included by default.
    —JayTee
  2. Use IMG (with alt 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

  1. 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
  2. Use IMG if you rely on browser scaling to render an image in proportion to text size.
  3. Use IMG
    for multiple overlay images in IE6.
  4. Use IMG with a z-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.
  5. Using img instead of background-image can dramatically improve performance of animations over a background.

When to use CSS background-image

  1. Use CSS background images if the
    image is not part of the content.
    —sanchothefat
  2. Use CSS background images when
    doing image-replacement of text eg. paragraphs/headers.
    —sanchothefat
  3. 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
  4. Use background-image if you need to improve download times, as
    with CSS sprites.
  5. Use background-image if you need for only a portion of the image to be visible, as with CSS sprites.
  6. Use background-image with background-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



Leave a reply



Submit