Example

Specify the size of a background image:

div
{
background:url(/images/w3css.gif);
-moz-background-size:60px 80px; /* Firefox */
background-size:60px 80px;
background-repeat:no-repeat;
}

Try it yourself »
More examples at the bottom of this page.

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The background-size property is only supported in Opera, Chrome, and Safari.

Firefox supports an alternative, the -moz-background-size property.


Definition and Usage

The background-size property specifies the size of the background images.

Default value: auto
Inherited: no
Version: CSS3
JavaScript syntax: object.style.backgroundSize="60px 80px"


Syntax

background-size: length|percentage|cover|contain;

Value Description
length Sets the height and width of the background image. The first value sets the width, the second value sets the height. If only one value is given, the second is set to "auto"
percentage Sets the height and width of the background image in percent of the parent element. The first value sets the width, the second value sets the height. If only one value is given, the second is set to "auto"
cover Scale the image to the smallest size such that both its width and its height can fit inside the content area
contain Scale the image to the largest size such that both its width and its height can fit inside the content area