CSS background-image Property
Example
Set the background image of the body element:
body
{
background-image:
url
('
paper
.
gif
')
;
background-color:
#cccccc
;
}
Try it »
Tag Definition and Usage Notes
The background-image property sets the background image of an element.
An element's background is the total size of the element, including padding and border (but not margins).
By default, a background-image is placed in the top-left corner of the element and repeats both vertically and horizontally.
Tip: set an available background color so that if the background image is unavailable, the background color can be used instead.
| Default value: | none |
|---|---|
| Inherited: | no |
| Version: | CSS1 |
| JavaScript syntax: | object object.style.backgroundImage="url(stars.gif)" |
Browser support
The numbers in the table indicate the first browser version that supports this property.
A number immediately before -webkit-, -ms-, or -moz- indicates the first browser version that supports that prefixed 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 a single element.
Attribute values
| Value | Description |
|---|---|
| url('URL') | The URL of the image |
| none | No background image is displayed. This is the default |
| linear-gradient() | Create a linear gradient "image" (top to bottom) |
| radial-gradient() | Create an "image" with a radial gradient. (center to edges) |
| repeating-linear-gradient() | Create a repeating linear gradient "image". |
| repeating-radial-gradient() | Create a repeating radial gradient "image" |
| inherit | Specifies that the background image should be inherited from the parent element |
Online example
Multiple background images
This example demonstrates multiple background images in a document.
Related Articles
CSS Tutorial: CSS Backgrounds
CSS3 tutorial: CSS3 Backgrounds