2018-10-04 13:47:55 +00:00
---
title: Background Size
---
## Background Size
2019-03-15 06:49:45 +00:00
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:
2018-10-04 13:47:55 +00:00
```css
2019-03-15 06:51:35 +00:00
/* Background size property values that can be used: */
2018-10-11 23:00:38 +00:00
.auto {background-size: auto;}
2019-03-15 06:51:35 +00:00
/* auto uses the default size of the background image*/
2018-10-11 23:00:38 +00:00
.cover {background-size: cover;}
2019-03-15 06:51:35 +00:00
/* scales the image as much as possible without changing its aspect ratio it to cover the entire element, cropping when necessary to ensure no empty space remains.*/
2018-10-11 23:00:38 +00:00
.contain {background-size: contain;}
2019-03-15 06:51:35 +00:00
/* Scales the image to its largest size without changing its aspect ratio such that both its width and height can fit inside the element.*/
2018-10-11 23:00:38 +00:00
.initial {background-size: initial;}
2019-03-15 06:51:35 +00:00
/* uses the initially or default size of the background image*/
2018-10-11 23:00:38 +00:00
.inherit {background-size: inherit;}
2019-03-15 06:51:35 +00:00
/* inherits the properties of its parent element*/
2018-10-04 13:47:55 +00:00
.pixel {background-size: 50px 50px;}
2019-03-15 06:51:35 +00:00
/* specifies the exact height and width of the image*/
2018-10-04 13:47:55 +00:00
.percentage {background-size: 50% 50%;}
2019-03-15 06:51:35 +00:00
/* changes the width and height based on the percentage specified*/
2018-10-16 03:06:21 +00:00
.view {background-size: 50vw 50vh;}
2018-10-04 13:47:55 +00:00
```
2019-03-15 06:51:35 +00:00
2018-10-16 04:43:33 +00: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 13:47:55 +00:00
2018-11-17 05:55:42 +00:00
To set this property on multiple background images, separate the values by a comma:
2018-10-04 13:47:55 +00: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 13:47:55 +00: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-11 23:00:38 +00:00
CSS-Tricks: < a href = 'https://css-tricks.com/almanac/properties/b/background-size/' target = '_blank' rel = 'nofollow' > background-size< / a >
2018-10-04 13:47:55 +00:00
Browser Support: < a href = 'http://caniuse.com/#search=background-size' target = '_blank' rel = 'nofollow' > caniuse< / a >