2018-10-04 14:47:55 +01:00
---
title: Background Size
---
## Background Size
The background-size property specifies the size of the background images. You can set a length or a percentage, with the first value being the width and the second one being the height. You can also use one of the 5 keyword values:
```css
2018-10-22 19:49:42 +01:00
/* Background size property values that can be used */
2018-10-12 04:30:38 +05:30
.auto {background-size: auto;}
.cover {background-size: cover;}
.contain {background-size: contain;}
.initial {background-size: initial;}
.inherit {background-size: inherit;}
2018-10-15 23:06:21 -04:00
/* Percentage, pixel, and viewport units can also be used */
2018-10-04 14:47:55 +01:00
.pixel {background-size: 50px 50px;}
.percentage {background-size: 50% 50%;}
2018-10-15 23:06:21 -04:00
.view {background-size: 50vw 50vh;}
2018-10-04 14:47:55 +01:00
```
2018-10-15 23:43:33 -05:00
Note: If using pixel or percentage for length and you only specify one value,
the second one will be set to auto by default.
2018-10-04 14:47:55 +01:00
2018-11-17 00:55:42 -05:00
To set this property on multiple background images, separate the values by a comma:
2018-10-04 14:47:55 +01:00
```css
.multiple {
2018-12-13 05:03:03 +00:00
background-image: url(1.png), url(2.png);
background-size: 3px 3px, cover;
/* first image is 3x3 px, second image covers the whole area */
2018-10-04 14:47:55 +01:00
}
```
#### More Information:
Documentation: < a href = 'https://developer.mozilla.org/en-US/docs/Web/CSS/background-size' target = '_blank' rel = 'nofollow' > MDN< / a >
2018-10-12 04:30:38 +05:30
CSS-Tricks: < a href = 'https://css-tricks.com/almanac/properties/b/background-size/' target = '_blank' rel = 'nofollow' > background-size< / a >
2018-10-04 14:47:55 +01:00
Browser Support: < a href = 'http://caniuse.com/ #search =background-size' target = '_blank' rel = 'nofollow' > caniuse</ a >