Web4College

CSS background-size property

src

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.

background-size: auto;
Try it

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.

background-size: contain;
Try it

cover

The image is rescaled to the smallest size such that it covers the background painting area completely while preserving the aspect ratio.

background-size: cover;
Try it

+ve length

20

We specify a fixed length for the background image size.

background-size: 20px;
Try it

percentage

30

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.

background-size: 30%;
Try it

Applicable to

It applies to all elements