CSS background-size property
Browser support · legacy reference
ChromeFully supports
SafariFully supports
FirefoxFully supports
Internet ExplorerFully supports
EdgeFully supports
OperaFully supports
Description
CSS background-size property defines the size of the background image on the background painting area.
Syntax
background-size : contain | cover | auto | length | percentage
Property values
autoDefault
-
The size of the background image is automatically calculated.
- Try it
background-size: auto; contain
-
The image is rescaled to the largest size such that both sides of the image fit inside the background painting area while preserving the aspect ratio.
- Try it
background-size: contain; cover
-
The image is rescaled to the smallest size such that it covers the background painting area completely while preserving the aspect ratio.
- Try it
background-size: cover; percentage
-
It represents the image size as the percentage of the background painting area.
30% means the background image occupies the 30% of the element. And three images can fill the painting area of an element with this size.
- Try it
background-size: 30%;
Applicable to
It applies to all elements