- <hr> tag
- <nav> tag
- <pre> tag
- Anchor tag
- Article tag
- Attributes
- Audio tag
- Blink tag
- Block elements
- Blockquote
- Bold
- Buttons
- Center text
- Comment
- Data attribute
- Div
- Entities
- Font color
- Font size
- Footer
- Form
- Global attributes
- iFrame
- Images
- Inline elements
- Inline style attribute
- Input element
- Italic
- Label
- Line break
- Linking local webpages
- Links
- Marquee tag
- Metadata
- Ordered lists
- Paragraph tag
- Script tag
- Select
- Semantic elements
- Space
- Span tag
- Strikethrough
- Style tag
- Table
- Textarea
- Underline
- Unordered lists
- Video tag
HTML
HTML Font Color: Syntax, Usage, and Examples
Changing the font color in HTML helps you make content more visually engaging and easier to understand. Whether you're writing headlines, highlighting key text, or just adding personality to a page, the ability to control text color matters.
How to Set Font Color in HTML
In the early days of HTML, developers used the <font>
tag with the color
attribute to set text color. Like this:
<font color="red">This is red text.</font>
However, modern HTML standards consider the <font>
tag obsolete. The recommended way to define font color HTML now is through CSS, either inline, embedded in a <style>
tag, or defined in an external stylesheet.
To change text color using inline CSS, you can use the style
attribute on most HTML elements:
<p style="color: blue;">This paragraph is blue.</p>
You can specify the color using:
- Named colors like
red
,blue
, orgreen
- Hex codes like
#ff0000
- RGB values like
rgb(255, 0, 0)
- HSL values like
hsl(0, 100%, 50%)
All of these methods work consistently in modern browsers and give you full control over text styling.
When to Use Font Color HTML
Changing font color can improve readability, emphasize important text, and support your site's visual design. Here are some common situations where you’d want to change font color in HTML:
Highlighting Important Text
Use color to draw attention to key messages or alerts.
<p style="color: red;">* Required fields must be completed</p>
This makes the warning stand out visually, even without using bold or larger font sizes.
Matching a Brand Style
If your site follows a particular branding color palette, you'll want to style fonts to match.
<h1 style="color: #1e90ff;">Welcome to BlueWave Media</h1>
This keeps your design consistent and professional.
Organizing Sections by Color
Color coding content can help users scan and process information more efficiently.
<h2 style="color: green;">Step 1: Register</h2>
<h2 style="color: orange;">Step 2: Confirm Email</h2>
<h2 style="color: red;">Step 3: Complete Profile</h2>
Each step stands out and signals its importance or urgency through color.
Examples of Changing Font Color in HTML
Let’s walk through some practical examples using HTML font color in modern code.
Inline Font Color Change
<span style="color: purple;">This sentence includes purple text.</span>
Useful when you only need to color a specific word or phrase without affecting the entire paragraph.
Paragraph with Colored Font
<p style="color: #228B22;">This paragraph uses a hex code to display forest green text.</p>
Hex values offer precision and are widely supported.
RGB and HSL Examples
<p style="color: rgb(255, 105, 180);">This text is hot pink using RGB.</p>
<p style="color: hsl(240, 100%, 50%);">This one’s pure blue using HSL.</p>
RGB and HSL values give you greater flexibility, especially when working with dynamic styles or JavaScript.
Color Classes in CSS
Instead of writing styles inline, define classes and reuse them throughout your HTML.
<style>
.warning {
color: red;
}
.success {
color: green;
}
.info {
color: blue;
}
</style>
<p class="warning">This is a warning message.</p>
<p class="success">Your changes have been saved.</p>
<p class="info">More information is available here.</p>
This method is cleaner and keeps your HTML more maintainable.
Learn More About Font Style and Color in HTML
Combining Font Style and Color in HTML
When you're styling text, color is just one of the tools you can use. Font style, size, and weight also matter.
You can combine all of these in a single style
attribute:
<p style="color: navy; font-family: Arial, sans-serif; font-style: italic; font-weight: bold;">
This text is bold, italic, and navy blue.
</p>
You can also apply styles with a class:
<style>
.custom-text {
color: #4B0082;
font-size: 20px;
font-weight: 600;
font-style: italic;
}
</style>
<p class="custom-text">Styled with a CSS class.</p>
This approach is especially useful if you want to apply font style and color in HTML to multiple elements without repeating yourself.
How to Change Font Color in HTML Without Inline Styles
Use embedded or external CSS instead of inline styling to keep code clean and scalable.
Embedded CSS:
<style>
h1 {
color: darkslategray;
}
</style>
<h1>This heading uses embedded CSS for color.</h1>
External CSS file (styles.css):
h1 {
color: coral;
}
In your HTML file:
<link rel="stylesheet" href="styles.css">
<h1>Heading from external stylesheet</h1>
This method keeps your design separate from content and is a best practice for modern web development.
Accessibility Considerations
When changing font color HTML, always make sure your choices meet accessibility standards. Low contrast between text and background can make your site difficult to read for people with vision impairments.
Use tools like WebAIM’s contrast checker to verify that your font color combinations provide enough contrast.
Avoid using color as the only way to convey meaning. For example, don’t just say “Click the red button”—use labels or icons as well.
Using Font Color in Tables
You can use font color in HTML tables to distinguish rows, highlight headers, or indicate status.
<table border="1">
<tr>
<th style="color: white; background-color: black;">Status</th>
<th>Name</th>
</tr>
<tr>
<td style="color: green;">Active</td>
<td>Jordan</td>
</tr>
<tr>
<td style="color: red;">Inactive</td>
<td>Avery</td>
</tr>
</table>
This provides instant visual feedback for users reviewing table data.
Dynamic Font Color with JavaScript
You can change font color dynamically with JavaScript. This might be helpful for themes, light/dark mode toggles, or user preferences.
<p id="dynamicText">Click the button to change my color!</p>
<button onclick="changeColor()">Change Color</button>
<script>
function changeColor() {
document.getElementById("dynamicText").style.color = "crimson";
}
</script>
This approach gives you control over interactivity and user experience.
Using HTML font color properly gives your content clarity and personality. Whether you're learning how to change font color in HTML or looking to combine color with other styles, knowing your options helps you write more readable and attractive pages. Stick to modern methods like CSS, prioritize accessibility, and use font color HTML features to enhance—not overwhelm—your message.
Sign up or download Mimo from the App Store or Google Play to enhance your programming skills and prepare for a career in tech.