CSS color Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Typography & Color

What You’ll Learn

The color property is one of the most essential CSS properties. It sets the color of text so you can improve readability, hierarchy, and visual design on your pages.

01

Text Color

Foreground text.

02

Syntax

Any CSS color.

03

Inherited

Flows to children.

04

Named & Hex

blue, #ff5733.

05

RGB & HSL

Functional colors.

06

currentColor

Match text color.

Definition and Usage

The color CSS property is one of the most commonly used properties. It allows you to set the color of the text content of an element — including paragraph text, headings, links, and list items.

By defining text color, you can improve the readability, aesthetics, and overall design of your web pages. The property accepts any valid CSS color value.

💡
Beginner Tip

color styles text, not backgrounds. Use background-color for the area behind content. Pair both for good contrast.

📝 Syntax

The syntax for color is straightforward — the value is any valid CSS color:

syntax.css
selector {
  color: color;
}

Basic Example

color-blue.css
p {
  color: blue;
}

Syntax Rules

  • The initial value is browser-dependent (text is usually dark in light mode).
  • Accepts named colors, hex, rgb(), hsl(), and currentColor.
  • The property is inherited — child elements receive the parent’s text color.
  • Also affects text decorations like underlines and overlines.
  • Use with sufficient contrast against the background for accessibility.

⚡ Quick Reference

QuestionAnswer
Initial valueBrowser default (typically dark text in light mode)
Applies toAll elements (text and text decorations)
InheritedYes
AnimatableYes, by computed color value
Common useBody text, headings, links, and labels

💎 Property Values

The color property accepts standard CSS color values. Here are the most common formats:

ValueExampleMeaning
Named colorcolor: blue;A color keyword such as blue, red, or green.
Hexadecimalcolor: #ff5733;A hex code representing a color.
RGBcolor: rgb(255, 87, 51);Red, green, and blue channels from 0 to 255.
HSLcolor: hsl(9, 100%, 60%);Hue, saturation, and lightness values.
currentColorcolor: currentColor;Uses the element’s computed color value (often for borders and icons).
blue #ff5733 green purple

Color Format Quick Guide

FormatWhen to use it
Named colorsQuick demos and learning — e.g. color: coral;
Hex (#rrggbb)Design handoffs and precise brand colors — e.g. #2563eb
rgb() / rgba()When you need transparency with the alpha channel
hsl() / hsla()Adjusting lightness or saturation without changing hue
var(--token)Theme colors stored once and reused across the site

👀 Live Preview

Four paragraphs styled with different color values — named blue, red, green, and HSL purple.

This paragraph uses a blue text color.

This paragraph uses a red text color.

This paragraph uses a green text color.

This paragraph uses an HSL purple text color.

Examples Gallery

Try named colors, hex values, HSL, and CSS variables for theme text colors.

🎨 Basic Text Colors

Start with the reference example — change paragraph text to blue with a named color.

Example 1 — Blue Text with a Named Color

Change the text color of a paragraph to blue.

color-blue.html
<style>
  p {
    color: blue;
  }
</style>

<p>This is a paragraph with blue text.</p>
Try It Yourself

How It Works

The named color blue applies to all text inside the paragraph element.

Example 2 — Hex Color on a Heading

Use a hexadecimal color for precise brand-colored headings.

color-hex.html
<style>
  h2 {
    color: #ff5733;
  }
</style>

<h2>Brand-colored heading</h2>
Try It Yourself

How It Works

Hex colors like #ff5733 give exact control over the text color value.

🛠 Functional Colors

Use HSL and CSS variables when you need flexible, theme-friendly text colors.

Example 3 — HSL Text Color

Set text color with HSL — easy to adjust lightness for muted or emphasis text.

color-hsl.css
.muted {
  color: hsl(215 16% 47%);
}

.accent {
  color: hsl(9, 100%, 60%);
}
Try It Yourself

How It Works

HSL separates hue, saturation, and lightness — change the last value to lighten or darken text without picking a new hex code.

Example 4 — Theme Color with CSS Variables

Store text colors in custom properties and apply them across your layout.

color-theme.css
:root {
  --text-primary: #1e293b;
  --text-link: #2563eb;
}

body { color: var(--text-primary); }
a { color: var(--text-link); }
Try It Yourself

How It Works

Because color is inherited, setting it on body styles all text unless a child overrides it — links often need their own rule.

♿ Accessibility & Contrast

  • Check contrast — Text color must have enough contrast against the background (WCAG recommends 4.5:1 for normal text).
  • Do not rely on color alone — Use labels, icons, or weight to convey meaning, not color only.
  • Test link colors — Links should be distinguishable from body text and have a visible focus state.
  • Support dark mode — Use CSS variables or media queries to adjust text colors in dark themes.

🧠 How color Works

1

You set a color value

Choose a named color, hex, rgb, hsl, or CSS variable in your stylesheet.

CSS rule
2

Browser computes the color

The value becomes the element’s computed foreground color for text and decorations.

Cascade
3

Children inherit by default

Unless overridden, nested text elements receive the same color from their parent.

Inheritance
=

Styled, readable text

Your content displays in the chosen color with clear hierarchy and design consistency.

Universal Browser Support

The color property is universally supported across all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera, as well as older browsers.

Baseline · All browsers

Text color everywhere

Every browser supports color — it is one of the original CSS properties and remains essential today.

100% Global browser support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions
Full support
Opera All versions
Full support
color property 100% supported

Bottom line: Use color with confidence in every project. Modern color functions like oklch() are supported in newer browsers as an optional enhancement.

Conclusion

The color property is an essential tool for styling text on your web pages. By customizing text color, you can enhance the visual appeal and readability of your content.

Experiment with named colors, hex, RGB, HSL, and CSS variables to see how this property can improve the look and feel of your web projects.

💡 Best Practices

✅ Do

  • Set base text color on body and override for headings or links
  • Use CSS variables for theme text colors
  • Check contrast against the background color
  • Use HSL when you need lighter or darker shades of the same hue
  • Pair with background-color for readable blocks of content

❌ Don’t

  • Confuse color with background-color
  • Use low-contrast gray text on light backgrounds
  • Rely on color alone to convey important information
  • Hard-code the same hex value dozens of times — use variables
  • Forget to style link and visited states separately when needed

Key Takeaways

Knowledge Unlocked

Five things to remember about color

Use these points when styling text on your pages.

5
Core concepts
02

Inherited

Flows to children.

Cascade
🖌 03

Many formats

Named, hex, rgb, hsl.

Values
📝 04

currentColor

Match text elsewhere.

Keyword
🛸 05

Universal

Works everywhere.

Browser

❓ Frequently Asked Questions

color sets the foreground color of an element's text and its decorations, such as underlines. It controls the color of text content, not the background.
The initial value depends on the browser, but text is usually black or dark gray in light mode. color is inherited, so child elements receive the parent's text color unless overridden.
color styles text and text decorations. background-color fills the area behind the content. Use both together for readable contrast.
currentColor is a keyword that uses the element's computed color value. It is useful for borders and icons that should match the text color.
Yes. You can set color to var(--brand-text) or any other custom property that holds a valid CSS color value.

Practice in the Live Editor

Open the HTML editor, set color: blue on a paragraph, and try hex and HSL values.

HTML Editor →

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.

5 people found this page helpful