SyntaxStudy
Sign Up
Home CSS Reference background-size

background-size

property

Sets the size of background images. cover fills the element; contain fits the entire image.

Syntax

background-size: auto | cover | contain | width height;

Example

css
.cover   { background-size: cover; }   /* fill, crop */
.contain { background-size: contain; } /* fit, show all */
.exact   { background-size: 200px 100px; }
.percent { background-size: 50% auto; }

.hero {
    background-image: url('hero.jpg');
    background-size: cover;
    background-position: center;
}