Javatpoint Logo
Javatpoint Logo

HTML Font Color

With the help of some tool of HTML, we can design and style our web content. Text formatting is one of the ways of web designing. With the help of HTML, we can provide a different look for the text of the web content. In that way, font color is one of the most important approaches to changing the look of the text. The basic syntax for using the font color is as follows.

Syntax:

In the above code:

  • The <element> tag represents all the HTML elements such as <h1>, <p>, or <span>.
  • style="color: color_value;" is the inline property of the CSS in which we can provide the font color to the text of the web content. We can use the color name in the form of color names, hexadecimal color codes, RGB values, or HSL values.

Let us discuss all the methods available for the font color property.

Using Color Names

In HTML, with the help of a color name, we can define the color property for the font color. This property is very easy to remember the name. Here are some examples.

Let us take a program and discuss elaborately the color property.

Example 1:

Output:

HTML font color

Explanation:

In the above code, we have created the seven div elements with different background colors using color names (red, orange, yellow, green, blue, indigo, and violet). We use the border-radius property to make the div elements circular and give them a rainbow-like appearance. The display inline-block style ensures that the rainbow colors are displayed next to each other horizontally.

Hexadecimal Color Codes

Providing the font color with the help of hexadecimal value is very popular among developers. Each hexa decimal color will be represented with the help of a # value along with a six-digit hexadecimal code. The hexadecimal code will provide a huge range of color collections. Below are some examples.

Example 2:

Let us take a program and discuss elaborately the color property.

Code:

Output:

HTML font color

Explanation:

In the above code, we have used the linear-gradient property for the background of the body element. The to-right direction specifies that the gradient should go from left to right, creating a horizontal rainbow effect. We specify seven hexadecimal color codes, one for each rainbow color (red, orange, yellow, green, blue, indigo, and violet).

RGB and RGBA Values

We can also use the color property with the help of RGB and RGBA values. We can use RGB (Red, Green, Blue) values or RGBA (Red, Green, Blue, Alpha) values for transparency. RGB consists of three integers, which represent the intensity of red, green, and blue, respectively, within the range of 0 to 255. Similarly, the RGBA value consists of a similar integer but includes an additional alpha value, which controls the opacity of the color (0 for fully transparent, 1 for fully opaque). Here are some examples.

Example 3:

It is an example of the implementation of RGB color.

Code:

Output:

HTML font color

Explanation:

In the above code, we have created an HTML <div> element with the class-colored box. Then, in the CSS, we define the .colored-box class and use the background-color property to set the background color to red using RGB values. The RGB value rgb(255, 0, 0) represents red, with maximum red intensity (255), no green (0), and no blue (0). In the output, we get the 200x200 pixel square with a red background color.

Example 4:

It is an example of the implementation of RGBA color.

Code:

Output:

HTML font color

Explanation:

In the above code, we have an HTML <div> element with the class semi-transparent box. After that, we define the .semi-transparent-box class and use the background-color property to set the background color to blue using rgba(0, 0, 255, 0.5). In that, RGBA values rgba(0, 0, 255, 0.5) represent blue with full intensity in the red and blue channels (0), no green (0), and a transparency level of 50% (0.5).

HSL and HSLA Values

It provides different methods to provide the font color on our web page. HSL represents the color itself, saturation controls the intensity, and lightness controls the brightness. HSLA values include an additional alpha value for transparency. Here are some examples.

Example 5:

It is an example of the implementation of HSL color.

Code:

Output:

HTML font color

Explanation:

In the above code, we have an HTML <div> element with the class hsl-box. After that, we have to define the .hsl-box class and use the background-color property to set the background color to green using hsl(120, 100%, 50%). In the HSL value, the first value (120 in this example) represents the hue, which determines the type of color (e.g., 0 for red, 120 for green, 240 for blue). The second value (100% in this example) represents the saturation, which controls the intensity or vividness of the color (100% for fully saturated, 0% for grayscale). The third value (50% in this example) represents the lightness, which controls how light or dark the color is (0% for black, 100% for white).

Example 6:

It is an example of the implementation of HSLA color.

Code:

Output:

HTML font color

Explanation:

In the above code, we have an HTML <div> element with the class hsla-box. After that, we have to define the. hsla-box class and use the background-color property to set the background color to a semi-transparent blue using hsla(210, 100%, 50%, 0.5). The hsla function takes four values. The first value (210 in this example) represents the hue, determining the type of color. The second value (100% in this example) represents the saturation, controlling the color's intensity. The third value (50% in this example) represents the lightness, controlling the color's brightness. The fourth value (0.5 in this example) represents the alpha channel, controlling the color's transparency. It ranges from 0 (fully transparent) to 1 (fully opaque).

Combining Font Color with Other Styles

For eye caching style, we have to combine all other style properties. For example, we can change the font size font family and add various CSS properties to create beautiful typography on your web pages.

Here are some examples,

Example 7:

It is an example of the implementation of Combining Font Color with Other Styles.

Code:

Output:

HTML font color

Explanation:

In the above code, We have an HTML <h1> element with the text "Welcome to javaTpoint." After that, we use the color property to set the font color to a reddish-orange color with the hexadecimal code #ff5733. We also set the font-size property to make the text larger (36px), font weight to make it bold and text-shadow to apply a subtle text shadow to improve readability.


Next TopicHTML Font Size





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA