CSS background
Property
Topic: CSS3 Properties ReferencePrev|Next
Description
The background
CSS property is a shorthand property for setting the individual background properties i.e. background-image
, background-position
, background-size
, background-repeat
, background-attachment
, background-origin
, background-clip
and background-color
in a single declaration.
The following table summarizes the usages context and the version history of this property.
Default value: | See individual properties |
---|---|
Applies to: | All elements |
Inherited: | No |
Animatable: | Yes, as some of the properties of the shorthand are animatable. See animatable properties. |
Version: | CSS 1, 2, 3 |
Syntax
The syntax of the property is given with:
Note: If any property listed above is missing or omitted, the default value for that property will be inserted, if any. See individual properties for details.
The example below shows the background
property in action.
Example
Try this code »body {
background: #ffff00 url("smiley.png") no-repeat fixed center;
}
In CSS3 you can also add multiple backgrounds to a single element. The backgrounds are layered on the top of one another along the z-axis.
Example
Try this code ».box {
width: 100%;
height: 500px;
background: url("images/birds.png") no-repeat center, url("images/clouds.png") no-repeat center, lightblue;
}
Property Values
The following table describes the values of this property.
Value | Description |
---|---|
|
Specifies whether the background scrolls with the document, or remains fixed to the viewing area. |
background-color |
Sets the background color of an element. |
background-clip |
Specifies the area within which the background is painted. |
background-image |
Sets one or several background images for an element. |
background-origin |
Specifies the positioning area of the background images. |
background-position |
Sets the initial position of the background image. |
background-repeat |
Specifies how background images are tiled after they have been sized and positioned. |
background-size |
Specifies the size of the background images. |
initial |
Sets this property to its default value. |
inherit |
If specified, the associated element takes the computed value of its parent element background property. |
Browser Compatibility
The background
property is supported in all major modern browsers.
Basic Support—
|
Further Reading
See tutorial on: CSS Background, CSS3 Background.
Related properties: background-attachment
, background-color
, background-clip
, background-image
, background-origin
, background-position
, background-repeat
, background-size
.