CSS color Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The color property sets the foreground color of an element’s text and text decorations. It also defines currentColor, which other properties can reuse (for example border-color).

It does not paint the background — that is background-color. The property is inherited, so one rule on a parent can color nested text.

Baseline · Widely available.

Not deprecated and not experimental. Supported everywhere modern browsers run, including Internet Explorer for classic color values.

CSS Syntax

syntax.css
color: <color> | currentColor | initial | inherit;

A <color> can be a name (red), hex (#2563eb), rgb(), hsl(), and more. The initial value is canvastext. The property is inherited.

Property Values

ValueDescriptionTry it
Named colorKeywords such as red or rebeccapurpleTry it
Hex#rgb, #rrggbb, optional alphaTry it
rgb()Red, green, blue channels; optional alphaTry it
hsl()Hue, saturation, lightness; optional alphaTry it
currentColorUses the element’s color; as color itself acts like inheritTry it
initialResets to the initial canvastext valueTry it
inheritTakes the parent’s text color (also the default behavior)Try it

How to Use color

Pick a readable text color, then check it against the background.

  1. Choose a color value: name, hex, rgb(), or hsl().
  2. Apply it with color: … on the element (or a parent, since it inherits).
  3. Set a contrasting background-color when needed.
  4. Reuse the same hue on borders with currentColor if you want them to match the text.
PieceRequired?Role
Color valueYesName, hex, rgb(), hsl(), …
Background contrastStrongly recommendedKeep WCAG contrast for readable text
InheritanceAutomaticChildren use the parent color unless overridden
currentColorOptionalMatch borders and icons to the text color

Live Preview

Change only color on the sample sentence. The background stays light for contrast.

color paints the text. It does not change the background.

Text

The color property sets this text.

color: #2563eb

CSS Examples

Each snippet focuses on color. Keep backgrounds light so the text stays readable. Use Try It Yourself for a live editor.

Example 1 — Hex Text Color

Set paragraph text with a hex value.

CSS
<style>
  p {
    color: #2563eb;
  }
</style>

<p>Blue text with hex</p>
Try It Yourself

How It Works

  1. Target the text. The rule applies to the p element.
  2. Use a hex color. #2563eb is a six-digit RGB hex.
  3. Paint the foreground. Only the text (and decorations) change color.
  4. Children inherit. Nested spans would use the same blue unless overridden.

Example 2 — rgb() Text Color

The same idea with channel functions.

CSS
<style>
  p {
    color: rgb(220, 38, 38);
  }
</style>

<p>Red text with rgb()</p>
Try It Yourself

How It Works

  1. Pass three channels. Red, green, and blue from 0–255.
  2. Same property. color still only sets the foreground.
  3. Optional alpha. Modern syntax allows rgb(220 38 38 / 0.8).
  4. hsl() works too. Try hsl(0 84% 50%) for a similar red by hue.

Example 3 — Match a Border with currentColor

Set text color once; the border follows automatically.

CSS
<style>
  p {
    color: #0f766e;
    border: 3px solid currentColor;
    padding: 8px;
  }
</style>

<p>Text and border share one color</p>
Try It Yourself

How It Works

  1. Set the text color. color: #0f766e is the source value.
  2. Point the border at it. currentColor reads that computed color.
  3. One change, two places. Updating color updates the border too.
  4. Default for many color props. Several properties already default to currentColor.

Edge Cases & Pitfalls

If the text looks wrong, check these first.

contrast

Low contrast is hard to read

Aim for about 4.5:1 contrast for normal text (WCAG). Light gray on white fails many readers.

background

color is not the background

Use background-color to fill behind text. Mixing them up is a common beginner mistake.

inherit

It inherits by default

Children take the parent’s color. Override on the child when you need a different shade.

currentColor

color: currentColor means inherit

When used as the value of color itself, currentColor is treated like inherit.

opacity

opacity fades the whole element

opacity affects text and background together. Prefer an alpha in the color value when only the text should be translucent.

Browser Support

color is a browser CSS property for text and foreground color. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

color

Classic values (names, hex, rgb, hsl) work in all major browsers, including Internet Explorer. Newer spaces like oklch need modern browsers.

99% Classic value support
Google Chrome 1+
Full support
Mozilla Firefox 1+
Full support
Apple Safari 1+
Full support
Microsoft Edge 12+
Full support
Opera 3.5+
Full support
Samsung Internet 1+
Full support
Internet Explorer 3+
Full support (classic values)
color (classic values) Universally supported

Bottom line: Safe everywhere for names, hex, rgb, and hsl. Use newer color functions only when you can require modern browsers. It is not a runtime API.

Key Takeaways

  • Role: set text (and decoration) color; define currentColor.
  • Formats: names, hex, rgb(), hsl(), and more.
  • Inherited: children follow the parent unless you override.
  • Accessibility: keep strong contrast with the background.

One line: color: #2563eb; paints the text; pair it with a contrasting background.

Frequently Asked Questions

It sets the foreground color of text and text decorations, and defines currentColor for other properties such as border-color when they use that keyword.
The initial value is canvastext, which is usually a dark text color in light mode. color is inherited, so children pick up the parent’s text color unless you override it.
color styles text and decorations. background-color paints behind the content. Use both with enough contrast for readable text.
currentColor means “use this element’s computed color.” Borders, outlines, and SVGs can match the text with border-color: currentColor. If you set color: currentColor, it behaves like inherit.
Aim for a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text (WCAG). Dark text on a light background, or the reverse, is the usual pattern.
It is Baseline Widely available and works in all major browsers, including Internet Explorer. Newer color functions have wider modern support. It is a browser CSS property, not a Node.js feature.

Next: column-count

Split content into a fixed number of newspaper-style columns.

column-count tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

18 people found this page helpful