👀 Live Preview
Text colored with the HTML color attribute on <font> elements:
Red text · Blue hex text · Green text

The color attribute in HTML is used to specify the text color inside various legacy HTML elements. By setting the color attribute, developers can customize the appearance of text to enhance the visual design of a web page.
red, blue, green.
#FF0000, #00FF00.
Where color applies.
CSS color property.
Dynamic text colors.
Use CSS instead.
colorThe primary purpose of the color attribute is to define the color of text content within an HTML element. This allows for a more personalized and aesthetically pleasing presentation of textual information on a webpage.
The HTML color attribute is not recommended for new projects. Use the CSS color property instead for better control, accessibility, and maintainability.
Add color to a supported legacy element with a color name or hex code:
<font color="red">Red text</font>
<font color="#0000FF">Blue text</font>red) or hex code (e.g. #FF0000).<font> and <basefont>.<p> or <div>.rgb() and hsl() colors, use CSS color instead.The color attribute accepts values that represent different colors. These values can be specified using various methods, including:
red, green, or blue can be used.#RRGGBB provide a wide range of color options.rgb(red, green, blue) is best applied with CSS color, not the legacy HTML attribute.hsl(hue, saturation, lightness) allows specifying colors based on hue, saturation, and lightness via CSS.<font color="red">Named color</font>
<font color="#00FF00">Hex color</font>
<p style="color: rgb(0, 0, 255);">RGB via CSS</p>
<p style="color: hsl(120, 100%, 50%);">HSL via CSS</p>| Format | Example | CSS Alternative |
|---|---|---|
| Color name | color="red" | color: red |
| Hex code | color="#FF0000" | color: #FF0000 |
| RGB | Use CSS instead | color: rgb(255, 0, 0) |
| HSL | Use CSS instead | color: hsl(0, 100%, 50%) |
| On font | <font color> | Primary legacy use |
| HTML5 status | Deprecated | Use CSS for new code |
| Element | Supported? | Notes |
|---|---|---|
<font> | Yes (legacy) | Primary use for text color |
<basefont> | Yes (legacy) | Default text color for document |
<body> | Yes (legacy) | Page text color in HTML4 |
<p>, <div> | No | Use CSS color |
<input type="color"> | No | Different feature — color picker input |
Color names, hex codes, RGB and HSL via CSS, a basic example, and dynamic JavaScript color changes.
Text colored with the HTML color attribute on <font> elements:
Red text · Blue hex text · Green text
Common color names like red, green, or blue can be used:
<font color="red">This text is in red color.</font>Hex codes such as #RRGGBB provide a wide range of color options:
<font color="#00ff00">This text is in green color.</font>Using the RGB format, you can define colors with the syntax rgb(red, green, blue) via CSS:
<p style="color: rgb(0, 0, 255);">This text is in blue color.</p>The HSL format (hsl(hue, saturation, lightness)) allows for specifying colors based on their hue, saturation, and lightness:
<p style="color: hsl(120, 100%, 50%);">This text is in green color using HSL.</p>Let’s see how the color attribute can be applied to an HTML element:
<font color="blue">This text is in blue color.</font>In this example, the color attribute is set to blue, changing the color of the text inside the <font> element.
You can dynamically set the color attribute using JavaScript, allowing for interactive and dynamic color changes. Here’s a brief example:
<font id="dynamicText">This text will turn red using JavaScript.</font>
<script>
// Dynamically set color for an element
document.getElementById("dynamicText").setAttribute("color", "#ff0000");
// Modern alternative:
// document.getElementById("dynamicText").style.color = "#ff0000";
</script>In this script, the color attribute is set to red (#ff0000) for an element with the id dynamicText. This dynamic approach can be beneficial when responding to user actions or other events. For new code, prefer style.color.
Add a color name or hex value to a supported legacy element.
The user agent resolves the color value to a display color.
The element’s text renders in the chosen foreground color.
In modern projects, CSS color achieves the same result with more flexibility.
The HTML color attribute is deprecated in HTML5 but still rendered by browsers on legacy elements like <font>.
Use CSS color for all new text styling.
Bottom line: Browsers still paint the HTML color attribute on font elements, but CSS is the standard for new code.
color for all new projectscolor attribute on <p> or <div>color<font> tags for layoutThe color attribute is a valuable tool for customizing the appearance of text in HTML, especially in legacy markup. By using different color values and techniques, you can create visually engaging and well-designed web pages.
For modern development, reach for CSS color instead. It works on any element, supports rgb(), hsl(), and custom properties, and keeps styling separate from structure.
colorBookmark these before coloring your HTML text.
red, #FF0000.
ValuesLegacy scope.
Scopecolor property.
ModernsetAttribute.
ScriptReadability.
A11y<font> and <basefont>.color is the modern property used in stylesheets and inline styles.color on <p>, <div>, and other modern elements.rgb() via CSS color.element.style.color = "#ff0000" for modern code, or setAttribute("color", "#ff0000") on legacy font elements.color property in a stylesheet or inline style attribute.Practice the legacy color attribute and compare it with CSS color in the Try It editor.
6 people found this page helpful