The background-size property sets how large a background-image is drawn. Leave it at its natural size with auto, stretch it with lengths or percentages, or fit the box with cover and contain while keeping the aspect ratio.
The initial value is auto. The property is not inherited. Percentages are relative to the background positioning area from background-origin. Gaps not covered by the image show the background-color. It applies to every element, including ::first-letter and ::first-line.
Standard-track.
Not deprecated and not experimental. Baseline widely available. In the background shorthand, size must follow position with a slash: center / cover.
Two values mean width then height.100px 60px draws the image at exactly that size.
One value would set only the width.100px alone keeps height as auto and preserves the ratio when the image has one.
Percentages use the positioning area.50% is half the width of the area from background-origin, not half of the image file.
Negative sizes are invalid. The browser ignores a negative length or percentage.
Edge Cases & Pitfalls
If the image looks tiled, stretched wrong, or unchanged, one of these is usually why.
repeat
contain can tile by default
If the scaled image is smaller than the box, background-repeat starts at repeat and fills the gaps with copies. Use no-repeat for a single logo or photo.
slash
Shorthand needs position / size
In background, write center / cover. A bare cover in the shorthand is not enough without a position and slash.
gradient
Gradients have no natural size
CSS gradients have no intrinsic dimensions. With auto, they often fill the positioning area, so cover and contain can look the same. Use a file or SVG with width and height to study the keywords.
crop
cover always may crop
When the box ratio differs from the image ratio, edges are cut off. Keep important subject matter near the center, or switch to contain.
a11y
Background images stay decorative
Screen readers do not announce them. Put meaning in an img with alt, and keep text contrast strong over cropped or scaled paint.
Compatibility
Browser Support
background-size is a browser painting property. Node.js, Deno, and Bun do not apply it. cover and contain are Baseline and widely available.
✓ Baseline · Widely available since 2015
background-size
cover and contain: Chrome 4+, Firefox 3.6+, Safari 5+, Edge 12+, Opera 10+, Samsung Internet 4+, Internet Explorer 9+. Lengths and percentages follow the same modern support.
97%Global support
Google Chrome4+ cover/contain
Full support
Mozilla Firefox3.6+
Full support
Apple Safari5+
Full support
Microsoft Edge12+
Full support
Opera10+
Full support
Samsung Internet4+
Full support
Internet Explorer9+
Full support
background-sizeWidely supported
Bottom line: Safe for cover, contain, lengths, and percentages in current browsers. Internet Explorer 8 and older lack the property. Prefer an image with intrinsic size when teaching or testing cover vs contain.
Remember
Key Takeaways
Role: set how large the background image is drawn inside the box.
Keywords:cover fills (may crop); contain fits (may leave gaps); auto is the default.
Two values: width then height. One value sets width; height becomes auto.
Pair with:no-repeat and often center for heroes and logos.
One line:background-size answers “how big is this background image inside the box?”
Frequently Asked Questions
It sets the width and height of a background image. You can keep the natural size, stretch with lengths or percentages, or use cover and contain to fit the box while keeping the aspect ratio.
auto, which is the same as auto auto. A bitmap keeps its natural size. Empty space shows the background-color.
cover scales up until the box is filled and may crop edges. contain scales until the whole image fits and may leave empty bands that show the background-color. Both keep the aspect ratio.
The default background-repeat is repeat. If the scaled image is smaller than the box, it tiles. Pair contain (or a length size) with background-repeat: no-repeat when you want one copy.
Write size after position with a slash, such as center / cover. Size is not valid in the shorthand without that slash after a position.
It is Baseline and widely available. cover and contain work in Chrome 4+, Firefox 3.6+, Safari 5+, Edge 12+, and Internet Explorer 9+. It is a browser painting property. Node.js, Deno, and Bun do not apply it.