Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

CSS Dictionary

  1. Home
  2. CSS Dictionary
  3. background-size

background-size

Specifies the size of the background image.

Sample Code

div.test { background-size: auto;}
div.test1 { background-size: contain;}
div.test2 { background-size: cover;}
div.test3 { background-size: 50%;}
div.test4 { background-size: 50px 100px;}

Available Values

ValueDescription
autoWith a single auto, the image is rendered at its natural size. With a second auto, the image scales proportionally to the first value.
containScales the image to fit within the background area while preserving the aspect ratio.
coverScales the image to cover the background area while preserving the aspect ratio, using the minimum size needed.
Length valueSets the background size to a specific value. Accepts units like px and %. Using % is relative to the background painting area, not the image size.

Browser Preview

※ The background image below is used in the samples. Its natural size is 100px × 100px. Background tiling is disabled for clarity.

<div style="border: dashed 10px rgba(0, 0, 255, 0.5); height: 100px; padding: 10px; font-weight: bold; background-image: url(/dics/dictionary-css/img/sample_bg1.png); background-repeat: no-repeat; background-size: auto;">A 100px tall div with 10px padding. Border is 'dashed 10px rgba(0, 0, 255, 0.5)'.</div>

<div style="border: dashed 10px rgba(0, 0, 255, 0.5); height: 100px; padding: 10px; font-weight: bold; background-image: url(/dics/dictionary-css/img/sample_bg1.png); background-repeat: no-repeat; background-size: cover;">A 100px tall div with 10px padding. Border is 'dashed 10px rgba(0, 0, 255, 0.5)'.</div>

<div style="border: dashed 10px rgba(0, 0, 255, 0.5); height: 100px; padding: 10px; font-weight: bold; background-image: url(/dics/dictionary-css/img/sample_bg1.png); background-repeat: no-repeat; background-size: contain;">A 100px tall div with 10px padding. Border is 'dashed 10px rgba(0, 0, 255, 0.5)'.</div>

<div style="border: dashed 10px rgba(0, 0, 255, 0.5); height: 100px; padding: 10px; font-weight: bold; background-image: url(/dics/dictionary-css/img/sample_bg1.png); background-repeat: no-repeat; background-size: 50%;">A 100px tall div with 10px padding. Border is 'dashed 10px rgba(0, 0, 255, 0.5)'.</div>

<div style="border: dashed 10px rgba(0, 0, 255, 0.5); height: 100px; padding: 10px; font-weight: bold; background-image: url(/dics/dictionary-css/img/sample_bg1.png); background-repeat: no-repeat; background-size: 50px 100px;">A 100px tall div with 10px padding. Border is 'dashed 10px rgba(0, 0, 255, 0.5)'.</div>

Browser Compatibility

Chrome Chrome
3+
2
1
↑ Requires prefix -webkit-
Firefox Firefox
4+
2 and below ×
Safari Safari
5+
4
3
↑ Requires prefix -webkit-
2 and below ×
Edge Edge
12+
Supported in all versions.
IE IE
11
10
9
8 ×
7 ×
6 ×
Opera Opera
10+
8 and below ×
iOS Safari iOS Safari
4.2+
3
2
1
↑ Requires prefix -webkit-
Android Android Browser
4.4+
3 and below ×
Chrome Android Chrome Android
Latest
Same support as desktop.
Firefox Android Firefox Android
Latest
Same support as desktop.

※ Version data is based on MDN / Can I Use.

Notes

Specifies the size of the background image.

You can provide one keyword value, or up to two numeric values (width and height).

With two numeric values, the first sets the width and the second sets the height. With a single numeric value, the second defaults to auto, scaling the image proportionally.

When using %, the percentage is relative to the background painting area — not the image's natural size. To render the image at its natural size, you need to calculate the exact pixel dimensions manually. CSS alone cannot automatically scale to the image's natural size.

To change the background painting area, use the width and height properties, or the background-clip property.

If you find any errors or copyright issues, please .