When it comes to customizing your site, font color often gets overlooked. In most cases, website owners leave the default font color like black or whatever their theme styles have defined for the body and heading text color.
However, it’s a good idea to change the HTML font color on your website for several reasons. Changing the HTML font color might seem daunting, but it’s pretty simple. There are several ways to change the font color on your website.
In this post, we’ll show you different ways to change the color of your website fonts, as well as discuss why you’d want to do it in the first place.
Why Change the HTML Font Color?
You would want to change the font color because doing so can help improve your website’s readability and accessibility. For example, if your site uses a darker color scheme, leaving the font color black would make it difficult to read the text on your website.
Another reason you would want to consider changing the font color is if you’re going to use a darker color from your brand color palette. This is yet another opportunity to reinforce your brand. It builds brand consistency and ensures that the text across all your marketing channels looks the same.
With that out of the way, let’s look at how you can define and change the HTML font color.
Ways To Define Color
There are several ways to define color in web design, including name, RGB values, hex codes, and HSL values. Let’s take a look at how they work.
Color Name
Color names are the easiest way to define a color in your CSS styles. The color name refers to the specific name for the HTML color. Currently, there are 140 color names supported, and you can use any of those colors in your styles. For example, you can use “blue” to set the color for an individual element to blue.
However, the downside of this approach is that not all color names are supported. In other words, if you use a color that’s not on the list of supported colors, you won’t be able to use it in your design by its color name.
RGB and RGBA Values
Next up, we have the RGB and RGBA values. The RGB stands for Red, Green, and Blue. It defines the color by mixing red, green, and blue values, similarly to how you’d mix a color on an actual palette.
The RGB value looks like this: RGB(153,0,255). The first number specifies the red color input, the second specifies the green color input, and the third specifies blue.
The value of each color input can range between 0 and 255, where 0 means the color is not present at all and 255 means that the particular color is at its maximum intensity.
The RGBA value adds one more value to the mix, and that’s the alpha value that represents the opacity. It ranges from 0 (not transparent) to 1 (fully transparent).
HEX Value
The hex color codes work similarly to RGB codes. They consist of numbers from 0 to 9 and letters from A to F. The hex code looks like this: #800080. The first two letters specify the intensity of the red color, the middle two numbers specify the intensity of the green color, and the last two set the intensity of the blue color.
HSL and HSLA Values
Another way to define colors in HTML is to use HSL values. HSL stands for hue, saturation, and lightness.
Hue uses degrees from 0 to 360. On a standard color wheel, red is around 0/360, green is at 120, and blue is at 240.
Saturation uses percentages to define how saturated the color is. 0 represents black and white, and 100 represents the full color.
Lastly, lightness uses percentages similarly to saturation. In this case, 0% represents black, and 100% represents white.
For example, the purple color we’ve been using throughout this article would look like this in HSL: hsl(276, 100%, 50%)
.
HSL, like RGB, supports opacity. In that case, you’d use the HSLA value where A stands for alpha and is defined in a number from 0 to 1. if we wanted to lower the opacity of the example purple, we’d use this code: hsl(276, 100%, 50%, .85)
.
Now that you know how to define color, let’s look at different ways to change the HTML font color.
The Old: <font>
Tags
Before HTML5 was introduced and set as the coding standard, you could change the font color using font tags. More specifically, you’d use the font tag with the color attribute to set the text color. The color
was specified either with its name or with its hex code.
Here’s an example of how this code looked with hex color code:
<font color="#800080">This text is purple.</font>
And this is how you could set the text color to purple using the color name.
<font color="purple">This text is purple.</font>
However, the <font>
tag is deprecated in HTML5 and is no longer used. Changing the font color is a design decision, and design is not the primary purpose of HTML. Therefore, it makes sense that the <font>
tags are no longer supported in HTML5.
So if the <font> tag is no longer supported, how do you change the HTML font color? The answer is with Cascading Style Sheets or CSS.
The New: CSS Styles
To change the HTML font color with CSS, you’ll use the CSS color property paired with the appropriate selector. CSS lets you use color names, RGB, hex, and HSL values to specify the color. There are three ways to use CSS to change the font color.
Inline CSS
Inline CSS is added directly to your HTML file. You’ll use the HTML tag such as <p> and then style it with the CSS color property like so:
<p style="color: purple">This is a purple paragraph.</p>
If you want to use a hex value, your code will look like this:
<p style="color:#800080">This is a purple paragraph.</p>
If you’re going to use the RGB value, you will write it like this:
<p style="color:RGB(153,0,255)">This is a purple paragraph.</p>
Lastly, using the HSL values, you’d use this code:
<p style="color:hsl(276, 100%, 50%)">This is a purple paragraph.</p>
The examples above show you how to change the color of a paragraph on your website. But you’re not limited to paragraphs alone. You can change the font color of your headings as well as links.
For example, replacing the <p>
tag above with <h2>
will change the color of that heading text, while replacing it with the <a>
tag will change the color of that link. You can also use the <span> element to color any amount of text.
If you want to change the background color of the entire paragraph or a heading, it’s very similar to how you’d change the font color. You have to use the background-color
attribute instead and use either the color name, hex, RGB, or HSL values to set the color. Here’s an example:
<p style="background-color: purple">
Embedded CSS
Embedded CSS is within the <style>
tags and placed in between the head tags of your HTML document.
The code will look like this if you want to use the color name:
<!DOCTYPE html>
<html>
<head>
<style>
<p> {
color: purple;
}
</style>
</head>
The code above will change the color of every paragraph on the page to purple. Similar to the inline CSS method, you can use different selectors to change the font color of your headings and links.
If you want to use the hex code, here’s how the code would look:
<!DOCTYPE html>
<html>
<head>
<style>
<p> {
color: #800080;
}
</style>
</head>
The example below uses the RBGA values so you can see an example of setting the opacity:
<!DOCTYPE html>
<html>
<head>
<style>
<p> {
color: RGB(153,0,255,0.75),
}
</style>
</head>
And the HSL code would look like this:
<!DOCTYPE html>
<html>
<head>
<style>
<p> {
color: hsl(276, 100%, 50%),
}
</style>
</head>
External CSS
Lastly, you can use external CSS to change the font color on your website. External CSS is CSS that’s placed in a separate stylesheet file, usually called style.css or stylesheet.css.
This stylesheet is responsible for all the styles on your site and specifies the font colors and font sizes, margins, paddings, font families, background colors, and more. In short, the stylesheet is responsible for how your site looks visually.
To change the font color with external CSS, you’d use selectors to style the parts of HTML you want. For example, this code will change all body text on your site:
body {color: purple;}
Remember, you can use RGB, hex, and HSL values and not just the color names to change the font color. If you want to edit the stylesheet, it’s recommended to do so in a code editor.
Inline, Embedded, or External?
So now you know how you can use CSS to change the font color. But which method should you use?
If you use the inline CSS code, you’ll add it directly into your HTML file. Generally speaking, this method is suitable for quick fixes. If you want to change the color of one specific paragraph or heading on a single page, this method is the fastest and the least complicated way to do it.
However, inline styles can make the size of your HTML file bigger. The bigger your HTML file is, the longer it will take for your webpage to load. In addition to that, inline CSS can make your HTML messy. As such, the inline method of using CSS to change the HTML font color is generally discouraged.
Embedded CSS is placed between the <head> tags and within the <style> tags. Like inline CSS, it’s good for quick fixes and overriding the styles specified in an external stylesheet.
One notable distinction between inline and embedded styles is that they will apply to any page that the head tags are loaded on, while inline styles apply only to the specific page they’re on, typically the element they’re targeting on that page.
The last method, external CSS, uses a dedicated stylesheet to define your visual styles. Generally speaking, it’s best to use an external stylesheet to keep all your styles in a single place, from where they are easy to edit. This also separates presentation and design, so the code is easy to manage and maintain.
Keep in mind that inline and embedded styles can override styles set in the external stylesheet.
Font Tags or CSS Styles: Pros and Cons
The two primary methods of changing the HTML font colors are to use the font tag or CSS styles. Both of these methods have their pros and cons.
HTML Font Tags Pros And Cons
The HTML font tag is easy to use, so that’s a pro in its favor. Typically speaking, CSS is more complicated and takes longer to learn than typing out <font color="purple">
. If you have an older website that isn’t using HTML5, then the font tag is a viable method of changing the font color.
Even though the font tag is easy to use, you shouldn’t use it if your website uses HTML. As mentioned earlier, the font tag was deprecated in HTML5. Using deprecated code should be avoided as browsers could stop supporting it at any time. This can lead to your website breaking and not functioning correctly, or worse, not displaying at all for your visitors.
CSS Pros and Cons
CSS, like the font tag, has its pros and cons. The most significant advantage of using CSS is that it’s the proper way to change font color and specify all the other styles for your website.
As mentioned earlier, it separates presentation from design which makes your code easier to manage and maintain.
On the downside, CSS and HTML5 can take time to learn and write properly compared to the old way of writing code.
Keep in mind that with CSS, you have different ways of changing the font color, and each of those methods has its own set of pros and cons, as discussed earlier.
Tips for Changing HTML Font Color
Now that you know how to change the HTML font color, here are a few tips that will help you out.
Use A Color Picker
Instead of picking colors randomly, use color pickers to select the right colors. The benefit of a color picker is that it will give you the color name and the correct hex, RGB, and HSL values that you need to use in your code.
Check the Contrast
Dark text with dark background as well as light text with light background doesn’t work well together. They will make the text on your site hard to read. However, you can use a contrast checker to ensure your site’s colors are accessible and the text is easy to read.
Find the Color Using the Inspect Method
If you see a color that you like on a website, you can inspect the code to get the color’s hex, RGB, or HSL value. In Chrome, all you have to do is point your cursor to the part of the web page you want to inspect, right-click and select Inspect. This will open up the code inspection panel, where you can see a website’s HTML code and the corresponding styles.
Summary
Changing the HTML font color can help improve your website’s readability and accessibility. It can also help you establish brand consistency in your website styles.
In this guide, you’ve learned about four different ways to change the HTML font color: with color names, hex codes, RGB, and HSL values.
We’ve also covered how you can change the font color with inline, embedded, and external CSS and use the font tag and the pros and cons of each method. By now, you should have a good understanding of which method you should use to change the HTML font color, so the only thing left to do now is to implement these tips on your site.
What are your thoughts on changing the font color with CSS and font tag? Let us know in the comments section!
Leave a Reply