How to change text color in HTML
Use the CSS color property. It sets the color of an element's text, and every element inside it inherits the same color unless it sets its own.
The property is named color, not font-color or text-color. Those names do not exist in CSS and are silently ignored.
Why not the font tag
Old tutorials show <font color="red">. That tag was removed from HTML years ago: validators flag it as an error, and it mixes styling into the markup, so changing a color means editing every tag by hand. Browsers still draw it for compatibility, which is the only reason it seems to work.
<!-- obsolete -->
<font color="red">Warning</font>
<!-- use this -->
<span style="color: red;">Warning</span>
<!-- or better, a class you can change in one place -->
<span class="warning">Warning</span>
Ways to write the color
color accepts every CSS color format. The most common four:
| Format | Example | Notes |
|---|---|---|
| Named | color: tomato; | 148 named colors, handy for quick tests |
| Hex | color: #2563eb; | The most common in design files |
| rgb() | color: rgb(37 99 235); | Red, green and blue from 0 to 255 |
| hsl() | color: hsl(221 83% 53%); | Hue, saturation, lightness: easy to make lighter or darker |
Hex, rgb() and hsl() can take an alpha channel for semi-transparent text, such as #2563eb80 or rgb(37 99 235 / 50%). The CSS colors page explains every format.
Coloring a whole page, a heading or a section
Set the color once on body and let inheritance do the rest, then override where needed:
A soft near black such as #111827 or #374151 on white is easier on the eyes than pure #000000 and still reads as black.
Link colors
Links are the exception to inheritance: the browser gives them their own blue (and purple once visited), so a color on the parent does not reach them. Set it on the link, or tell the link to inherit:
:hover, :visited and :focus-visible let you change the color per state; the hover page covers them. When a link is the same color as the text around it, keep its underline so it is still recognizable as a link.
Make the text readable: contrast
Text color is only half of the pair; the background is the other half. WCAG asks for a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text (about 24px, or 19px bold).
Light gray placeholder-style text is the most common failure. Chrome and Firefox developer tools show the contrast ratio when you inspect a text color.
currentColor: reuse the text color
currentColor is a keyword equal to the element's color. Borders, outlines and inline SVG icons can use it, so one color change recolors the text and its decoration together:
Common mistakes
- Writing
font-colorortext-color. The property iscolor. - Using the
<font>tag. It is obsolete; use CSS. - Expecting links to inherit. Set
a { color: ... }orcolor: inherit. - Color as the only signal. "Fields in red are required" fails for readers who cannot tell red apart. Add text or an icon.
- Low contrast gray text. Check the ratio: 4.5:1 or more for body text.
- Using
opacityto lighten text. It fades the whole element, background and children included. Use a lighter color or an alpha color instead.
Frequently Asked Questions
How do I change the font color in HTML?
Use the CSS color property, in a stylesheet or a style attribute: <p style="color: #2563eb;">Blue text</p>. The old <font color> tag is obsolete.
Is the <font> tag still supported?
Browsers still draw it so that very old pages keep working, but it is obsolete in HTML and validators report it as an error. Use CSS color instead.
How do I change the color of one word?
Wrap the word in a <span> and give it a color: This is <span style="color: #dc2626;">red</span>. Use <strong> or <em> instead of <span> if the word is also important or stressed.
Why doesn't my link change color when I set color on the parent?
Links have their own color from the browser's stylesheet, so they do not inherit the parent's. Set it on the link itself (a { color: #2563eb; }) or use a { color: inherit; } to follow the parent.
Is it font-color or color in CSS?
It is color. There is no font-color or text-color property; the browser ignores them.