HTML color Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The color attribute sets text color on the legacy <font> element (named color or #RRGGBB). Older pages also used it on <hr> for the rule color.

For new work, use the CSS color property. Do not confuse this attribute with <input type="color"> (a color picker).

Deprecated.

Do not use color (or <font>) in new HTML. Prefer CSS. Browsers still honor many values for old pages — learn it to read legacy markup.

HTML Syntax

syntax.html
<font color=" colorname | #RRGGBB"> … </font>

Legacy <hr color="…"> used the same value forms. Prefer CSS for both text and rules.

Attribute Values

Common value forms and what to use instead:

ValueDescriptionTry it
red, blue, …Named CSS/HTML color. Prefer color: red in CSSTry it
#RRGGBBHex color, e.g. #FF0000. Prefer CSS color: #FF0000Try it
#RGBShort hex (often accepted). Prefer full hex or CSSTry it
On <hr>Legacy rule color. Prefer CSS border-color / backgroundTry it
CSS replacementUse color in a stylesheet — not the HTML attributeTry it

Live Preview

Change the legacy color value on a <font> sample. For new pages, use CSS instead.

Deprecated attribute demo. Prefer CSS color for real projects.

font demo

Sample text using the color attribute.

color="red" — prefer color: red in CSS

HTML Examples

Short study snippets. Use Try It Yourself for a live editor. Prefer example 3 for new work.

Example 1 — Named color on font

Legacy pattern: wrap text in <font> and set a color name.

HTML
<p>
  <font color="red">This text is red.</font>
</p>
<p>
  Normal text without a color attribute.
</p>
Try It Yourself

How It Works

  1. Wrap the text in <font> — that is where color applies.
  2. Use a color name such as red, blue, or green.
  3. Only that span changes. Sibling text keeps the page default color.
  4. Deprecated path. Learn it for old pages; ship CSS for new ones.

Example 2 — Hex on font and hr

Hex codes give precise colors. <hr color> is obsolete presentational markup.

HTML
<p>
  <font color="#FF6600">Orange heading-style text.</font>
</p>
<hr color="#336699">
<p>Text after a colored rule (legacy).</p>
Try It Yourself

How It Works

  1. #RRGGBB sets red, green, and blue channels (here orange text).
  2. hr color tried to tint the thematic break — obsolete; browsers differ.
  3. Keep contrast in mind. Light text on light backgrounds fails accessibility.
  4. Prefer CSS color and border-color for predictable results.

Example 3 — CSS color replacement

Modern, recommended approach — no color attribute and no <font>.

HTML
<style>
  .accent { color: #c62828; }
  .rule { border: none; border-top: 2px solid #336699; }
</style>

<p class="accent">This text uses CSS color.</p>
<hr class="rule">
<p>Thematic break styled with a border.</p>
Try It Yourself

How It Works

  1. Class + CSS separates structure from presentation.
  2. color on the class styles text the modern way.
  3. hr is restyled with border-top instead of a color attribute.
  4. Reusable. One class can style many elements across the site.

Edge Cases & Pitfalls

Treat HTML color as historical — CSS is the durable approach.

deprecated

Not for new HTML

Validators flag presentational attributes. Replace <font color> when you edit old templates.

scope

Not global — not on every tag

color is not a global attribute. Putting it on <p> or <div> is invalid; use CSS instead.

confusion

Not type="color"

A color input lets users pick a color. The color attribute paints legacy text.

a11y

Contrast still matters

Bright yellow on white fails readability. Check contrast whether you use attributes or CSS.

bgcolor

Different from bgcolor

bgcolor set background color. color set foreground text. Both are legacy — use CSS.

Browser Support

color is a legacy HTML attribute on <font> (and historically <hr>). Engines still honor many values for old documents.

✓ Deprecated · Still parsed

color

Widely recognized for legacy font color. New sites should use the CSS color property (and CSS borders for hr).

Legacy Compatibility only
Google Chrome Legacy font color support
Supported*
Mozilla Firefox Legacy font color support
Supported*
Apple Safari Legacy font color support
Supported*
Microsoft Edge Legacy font color support
Supported*
Opera Legacy font color support
Supported*
Samsung Internet Legacy font color support
Supported*
Internet Explorer Full legacy support
Supported*
color Supported (deprecated)

Bottom line: *Supported for old pages — not recommended. Migrate to CSS color when you can.

Key Takeaways

  • Role: set foreground color on legacy <font> (names or hex).
  • Status: deprecated — read old HTML; do not ship new.
  • Replace with: CSS color (and CSS borders for <hr>).
  • Not the same as <input type="color">.

One line: learn HTML color for legacy <font> — ship CSS color instead.

Frequently Asked Questions

On legacy font (and historically hr), color sets the foreground text or rule color using a color name or #RRGGBB hex value.
Yes. It is a legacy presentational attribute. Prefer the CSS color property (and border-color for hr). Do not use it in new pages.
Primarily font. Older markup also used it on hr. It is not a global attribute and does not apply to p or div by itself.
No. The color attribute styles legacy text. An input with type=color is a color picker control — a different feature.
Named colors such as red or blue, and hex codes such as #FF0000. Use CSS for rgb(), hsl(), and modern color functions.
Use CSS color for text. For a thematic break, style hr with CSS border (or background). Keep presentation in stylesheets, not HTML attributes.

Next: cols

Set the visible width of a textarea in average character widths.

cols tutorial →

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.

8 people found this page helpful