The background-color property is one of the most common CSS properties. It sets the solid color behind an element’s content using named colors, hex, rgb, hsl, and more.
01
Solid Backgrounds
Fill element areas.
02
Syntax
One simple property.
03
Color Formats
Named, hex, rgb, hsl.
04
transparent
Default see-through value.
05
Alpha Colors
Semi-transparent panels.
06
CSS Variables
Reusable theme colors.
Fundamentals
Definition and Usage
The background-color CSS property sets the background color of an element. It paints a solid color behind the content area, which helps you separate sections, highlight cards, and improve readability.
Unlike background-image, which can use photos or gradients, background-color applies one flat color. It is often combined with padding, borders, and other background properties.
💡
Beginner Tip
Start with a named color like lightblue or a hex value like #2563eb. Once that works, try rgba() when you need transparency.
Foundation
📝 Syntax
Apply background-color to any element that should have a colored background:
The property is not inherited, but transparent backgrounds can reveal a parent’s background.
It can be animated when the color value changes over time.
Use background-color for solid fills and background-image for photos or gradients.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
transparent
Applies to
All elements
Inherited
No
Animatable
Yes
Common use
Cards, sections, alerts, buttons, panels
Defaults
Default Value
The initial value of background-color is transparent. That means the element does not paint its own background color, so the parent element’s background can show through.
Reference
💎 Property Values
background-color accepts standard CSS color values. These are the most common ones for beginners.
Value
Example
Meaning
Named color
background-color: lightblue;
Uses a CSS color keyword
Hex color
background-color: #2563eb;
Uses a hexadecimal color
RGB or RGBA
background-color: rgba(37, 99, 235, 0.8);
Uses red, green, blue, and optional alpha
HSL or HSLA
background-color: hsl(142 72% 29%);
Uses hue, saturation, and lightness
CSS variable
background-color: var(--surface);
Uses a reusable theme color
transparent
background-color: transparent;
No background color is painted
lightblue#2563ebrgb()hsl()rgba()
named
Easy to read and great for quick demos and learning.
Example: lightblue
hex
Very common in design systems and brand color palettes.
Example: #7c3aed
rgb()
Useful when you want numeric control over red, green, and blue.
Example: rgb(5, 150, 105)
hsl()
Helpful when adjusting lightness or saturation is easier than hex.
Example: hsl(24 95% 53%)
rgba()
Lets the background show through with partial transparency.
Example: rgba(219, 39, 119, 0.65)
transparent
The default value. No background color is painted.
Parent backgrounds can show through.
Compare
background-color vs color
Property
Styles
Best for
background-color
The area behind the element’s content
Panels, sections, cards, page blocks
color
Text and other foreground content
Headings, paragraphs, links, button labels
Preview
👀 Live Preview
These swatches use different color formats with the same property:
lightblue
#2563eb
rgb()
rgba()
All four boxes use background-color with different valid color values.
Hands-On
Examples Gallery
Try background-color with named colors, hex values, rgba transparency, and CSS theme variables.
📚 Basic Background Colors
Start with simple solid colors before moving to transparency and theme variables.
Example 1 — Named Color on a div
Set a quick background color using a CSS color keyword.
named-color.html
<style>div{background-color:lightblue;padding:20px;border:1px solid #000;}</style><div>This is a div with a light blue background.</div>
Changing the custom properties updates every element that references them, which makes theme updates much easier.
🧠 How background-color Works
1
You choose a color value
Write a named color, hex value, rgb(), hsl(), or CSS variable in your stylesheet.
Color value
2
The browser paints the background
The color fills the element’s background painting area behind its content.
Rendering
3
Other properties can shape it
Properties like background-clip, padding, and borders affect how much of that color you see.
Layout
=
🎨
Clear visual sections
Solid background colors help organize content and improve readability.
Compatibility
Universal Browser Support
background-color is one of the most widely supported CSS properties and works reliably across modern and older browsers.
✓ Baseline · All browsers
Set background colors everywhere
Chrome, Firefox, Safari, Edge, Opera, and legacy browsers all support standard color values.
99%Universal support
Google Chrome1+ · Desktop & Mobile
Full support
Mozilla Firefox1+ · Desktop & Mobile
Full support
Apple Safari1+ · macOS & iOS
Full support
Microsoft Edge12+ · All versions
Full support
Opera3.5+ · Modern versions
Full support
Fallback behavior
Invalid color values are ignored by the browser, leaving the previous or default background in place.
💻
Very old browsersMay not support newer color formats like space-separated hsl()
Rare
background-color property99% supported
Bottom line: Use background-color confidently in any web project.
Wrap Up
Conclusion
The background-color property is a foundational CSS tool for styling the web. It lets you add solid colors to sections, cards, buttons, and panels using simple, readable syntax.
Start with named colors and hex values, then explore rgba() for overlays and CSS variables for reusable theme colors.
Use hex or CSS variables for brand and theme colors
Pair background colors with readable text colors
Use rgba() for overlays and subtle panels
Test contrast in light and dark sections
Keep color choices consistent across the page
❌ Don’t
Confuse background-color with color
Use low-contrast background and text combinations
Hard-code the same color in many unrelated selectors
Assume transparent means inherited
Forget that gradients belong in background-image
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about background-color
Use these points when styling backgrounds in your next layout.
5
Core concepts
🎨01
Solid Fill
Colors the area behind content.
Purpose
📝02
Many Formats
Named, hex, rgb, hsl.
Values
🖼️03
transparent Default
No color unless you set one.
Default
👁04
Not color
Background vs text color.
Compare
🛠05
Theme Variables
Reuse with var().
Projects
❓ Frequently Asked Questions
The background-color property sets the solid background color behind an element's content. It fills the element's background painting area unless clipped by other background properties.
The initial value is transparent, which means no background color is painted and the parent element's background can show through.
You can use named colors, hex values, rgb(), rgba(), hsl(), hsla(), currentColor, and CSS custom properties.
background-color styles the area behind the element's content. color styles the text and other foreground content inside the element.
Yes. Use rgba() or hsla() with an alpha value, or a modern hex value with alpha such as #2563eb80.