HTML Text Color
The color property sets text color in HTML and CSS.
Pick a text color and a background below — the sample paragraph recolors
instantly, the code appears in all four syntaxes, and the contrast checker
scores the pair live.
A headline in your text color
This paragraph is colored with the color you picked. The same color is written four different ways below — hex, name, RGB, and HSL — and every one of them means exactly the same color.
Contrast ratio: —
WCAG AA needs 4.5:1 for normal text and 3:1 for large text (18pt+, or 14pt bold+). AAA needs 7:1 for normal text and 4.5:1 for large text. With opacity below 100%, the ratio is measured against the color the text actually appears as on this background.
Your color in four syntaxes
#FF0000
red
rgb(255, 0, 0)
hsl(0, 100%, 50%)
How to set text color in HTML: inline style color in hex (#FF0000), named color (red), RGB/rgba, and HSL/hsla — with a live demo that recolors a paragraph and shows all four syntaxes side by side.
Set text color with the color property — as a hex code (#FF0000), a named color (red), rgb(255, 0, 0), or hsl(0, 100%, 50%). All four describe the same color; pick a color in the demo and copy whichever syntax fits your code.
Four ways to write the same color
Every color on a screen is a mix of red, green, and blue light. HTML and CSS let you write that mix in four notations. They are interchangeable — pick the one that is easiest to read for the job at hand:
| Method | Syntax | Example (red) | Best for |
|---|---|---|---|
| Hex code | #RRGGBB | #FF0000 | Exact colors copied from a picker or a design file |
| Named color | red | red | Quick, readable code when an exact named color exists |
| RGB / RGBA | rgb(255, 0, 0) | rgb(255, 0, 0) | Working with channel values, or adding transparency with rgba(255, 0, 0, 0.5) |
| HSL / HSLA | hsl(0, 100%, 50%) | hsl(0, 100%, 50%) | Adjusting a color — change the lightness to make a lighter or darker version |
Method 1: hex code
A hex code is six hexadecimal digits after a #: two for red,
two for green, two for blue. #FF0000 is pure red (red at full
strength, green and blue at zero). Hex is the format color pickers show, so
it is the fastest way to copy an exact color into your code. Three-digit
shorthand works too — #F00 means #FF0000 — and
modern browsers also accept eight digits, where the last two set the opacity
(#FF000080 is red at 50%).
<p style="color: #FF0000;">This text is red.</p>
Method 2: named color
CSS defines 148 named colors, from red and
steelblue to papayawhip and
mediumseagreen. Names are the most readable option — anyone can
guess what color: teal; looks like — but they only work when the
exact color you want has a name. There is no named color for
#FF5733, for example, so for anything specific you need hex, RGB,
or HSL. The full list, with a demo for every name, is on the
color names page.
<p style="color: red;">This text is red.</p>
Method 3: RGB and RGBA
RGB writes the three channels as decimals from 0 to 255:
rgb(255, 0, 0) is the same red as #FF0000. RGBA adds
a fourth number, alpha, from 0 (fully transparent) to 1 (fully opaque):
rgba(255, 0, 0, 0.5) is red at half opacity, so the background
shows through. Use RGBA when you want see-through text — for example, a
watermark or text over a photo.
<p style="color: rgb(255, 0, 0);">This text is red.</p> <p style="color: rgba(255, 0, 0, 0.5);">This text is half-transparent red.</p>
Method 4: HSL and HSLA
HSL describes a color the way people think about it: hue (the angle on the
color wheel, 0–360), saturation (0–100%), and lightness (0–100%).
hsl(0, 100%, 50%) is pure red. HSL is the best format for
adjusting a color — keep the hue and saturation, raise the lightness to 70%
for a lighter red, or drop it to 30% for a darker one. HSLA adds the same
0–1 alpha as RGBA: hsla(0, 100%, 50%, 0.5).
<p style="color: hsl(0, 100%, 50%);">This text is red.</p> <p style="color: hsl(0, 100%, 70%);">This text is a lighter red.</p>
Inline style or stylesheet?
The examples above use the style attribute, which is fine for
a one-off. For a real page, put the rule in a stylesheet instead — one rule
then colors every matching element, and you can change the color in one
place:
p.warning {
color: #FF0000;
}
An inline style attribute beats a stylesheet rule, so use it
only when you mean to override the stylesheet for that one element.
Check the contrast before you ship
Red on white scores 4.00:1 — it fails WCAG AA for normal text (4.5:1) and only passes for large text (3:1). That is the most common surprise with colored text: a color that looks fine as a button or a heading can be unreadable as body text. The demo at the top of this page scores your exact pair live — if it says Fail, darken the text or lighten the background until it passes, or use the color only for large headings. The contrast checker does the same check for any two colors.
Frequently asked questions
How do I change text color in HTML?
Use the style attribute: <p style="color: #FF0000;">text</p> — or, for a whole page, a CSS rule such as p { color: #FF0000; }. The color can be written as a hex code, a named color, rgb(), or hsl().
What is the difference between hex, RGB, and HSL for text color?
They describe the same color in different notation. Hex (#FF0000) is the most compact, RGB (rgb(255, 0, 0)) writes the channels as decimals, and HSL (hsl(0, 100%, 50%)) describes hue, saturation, and lightness, which makes it easiest to lighten or darken a color.
Can I use a color name instead of a hex code?
Yes, when the exact color has a name — CSS defines 148 named colors, including red, steelblue, and papayawhip. If your color has no exact name, use its hex, RGB, or HSL code instead; the nearest name is a different color.
How do I make text semi-transparent?
Use rgba() or hsla(): color: rgba(255, 0, 0, 0.5); makes red text at 50% opacity so the background shows through. The alpha value runs from 0 (invisible) to 1 (fully opaque).
Why does my colored text fail the contrast check?
Most bright colors are too light against a white background — pure red on white is only 4.00:1, below the 4.5:1 WCAG AA needs for normal text. Darken the text, lighten the background, or use the color only for large headings, which need just 3:1.
Related tools
Tutorials · HTML Link Color · HTML Background Color · CSS Text Color · Color Names · Contrast Checker