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.
Fundamentals
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.
Foundation
📝 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.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
Browser default (typically dark text in light mode)
Applies to
All elements (text and text decorations)
Inherited
Yes
Animatable
Yes, by computed color value
Common use
Body text, headings, links, and labels
Reference
💎 Property Values
The color property accepts standard CSS color values. Here are the most common formats:
Value
Example
Meaning
Named color
color: blue;
A color keyword such as blue, red, or green.
Hexadecimal
color: #ff5733;
A hex code representing a color.
RGB
color: rgb(255, 87, 51);
Red, green, and blue channels from 0 to 255.
HSL
color: hsl(9, 100%, 60%);
Hue, saturation, and lightness values.
currentColor
color: currentColor;
Uses the element’s computed color value (often for borders and icons).
blue#ff5733greenpurple
Deep Dive
Color Format Quick Guide
Format
When to use it
Named colors
Quick 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
Preview
👀 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.
Hands-On
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>
Because color is inherited, setting it on body styles all text unless a child overrides it — links often need their own rule.
A11y
♿ 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.
Compatibility
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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions
Full support
OperaAll versions
Full support
color property100% supported
Bottom line: Use color with confidence in every project. Modern color functions like oklch() are supported in newer browsers as an optional enhancement.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about color
Use these points when styling text on your pages.
5
Core concepts
🎨01
Text color
Foreground content.
Purpose
⚙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.