color
Widely availableSince 201597% of users
Sets the color of an element's text. Child elements inherit it, and anything set to currentcolor, like a border or an SVG icon's fill, uses it too.
What's modern
From web-features, MDN's browser data and our snippets, checked dailyClassicIt has worked everywhere since July 2015.
See how modern your own CSS is.Check your CSS →
Quick facts
- Initial value
CanvasText- Inherited
- Yes
- Applies to
- all elements and text
- Animation type
- byComputedValueType
Quick example
.button {
color: oklch(45% 0.15 250);
border: 2px solid currentcolor;
}Values
<named-color><hex-color>rgb()hsl()hwb()lab()lch()oklab()oklch()color()color-mix()light-dark()<system-color>currentcolortransparentExamples
Set the text color once
:root {
--text: #1f2937;
}
body {
color: var(--text);
}color is inherited, so setting it on body colors the text of the elements inside it. Elements that get a color from the browser's default styles, like links, keep their own.
Icons and borders that follow the text
.button {
color: #0b5394;
border: 1px solid currentcolor;
}
.button svg {
fill: currentcolor;
}currentcolor resolves to the element's color value. Change color on the button and the border and the icon change with it.
Different text colors for light and dark
:root {
color-scheme: light dark;
}
body {
color: light-dark(#111, #eee);
}light-dark() uses the first color when the element's color scheme is light and the second when it is dark. color-scheme: light dark lets the page follow the user's setting.
Common pitfalls
- Links keep their own colorThe browser's default styles give links a color of their own, so they do not pick up the color of their parent. Add a { color: inherit; } if links should match the surrounding text.
- opacity fades more than the textopacity applies to the whole element and everything inside it, backgrounds and children included. To fade only the text, give color an alpha value, like rgb(0 0 0 / 60%).
- Check the contrastWCAG 2 level AA asks for a contrast ratio of at least 4.5:1 between normal text and its background, and 3:1 for large text. Light gray on white often falls short.
color browser support
BaselineWidely availableThis feature is well established and works across many devices and browser versions. It has been available across browsers since 2015.Safe to use without fallbacks.
Usage97%of people can use this3% use a browser without it.
Browsers
1+
1+
1+
12+Mobile
18+Android
4+Android
1+iOS