The background-size property controls how large a background image appears inside an element. It is essential for responsive hero banners, logos, and repeating patterns.
01
cover
Fill the container.
02
contain
Show the full image.
03
auto
Natural image size.
04
Pixels
Exact width and height.
05
Percentages
Relative to the element.
06
Responsive
Pair with no-repeat.
Fundamentals
Definition and Usage
The background-size CSS property sets the dimensions of a background image. You can scale backgrounds to fill a container, fit entirely inside it, or set exact widths and heights.
This property is widely used in responsive design so backgrounds look good on phones, tablets, and desktops without stretching awkwardly or leaving unwanted empty space.
💡
Beginner Tip
For hero sections, the most common combination is background-size: cover; with background-repeat: no-repeat; and background-position: center;.
Foundation
📝 Syntax
Apply background-size after setting a background-image:
auto keeps natural dimensions, cover fills the box, and contain shows the full background without cropping.
🧠 How background-size Works
1
You add a background image
Set a photo, logo, or pattern with background-image.
Background
2
You choose a size mode
Use cover, contain, auto, or explicit dimensions.
Sizing rule
3
You position and repeat
Pair with background-repeat: no-repeat and background-position for polished layouts.
Layout polish
=
📐
Responsive background control
Backgrounds scale correctly across screen sizes without awkward stretching.
Compatibility
Universal Browser Support
background-size is supported in all modern browsers. Basic keywords and length values work back to IE9.
✓ Baseline · Modern browsers
Scale backgrounds confidently everywhere
Chrome, Firefox, Safari, Edge, and Opera all support cover, contain, and custom dimensions.
99%Modern browser support
Google Chrome1+ · Desktop & Mobile
Full support
Mozilla Firefox3.6+ · Desktop & Mobile
Full support
Apple Safari4.1+ · macOS & iOS
Full support
Microsoft Edge12+ · Modern versions
Full support
Opera10.5+ · Modern versions
Full support
Fallback behavior
For very old browsers, provide a fixed height container and test that cover and contain behave as expected.
💻
IE9+Supports background-size with vendor prefixes in legacy codebases
Legacy
background-size property99% supported
Bottom line: Use background-size freely in modern projects for responsive background images.
Wrap Up
Conclusion
The background-size property gives you precise control over how large background images appear. Whether you need a full-bleed hero with cover or a fully visible logo with contain, this property is a core tool for responsive web design.
Combine it with background-repeat, background-position, and background-image to build polished background layouts on any screen size.
Use cover for hero banners that should fill the container
Use contain for logos and images that must stay fully visible
Pair with background-repeat: no-repeat for single images
Set explicit pixel sizes for repeating pattern tiles
Test backgrounds at mobile and desktop widths
❌ Don’t
Stretch images with unequal width and height unless intentional
Use cover when every part of the image must remain visible
Forget to set a min-height on containers using background images
Ignore file size and performance for large background photos
Mix up cover and contain when choosing a layout
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about background-size
Use these points when sizing background images.
5
Core concepts
📐01
cover Fills
May crop edges.
Hero
🖼️02
contain Fits
Shows full image.
Logo
⚡03
auto Default
Natural size.
Default
📝04
Two Values
Width and height.
Syntax
🛠05
With no-repeat
Single-image layouts.
Pair
❓ Frequently Asked Questions
The background-size property sets the width and height of a background image. It controls how large the background appears inside an element.
The initial value is auto, which keeps the background image at its natural size in each dimension.
cover scales the image to fill the entire container and may crop edges. contain scales the image to fit entirely inside the container without cropping, which may leave empty space.
Yes. You can provide one value for both axes or two values such as background-size: 100px 200px or 50% 75%.
Often yes. Pair background-size: cover or contain with background-repeat: no-repeat for hero images and logos.