-3

From my knowledge, there are 2 primary ways to insert images into HTMl.

  1. You can either use the traditional image tag and add the image via the "src" attribute.
  2. Or you can add the image as a background-image to a div tag via the background-image property.

Can someone explain some of the pros and cons of using either of these approaches? When would you use one or the other?

wmock
  • 5,382
  • 4
  • 40
  • 62
  • **primarily opinion-based** _Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise._ – emerson.marini Aug 13 '14 at 14:48
  • I'm not sure why this should be closed - this seems to be a very valid question the community can help me understand better. – wmock Aug 13 '14 at 14:49
  • 1
    `` and `background-image:url('')` are not the same at all each one inherit its own property. `src` where it act like as content of the page where as you can give that content `background-image`. For more reference. Check this one http://stackoverflow.com/questions/492809/when-to-use-img-vs-css-background-image – Benjamin Aug 13 '14 at 14:51
  • You can find more about this by just looking for documentation around the web, or the already present question mentioned by @Benjamin. – emerson.marini Aug 13 '14 at 14:52
  • Your question should be closed because it's not about a doubt, issue, problem, etc, that you've found while writing code. – emerson.marini Aug 13 '14 at 14:53

2 Answers2

1

If your images are for designing reasons, your best of placing them as background. But when your images are part of your content, for example your website logo, or some illustration as an explanation to your text, you put it in with an img tag.

GreyRoofPigeon
  • 17,833
  • 4
  • 36
  • 59
1

I would say use css to insert background images. From my experience it's more efficient and easier to read if you can keep all attributes of a div in one language. You can then edit them without switching screens in your editor, unless you plan to add some kind of user interface (javascript, jquery, etc.)

dSumner.1289
  • 712
  • 1
  • 5
  • 16