Property Description
The background-size property specifies the size of the background images.
This property has the following syntax:
background-size: auto|length|%|cover|contain|initial|inherit;
Property Values
Value | Description |
---|---|
auto | Specifies that the background-image contains the height and width |
length | Sets the height and width of the background image. The first value sets the width, the second value sets the height. If only one value is given, the second is set to "auto" |
% | Sets the height and width of the background image in percent of the parent element. The first value sets the width, the second value sets the height. If only one value is given, the second is set to "auto" |
cover | Scale the image to the smallest size such that both its width and its height can fit inside the content area |
contain | Scale the image to the largest size such that both its width and its height can fit inside the content area |
initial | Specifies that the value of the property should be set to the default value |
inherit | Specifies that the value of the property should be inherited from the parent element |
Examples
This example shows how to size the background image:
div {
background:url(img_flwr.gif);
background-size:80px 60px;
background-repeat:no-repeat;
}
Browser Support
Chrome | Firefox | IE | Safari | Opera |
---|---|---|---|---|
4.0
1.0 -webkit- |
4.0
3.6 -moz- |
9.0 | 4.1
3.0 -webkit- |
10.5
10.0 -o- |
Miscellaneous Information
Inherited: | No |
---|---|
Defined In: | CSS3 |
Default Value: | auto |