ExampleSpecify the size of a background image:
Try it yourself » More examples at the bottom of this page. |
The background-size property is only supported in Opera, Chrome, and Safari.
Firefox supports an alternative, the -moz-background-size property.
The background-size property specifies the size of the background images.
Default value: | auto |
---|---|
Inherited: | no |
Version: | CSS3 |
JavaScript syntax: | object.style.backgroundSize="60px 80px" |
background-size: length|percentage|cover|contain; |
Value | Description |
---|---|
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" |
percentage | 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 |