Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Colors and Backgrounds

The color property

Reference for the CSS color property: how it sets text color, how currentcolor reuses it, accepted color notations, inheritance, contrast tips and examples.

The color property sets the foreground color of an element: the color of its text and text decorations. It also defines the value of the special keyword currentcolor, which many other properties (borders, outlines, shadows, SVG fills) use when you do not give them a color of their own.

Because color is inherited, you usually set it once on body or :root and let every descendant pick it up. You only override it where something should look different.

CSS
body { color: #1f2933; }
a { color: oklch(55% 0.2 260); }
.error { color: crimson; }

Try it

Setting and inheriting text color
currentcolor in action

Syntax

CSS
color: <color>;

color: red;
color: #09f;
color: rgb(0 120 255 / 80%);
color: currentcolor;
  • Initial value: CanvasText, the browser's default text color (black in a light scheme, white in a dark one when color-scheme allows it)
  • Applies to: all elements and text
  • Inherited: yes
  • Animatable: yes (as a color)
  • Computed value: the computed color; currentcolor on color itself behaves like inherit

Values

Value Description
Named color A keyword such as red, rebeccapurple or transparent.
Hex #rgb, #rrggbb, and the forms with alpha: #rgba, #rrggbbaa.
rgb() / hsl() / hwb() Colors in the sRGB model; alpha is written after a slash.
lab() / lch() / oklab() / oklch() / color() Modern notations that can express colors beyond sRGB.
color-mix() / light-dark() Computed colors, mixed from others or chosen by color scheme.
currentcolor The element's own computed color (on color itself it means the inherited value).
System color Keywords such as CanvasText or LinkText that follow the user's theme.

See color values for every notation in detail.

Usage notes

  • Set it on a high ancestor. Define the body text color once and override only the exceptions; do not repeat color on every element.
  • currentcolor keeps things in sync. Borders, icons drawn with fill: currentColor and text-decoration all follow the text color, so changing color in a hover rule updates them together.
  • Contrast matters. WCAG asks for a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text. Never use color alone to convey meaning (add an icon or text for errors).
  • Always pair a text color with a background color when you set one of them on a component. A user style sheet or dark mode can otherwise leave you with, for example, dark text on a dark background.
  • Links and form controls have their own default colors from the browser style sheet. Set color on them explicitly, or use color: inherit.
  • Alpha in text colors. A translucent color is blended with whatever is behind the text; this is different from opacity, which fades the whole element.

Browser support

The property and the classic notations are supported in every browser. Newer color notations such as oklch() and color-mix() are available in current browsers, but check a compatibility table if you must support older ones.