The background property is a shorthand that sets color, images, position, size, repeat, and more in one line. It is one of the most useful shortcuts in CSS for styling element backgrounds quickly.
01
Shorthand
Many values, one line.
02
Color
Solid fill backgrounds.
03
Images
Photos and gradients.
04
Position & Size
center / cover syntax.
05
Repeat
Tile or no-repeat.
06
Longhand
Individual properties.
Fundamentals
Definition and Usage
The background CSS shorthand property sets all background-related longhand properties at once. Instead of writing six or more separate declarations, you can combine them into a single rule.
This is especially helpful for hero banners, cards, and sections where you need a background color, an image or gradient, centered placement, and cover sizing together.
💡
Beginner Tip
When size is included in the shorthand, it must come after position with a slash: background: ... center / cover;
Foundation
📝 Syntax
The background shorthand accepts multiple values in a specific order:
When no background is declared, the element background is transparent. Each longhand property inside the shorthand has its own initial value, such as background-repeat: repeat and background-color: transparent.
Reference
💎 Property Values
The background shorthand can include these component values:
Component
Example
Meaning
color
background: #eff6ff;
Sets the background color behind images
image
url("photo.jpg")
Adds a background image or gradient
repeat
no-repeat
Controls tiling behavior
position / size
center / cover
Places and scales the background
attachment
fixed
Controls scroll behavior
origin / clip
border-box
Controls positioning and painting areas
Scope
Shorthand Components
The background property combines these longhand properties. Learn each one individually for deeper control:
background-color
Sets the fill color behind images.
background-image
Adds photos, SVGs, or CSS gradients.
background-repeat
Controls whether images tile.
background-position
Places the background inside the element.
background-size
Scales backgrounds with cover, contain, or lengths.
background-attachment
Sets scroll, fixed, or local behavior.
background-origin
Defines where positioning starts.
background-clip
Controls how far the background paints.
Compare
Shorthand vs Longhand
Approach
When to use
Example
background shorthand
Quick hero sections and common one-line setups
background: #fff url(img.jpg) no-repeat center / cover;
Longhand properties
When one value changes independently in media queries
background-size: contain; on mobile only
Color-only shorthand
Simple colored panels without images
background: #dbeafe;
Preview
👀 Live Preview
Three common ways to use the background shorthand:
color only
gradient hero
pattern tile
One property handles color, images, repeat, position, and size together.
Hands-On
Examples Gallery
Try the background shorthand with a hero banner, solid color, repeating pattern, and a longhand comparison.
📚 Common Background Setups
Start with the shorthand patterns you will use most in real layouts.
Example 1 — Hero Banner with cover
Set a fallback color, gradient image, placement, and cover sizing in one declaration.
hero-background.css
.hero{background:#fff7ed linear-gradient(135deg, #2563eb, #7c3aed) no-repeat center / cover;min-height:12rem;}
Shorthand is concise; longhand is easier to read and override one value at a time in responsive layouts.
🧠 How the background Shorthand Works
1
You list the values you need
Include color, image, repeat, position, and size in one declaration.
One line
2
The browser maps each value
CSS assigns each part to its matching longhand property automatically.
Auto mapping
3
Omitted values reset
Any longhand not included returns to its initial value for that layer.
Defaults apply
=
🎨
Complete background styling
You control color, images, placement, and sizing with a single property.
Compatibility
Universal Browser Support
The background shorthand is supported in all modern browsers. The slash syntax for position and size is widely supported in current browsers.
✓ Baseline · All browsers
Set complete backgrounds everywhere
Chrome, Firefox, Safari, Edge, and Opera support the background shorthand and its components.
99%Modern browser support
Google Chrome1+ · Desktop & Mobile
Full support
Mozilla Firefox3.6+ · Desktop & Mobile
Full support
Apple Safari4+ · macOS & iOS
Full support
Microsoft Edge12+ · Modern versions
Full support
Opera10.5+ · Modern versions
Full support
Fallback behavior
If slash syntax is unsupported in a legacy browser, split into longhand background-position and background-size declarations.
💻
Legacy browsersUse longhand properties as a fallback for complex shorthand values
Fallback
background shorthand property99% supported
Bottom line: Use the background shorthand confidently in modern projects, especially for hero sections and colored panels.
Wrap Up
Conclusion
The background shorthand is one of the most practical CSS properties for web design. It lets you set color, images, repeat behavior, placement, and size in a single declaration.
Continue with the individual background properties—starting with background-attachment—to learn each longhand value in depth.
Use shorthand for hero banners: background: color image no-repeat center / cover;
Include a fallback background color before images
Use longhand when overriding one value in media queries
Keep shorthand readable by limiting the number of values
Learn individual background-* properties for advanced control
❌ Don’t
Forget the slash before background-size in shorthand
Assume shorthand and longhand can be mixed carelessly on the same layer
Put size before position in shorthand syntax
Use overly long one-line declarations that are hard to maintain
Skip testing backgrounds on mobile and high-DPI screens
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about the background shorthand
Use these points when writing background CSS.
5
Core concepts
🎨01
All-in-One
Sets many longhands.
Shorthand
🖼️02
Color + Image
Layer backgrounds.
Layers
📍03
center / cover
Position and size.
Syntax
📝04
Color Only
background: #dbeafe;
Simple
🛠05
Learn Longhand
Fine-grained control.
Next steps
❓ Frequently Asked Questions
The background property is a shorthand that sets multiple background-related values in one declaration, including color, image, position, size, repeat, attachment, origin, and clip.
When no background is specified, the background is transparent. Individual longhand properties each have their own initial values when reset.
Common order is color, image, repeat, attachment, position, then size after a slash. For example: background: #fff url(img.jpg) no-repeat center / cover;
The slash separates background-position from background-size. Size must come after position when using the slash syntax, such as center / cover.
Use shorthand for concise hero sections and common patterns. Use longhand properties when you need to change one value independently or improve code readability in complex layouts.