background-color defaults to transparent, letting whatever's behind the element, its parent's background or the page itself, show through unless explicitly set to an opaque or semi-transparent value. Unlike color, background-color is not inherited by default, so setting it on a parent doesn't automatically apply it to nested children — each element's background remains transparent by default regardless of its ancestors' background-color, which is why a background color set on a page's body doesn't automatically also appear behind every nested box unless that box's own background is also transparent, letting the body's color show through.
1Understanding Background-color
background-color defaults to transparent, letting whatever's behind the element, its parent's background or the page itself, show through unless explicitly set to an opaque or semi-transparent value. Unlike color, background-color is not inherited by default, so setting it on a parent doesn't automatically apply it to nested children — each element's background remains transparent by default regardless of its ancestors' background-color, which is why a background color set on a page's body doesn't automatically also appear behind every nested box unless that box's own background is also transparent, letting the body's color show through.
Remember background-color is NOT inherited, unlike color — a background set on a parent only shows through a child if that child's own background stays transparent, it isn't automatically applied to descendants the way text color is.
.alert {
background-color: #fff3cd;
padding: 16px;
}2Practical Example
Here is a real-world application of Background-color showing how it is used in production CSS code.
body {
background-color: navy;
}
.card {
background-color: white;
}3Best Practices
Follow these guidelines when working with Background-color:
1. Set an explicit background-color rather than relying on transparency when an element genuinely needs a solid, opaque background behind its content
2. Use rgba() or a similar alpha-channel format for background-color when you want a semi-transparent tint that lets whatever's behind it partially show through
3. Remember background-color isn't inherited, so a child element needs its own explicit background-color, or to remain transparent, rather than automatically picking up a parent's background
Tip: Remember background-color is NOT inherited, unlike color — a background set on a parent only shows through a child if that child's own background stays transparent, it isn't automatically applied to descendants the way text color is.
.alert {
background-color: #fff3cd;
padding: 16px;
}