CSS background-image Property
Example
Set a background-image for the <body> element:
body
{
background-image: url("paper.gif");
background-color: #cccccc;
}
Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The background-image property sets one or more background images for an element.
The background of an element is the total size of the element, including padding and border (but not the margin).
By default, a background-image is placed at the top-left corner of an element, and repeated both vertically and horizontally.
Tip: Always set a background-color to be used if the image is unavailable.
Default value: | none |
---|---|
Inherited: | no |
Animatable: | no. Read about animatable |
Version: | CSS1 + new values in CSS3 |
JavaScript syntax: | object.style.backgroundImage="url(smiley.gif)" Try it |
Browser Support
The numbers in the table specify the first browser version that fully supports the property.
Property | |||||
---|---|---|---|---|---|
background-image | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Note: IE8 and earlier do not support multiple background images on one element.
CSS Syntax
background-image: url|none|initial|inherit;
Property Values
Value | Description |
---|---|
url('URL') | The URL to the image. To specify more than one image, separate the URLs with a comma |
none | No background image will be displayed. This is default |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
More Examples
Example
Set multiple background images for the <body> element:
body {
background-image: url("img_tree.gif"),
url("img_flwr.gif");
background-color: #cccccc;
}
Try it Yourself »
Related Pages
CSS tutorial: CSS Background
CSS3 tutorial: CSS3 Backgrounds
HTML DOM reference: backgroundImage property