background-size

Sets the size of the element's background image. It can be it's original size, stretched or fills the available space in the element.

Example

Initial value auto auto
Applies to all elements. It also applies to ::first-letter and ::first-line.

Syntax

  
background-size: cover;
  

Values

Scales the image as large as possible within its container. If the container is larger than the image, this will result in image tiling, unless the background-repeat property is set to no-repeat.
Scales the image as large as possible to fill the container, stretching the image if necessary. If the proportions of the image differ from the element, it is cropped either vertically or horizontally so that no empty space remains.
Scales the background image in the corresponding direction such that its intrinsic proportions are maintained.
Stretches the image in the corresponding dimension to the specified length. Negative values are not allowed.
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 of background-origin (by default, the padding box). However, if the background's background-attachment value is fixed, the positioning area is instead the entire viewport. Negative values are not allowed.
The background image is rendered at the specified size.
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 image has both horizontal and vertical intrinsic dimensions, it's rendered at that size. If the image has no intrinsic dimensions and has no intrinsic proportions, it's rendered at the size of the background positioning area. If the image has no intrinsic dimensions but has intrinsic proportions, it's rendered as if contain had been specified instead. If the image has only one intrinsic dimension and has intrinsic proportions, it's rendered at the size corresponding to that one dimension. The other dimension is computed using the specified dimension and the intrinsic proportions. If the image has only one intrinsic dimension but has no intrinsic proportions, it's rendered using the specified dimension and the other dimension of the background positioning area.
Note: SVG images have a preserveAspectRatio attribute that defaults to the equivalent of contain; an explicit background-size causes preserveAspectRatio to be ignored.

Browser support

background-size31249105
contain_and_cover3123.69105

We use cookies to improve your experience. Learn more in our Privacy policy.

×