background-size
Introduction
The background-size CSS property sets the size of the element's background image. The image can be left to its natural size, stretched, or constrained to fit the available space.
Examples

Syntax
Values
-
cover
Scales the image as large as possible within its container without cropping or stretching the image. If the container is larger than the image, this will result in image tiling, unless thebackground-repeatproperty is set tono-repeat. -
contain
Scales the image (while preserving its ratio) to the smallest possible size to fill the container (that is: both its height and width completely cover the container), leaving no empty space. If the proportions of the background differ from the element, the image is cropped either vertically or horizontally. -
Default value auto
Scales the background image in the corresponding direction such that its intrinsic proportions are maintained. -
<length>
Stretches the image in the corresponding dimension to the specified length. Negative values are not allowed. -
<percentage>
Stretches the image in the corresponding dimension to the specified percentage of the background positioning area. The background positioning area is determined by the value ofbackground-origin(by default, the padding box).
Size Calculation
-
If both components of
background-sizeare specified and are notauto:
The background image is rendered at the specified size. -
containorcover:
While preserving its intrinsic proportions, the image is rendered at the largest size contained within, or covering, the background positioning area. If the image has no intrinsic proportions, then it's rendered at the size of the background positioning area. -
If the background-size has one
autocomponent and onenon-autocomponent:
The image stretched to the specified dimension. The unspecified dimension is computed using the specified dimension and the intrinsic proportions.
Notes
Do not use auto with <gradient>. It may cause some rendering issue in old version SDK.
Formal definition
| Initial value | auto auto |
| Applies to | all elements |
| Inherited | no |
| Animatable | no |
Formal Syntax
Compatibility
LCD tables only load in the browser