Color in Different Contexts
What you'll learn: How to apply color to different parts of your webpage—text, backgrounds, borders, shadows—and how color values flow through your HTML structure.
The Core Idea
You already know how to write color values (hex, RGB, HSL, keywords), but CSS lets you apply these colors to many different properties. Each property serves a different visual purpose, and understanding where color can be used unlocks your design toolkit.
Where Color Lives
Text Color
The color property controls the color of text content:
p {
color: #333333;
}
Backgrounds
The background-color property fills the entire box behind content:
div {
background-color: rgba(100, 150, 200, 0.5);
}
Borders
Borders can be colored using border-color:
button {
border-color: hsl(200, 50%, 60%);
}
Shadows
Text and box shadows accept color values:
h1 {
text-shadow: 2px 2px 4px gray;
}
Inheritance and Cascade
Here's where it gets interesting: the color property inherits from parent elements. If you set color: blue on a <div>, all text inside that div becomes blue—unless a child element overrides it.
Background colors and border colors do not inherit—each element needs its own declaration.
Think of color inheritance like a family passing down eye color: children inherit it automatically. But background colors are like clothing: each person chooses their own unless specifically told what to wear.
Key Takeaway: Color can be applied to text, backgrounds, borders, and shadows; the color property inherits down the HTML tree, but background and border colors do not.