The CSS reference

"background-image" - css property (v. css 1)

  • This property sets the background image of an element.
  • When setting a background image, one should also set a background color that will be used when the image is unavailable.
  • When the image is available, it is overlaid on top of the background color.
  • Initial value: none
  • The property is not inherited
  • HTML usage: all elements
  • The value must be none or url -> url(myimage.png)
  • The inherit value, which is new with CSS 2 will inherit the image from parent specification.
  • Browsers that support the background-image - property :
    Internet Explorer Mozilla Firefox Opera Google Chrome Apple Safari

Property "background-image" example:

<style type="text/css">
  body { background-image: url(images/Trophy.png);
         background-color: #cdcdcd; }

Javascript access:

// To SET values ([o] is the target object) 
[o].style.backgroundImage="background-image url"
// To GET values you must first get the computed style object
// To get that object in IE or Opera:
var cStyle=[o].currentStyle;
// To get that object in Firefox, Chrome or Safari (w3c-type):
var cStyle=window.getComputedStyle([o],null);
// To GET the property url:
var value=cStyle.backgroundImage;
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.