Search

5/01/2009

When to use IMG vs. CSS background-image?

When to use IMG vs. CSS background-image?

PRO
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 intend to have people print your page and you want the image to be included by default. —JayTee
3. 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.
4. Use IMG if you rely on browser scaling to render an image in proportion to text size.
5. Use IMG for multiple overlay images in IE6.
6. Use IMG with a z-index in order to stretch a background image to fill its entire window.
7. Using img instead of background-image can dramatically improve performance of animations over a background.

CON
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.

沒有留言: