HTML color Attribute

Definition
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.
Syntax
HTML Syntax
<font color=" colorname | #RRGGBB"> … </font>
Legacy <hr color="…"> used the same value forms. Prefer CSS for both text and rules.
Values
Attribute Values
Common value forms and what to use instead:
| Value | Description | Try it |
|---|
red, blue, … | Named CSS/HTML color. Prefer color: red in CSS | Try it |
#RRGGBB | Hex color, e.g. #FF0000. Prefer CSS color: #FF0000 | Try it |
#RGB | Short hex (often accepted). Prefer full hex or CSS | Try it |
On <hr> | Legacy rule color. Prefer CSS border-color / background | Try it |
| CSS replacement | Use color in a stylesheet — not the HTML attribute | Try it |
Try it
Live Preview
Change the legacy color value on a <font> sample. For new pages, use CSS instead.
Code
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.
<p>
<font color="red">This text is red.</font>
</p>
<p>
Normal text without a color attribute.
</p>
This text is red.
Normal text without a color attribute.
Browsers still paint the named color for compatibility.
How It Works
- Wrap the text in
<font> — that is where color applies. - Use a color name such as
red, blue, or green. - Only that span changes. Sibling text keeps the page default color.
- 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.
<p>
<font color="#FF6600">Orange heading-style text.</font>
</p>
<hr color="#336699">
<p>Text after a colored rule (legacy).</p>
Orange heading-style text.
Text after a colored rule (legacy).
hr color support varies; CSS borders are more reliable.
How It Works
- #RRGGBB sets red, green, and blue channels (here orange text).
- hr color tried to tint the thematic break — obsolete; browsers differ.
- Keep contrast in mind. Light text on light backgrounds fails accessibility.
- Prefer CSS
color and border-color for predictable results.
Example 3 — CSS color replacement
Modern, recommended approach — no color attribute and no <font>.
<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>
This text uses CSS color.
Thematic break styled with a border.
How It Works
- Class + CSS separates structure from presentation.
- color on the class styles text the modern way.
- hr is restyled with
border-top instead of a color attribute. - Reusable. One class can style many elements across the site.
Edge Cases & Pitfalls
Treat HTML color as historical — CSS is the durable approach.
deprecatedNot for new HTML
Validators flag presentational attributes. Replace <font color> when you edit old templates.
scopeNot global — not on every tag
color is not a global attribute. Putting it on <p> or <div> is invalid; use CSS instead.
confusionNot type="color"
A color input lets users pick a color. The color attribute paints legacy text.
a11yContrast still matters
Bright yellow on white fails readability. Check contrast whether you use attributes or CSS.
bgcolorDifferent from bgcolor
bgcolor set background color. color set foreground text. Both are legacy — use CSS.
Compatibility
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.
Remember
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
Developer, cloud engineer, and technical writer
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