Which CSS property changes the font color of an element to blue?

Many years ago, if we want to change an element font color, we used <font> tag with its attribute i.e. color. But in HTML5, the <font> element has been deprecated. So instead of doing this, we can use the CSS color attribute.

The HTML container tag can contain text, we can easily change its foreground color or font color by using the CSS color property.

Syntax of color attribute:

color: color|initial|inherit;

We can use this color attribute to any element i.e. div, span, a, p etc. In order to change the color property to any color, we can change it by three ways like give a specific color name by using hex value or we can use RGB value.

Below are the example of changing an element font color to blue with the above methods:

By using color name:

    color: blue;

By using hex value:

    color: #0000ff;

Here we can see the above example will change the div color to blue. So how to use this hex color? Well, the above hex color is based on RGB value i.e RR GG BB. If we set the red value(RR) to 00 and the last two characters(BB) to 0 and the GG value is ff (which is hex value), we can get the green color. So the value of the green color in hex is #00ff00. So if we need yellow color, how to get that?

Also Read: How to make certain text unselectable with CSS?

The answer is we have to mix the color to get the appropriate color. So mix RR & GG and BB set to 0 will get yellow color like #ffff00. We can also change the alpha property of this color by adding a to #RR GG BB value like that #RRGGBBaa. You can easily get the hex color value by using google search like below-

hex color picker Google Search

By using initial and inherit:

Here inherit value is used when no value is specified for that element, use root element value, and initial when not inherit, it uses initial value generally black.

Also Read: Difference between CSS initial and inherit


So the conclusion is, you can use color attributes in order to change the font color of an element to not only blue but also any color with alpha value.

About Ashis Biswas

A web developer who has a love for creativity and enjoys experimenting with the various techniques in both web designing and web development. If you would like to be kept up to date with his post, you can follow him.

Leave a Comment