Should I place the backround image in the CSS or HTML?

Discussion in 'HTML & Website Design' started by cscott5288, Feb 7, 2009.

  1. #1
    I was wondering...

    If I have a layout image, like the peice of a menu or something and I position it using divs. Should I place the actual image withing the HTML, within the div tags, like so <img src"=blahblah.jpg"> or should I place it in the CSS, like so: background-image: url('blahblah.jpg');?

    They both appear to have the same visual effect, and I am not planning on putting any additional HTML within these <divs> (other then the image itself).

    Does it matter whichever way?
     
    cscott5288, Feb 7, 2009 IP
  2. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Basically your aim is to try and keep everything presentational inside the CSS, so that your HTML is pure content.

    If the image is part of the content, and worth a SE Spider seeing e.g an image related to an article keep it inside the HTML, if it's just something like a background image or a piece of a menu then shove it inside the CSS.
     
    wd_2k6, Feb 7, 2009 IP
  3. cscott5288

    cscott5288 Active Member

    Messages:
    912
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #3
    thanks! will do :)
     
    cscott5288, Feb 7, 2009 IP
  4. tarponkeith

    tarponkeith Well-Known Member

    Messages:
    4,758
    Likes Received:
    279
    Best Answers:
    0
    Trophy Points:
    180
    #4
    Great advice.

    I would just like to add that as you start using external stylesheets more and more, watch out for "divitis" (the overusing of the DIV tag)...
     
    tarponkeith, Feb 7, 2009 IP
  5. SweetChilli

    SweetChilli Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Ditto, that is the key to designing with HTML/CSS. CSS stylesheets give you a central point to change the site's presentation, instead of having to change each HTML page individually, which can become a nightmare.
     
    SweetChilli, Feb 7, 2009 IP
  6. megatechfreaxz

    megatechfreaxz Banned

    Messages:
    76
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    good info! now i know how to work with this situation.
    thanks!
     
    megatechfreaxz, Feb 7, 2009 IP
  7. karthimx

    karthimx Prominent Member

    Messages:
    4,959
    Likes Received:
    127
    Best Answers:
    2
    Trophy Points:
    340
    #7
    Try to avoid styles in the html content... Its better to use in css...
     
    karthimx, Feb 8, 2009 IP
  8. kellywriter

    kellywriter Banned

    Messages:
    81
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    If you will use background images properly you will be able to make fast loading site as backgroudn will stretch automatically even if the image is small in size.
     
    kellywriter, Feb 8, 2009 IP