The color property

color sets the text color (and everything drawn in the text color by default, such as borders with currentColor). It is inherited, so it is handy to set it on parent elements.

Syntax

color: red;
color: #0284c7;
color: rgb(2 132 199);
color: rgb(2 132 199 / 50%);  /* with transparency */
color: hsl(200 98% 39%);
Initial value
CanvasText
Inherited
yes
Applies to
all elements and text

Values

ValueWhat it does
reda color name — CSS has over 140 of them
#0284c7hexadecimal #rrggbb (or short #rgb); #rrggbbaa adds transparency
rgb()red, green and blue from 0 to 255; after / comes the transparency
hsl()hue (0–360°), saturation and lightness in percent — handy for shades of one color
currentColorthe current color value: a border, shadow or icon takes the text color

Example

.named { color: red; }
.hex { color: #0284c7; }
.rgb { color: rgb(22 163 74); }
.hsl { color: hsl(280 70% 45%); }
.box {
  color: #b45309;
  border: 2px solid currentColor;
  padding: 8px;
}
<p class="named">color: red</p>
<p class="hex">color: #0284c7</p>
<p class="rgb">color: rgb(22 163 74)</p>
<p class="hsl">color: hsl(280 70% 45%)</p>
<div class="box">a currentColor border — the same color as the text</div>

Result

▶ Open in HTML Editor

Good to know

  • color is inherited: set it on body and it applies to all text until a descendant sets its own.
  • The initial value is the system text color CanvasText (usually black).
  • The background color is a different property, background-color. For readability, normal text needs a contrast of at least 4.5 : 1 with its background (WCAG).

Sources and specification

See also