0

When querying an API that may or may not have an image, what are the main differences in setting the background-image or actually creating an img tag?

<div class="img" style="background-image:url(...)"></div>

vs

<div class="img"><img src="..." alt="#" /></div>
1
  • 1
    By what criteria do you wish to evaluate "better"? E.g. consistent appearance across browsers, ease of maintenance, ease of styling to achieve a certain appearance, etc. Commented Nov 25, 2013 at 23:34

3 Answers 3

0

The second makes the background selectable, which can harm design. And it can harm the positioning, too. Imho there is not always the first to use. And from external css.

Sign up to request clarification or add additional context in comments.

Comments

0

A broken image tag may show if the image doesn't exist. It will also fire an 'error' event. See http://css-tricks.com/snippets/jquery/better-broken-image-handling/

A broken background-image would fail a little more 'silently.'

Comments

0

A background image is a presentational detail.

A foreground image is content.

If the image changes the readers' understanding of the document then it should be an <img>. If it is only decorative it should be applied with CSS.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.