The purpose of color is to define an element foreground color and the currentColor reference used by related properties. It affects text and other foreground-dependent styles, not the background fill.
What is the purpose of the color property?
Purpose in one linecolor sets foreground color (mainly text) and provides a shared value via currentColor.
Affects | Does not affect |
|---|---|
Text color, inherited foreground styling, | Background paint (use |
Borders/icons when explicitly set to | Layout properties like margin, padding, width |
Example: one source of truth with currentColor
.chip {
color: #334155;
border: 1px solid currentColor;
}
.chip svg {
fill: currentColor;
}
Now text, border, and icon all stay in sync when you change one property (color). This is the practical power of the property.
.article { color: #1f2937; }
.article p {
/* inherits #1f2937 automatically */
}
Many UI bugs come from mixing foreground and background concerns. If you separate color and background-color cleanly, theming and accessibility become easier.
Practical scenario
You build a button system where icon and label must always match in all states (default/hover/disabled). Using currentColor avoids duplicated color declarations.
Common pitfalls
- Changing text color but forgetting icon/border colors.
- Using very low-contrast foreground colors on tinted backgrounds.
- Treating
colorandbackground-coloras interchangeable.
currentColor simplifies maintenance, but only if your team consistently uses it in component CSS.Think of color as your component foreground theme knob. Turn it once, and every part using currentColor follows.
coloris for foreground/text, not background.- It inherits, which reduces repetitive CSS.
currentColorlets borders/icons stay aligned with text.
Use the relevant interview-question hub first, then move into a concrete study plan before targeted company sets.