CSS background property
Example
Set multiple background images in a div element (and specify their positions):
body
{
background:
#00ff00
url
('
smiley
.
gif
')
no-repeat
fixed
center
;
}
Try it »
Browser support
The numbers in the table indicate the first browser version that supports this property.
| property | |||||
|---|---|---|---|---|---|
| background | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
All major browsers support the background attribute.
Note: IE8 and earlier do not support multiple background images on one element.
Note: IE7 and earlier do not support the "inherit" value. IE8 requires defining !DOCTYPE. IE9 supports "inherit".
Tag Definition and Usage Notes
The background shorthand property can set all background properties in one declaration.
The properties that can be set are: background-color, background-position, background-size, background-repeat, background-origin, background-clip, background-attachment, and background-image.
Values are separated by spaces, in any order. You can have only some of these values, for example background:#FF0000 URL (smiley.gif); is allowed.
| Default value: | See the individual properties |
|---|---|
| Inherited: | no |
| Version: | New properties in CSS1+ CSS3 |
| JavaScript syntax: | object object.style.background="red url(smiley.gif) top left no-repeat" |
Syntax
background:
bg-color
bg-image
position
/
bg-size
bg-repeat
bg-origin
bg-clip
bg-attachment
initial
|
inherit
;
| Value | Description | CSS |
|---|---|---|
| background-color | Specifies the background color to use | 1 |
| background-position | Specifies the position of the background image | 1 |
| background-size | Specifies the size of the background image | 3 |
| background-repeat | Specifies how to repeat the background image | 1 |
| background-origin | Specifies the positioning area of the background image | 3 |
| background-clip | Specifies the painting area of the background image | 3 |
| background-attachment | Sets whether the background image is fixed or scrolls with the rest of the page. | 1 |
| background-image | Specifies one or more background images to use | 1 |
Related Articles
CSS Tutorial: CSS Backgrounds
CSS3 tutorial: CSS3 Backgrounds