HOW-TO

How to change text color in HTML (CSS color)

The color property in a style attribute, a class and a stylesheet, the value formats, coloring links and part of a sentence, contrast, and fixes when the color will not change.

4 min read·

To change text color in HTML, set the CSS color property on the element: <p style="color: red;">Overdue</p>. The old <font color="red"> tag still works in most browsers, but it was removed from the HTML standard, so use CSS instead.

Three places to set the color

A class is the easiest to change later: edit one line and every element with that class updates.

  • ✓On one element, with a style attribute: <h1 style="color: #1a4fd6;">Q3 report</h1>.
  • ✓On every element of a kind, in a <style> block in the <head>: <style> h2 { color: #1a4fd6; } </style>.
  • ✓On chosen elements, with a class: <style> .warning { color: #b42318; } </style> then <p class="warning">Payment failed</p>.

Color value formats

  • ✓Names: red, navy, darkgreen, gray. Browsers know 140 or so named colors.
  • ✓Hex: #1a4fd6, or the short form #333 for #333333. This is what most design tools give you.
  • ✓rgb(): rgb(26, 79, 214). Add a fourth value for transparency: rgb(26 79 214 / 60%).
  • ✓hsl(): hsl(220 78% 47%). Handy when you want a lighter or darker shade of the same hue; change only the last number.

Color the whole page or one word

For the whole page, set color on body: <style> body { color: #222; } </style>. Text inside inherits it unless something sets its own color.

For one word inside a sentence, wrap it in a <span>: Status: <span style="color: green;">approved</span>.

To change the background behind the text, use background-color, not color: <p style="background-color: #fff3c4;">Draft</p>.

Link colors

Links ignore the color on their parent and use the browser default blue and purple. Set it on the a element itself:

<style> a { color: #1a4fd6; } a:visited { color: #6b3fc2; } a:hover { color: #0b2f8a; } </style>

When the color does not change

  • ✓Another rule wins: a more specific selector or a later rule overrides yours. Right-click the text, choose Inspect, and look for your rule crossed out in the Styles panel.
  • ✓Typo in the value: color: #1a4fd (five digits) or colour: red is ignored with no error. Check the spelling and count the hex digits.
  • ✓The text is a link: set the color on a, as above.
  • ✓Missing semicolon: style="color: red background: yellow" breaks both. Separate each property with a semicolon.
  • ✓Cached file: after you save, reload with Ctrl+Shift+R (Cmd+Shift+R on a Mac).

Keep it readable

Light gray on white or red on green is hard for many people to read. Aim for a contrast ratio of at least 4.5:1 for body text. Chrome shows the ratio when you click the color swatch in Inspect.

Pages made with AI tools

Pages from Claude, ChatGPT and other tools often use Tailwind, where color is a class such as text-red-600 or text-slate-700. Swap the class on the element instead of adding a style attribute, so the two do not fight. If the page has a dark mode, check the text color in both.

Share the page as a link

Colors look different on different screens, so check the page on a phone before you send it. With FileShare Pro you upload the .html file from the dashboard, copy the link and send it; it opens as a page in any browser and the person opening it needs no account. To change a color after you send it, fix the file and upload it to the same link. New to HTML? Start with how to create an HTML file. Sign up free to share your first page.

Frequently asked

How do I change the font color in HTML?

Use the CSS color property, for example <p style="color: blue;">Text</p>, or set it in a class in a <style> block.

Is the <font color> tag still allowed?

It is obsolete. Most browsers still show it, but use CSS color instead.

How do I color one word in a sentence?

Wrap the word in a <span> and give it a color: <span style="color: green;">approved</span>.

Why are my links still blue?

Links do not inherit the parent color. Set color on the a element, plus a:visited and a:hover if you want.

Got a page to share?

Drop the file, copy the link — live in seconds, free plan included.

Start sharing free