×

HTML Font Color

The HTML <font> tag has an attribute called color, which defines the color of the text. We use the color attribute inside the <font> tag to specify the color of the text.

Syntax:

<font color="color_name | rgb_number | hex_number | hsl_number">

Following are the ways to define the font color:

Color name:

We use the color name to define the color of the text in an HTML document. The color name represents the specific name of the HTML color. There are 140 standard color names that HTML supports. You can use any color which you want to show in your HTML document. For example, if you want to change the text's color to purple, then you have to set the color of the text to purple.

Syntax:

<font color="Color_name ">  

RGB and RGBA number:

We use RGB and RGBA numbers to define the color of the text in an HTML document. The complete form of RGB is Red, Green, and Blue, and the full form of RGBA is Red, Green, and Blue with an Alpha, which defines opacity. We can create about 16 million different colors by combining red, green, and blue to form a color.

We can provide a color input value between 0 and 255, where 0 represents a color with minimum intensity and 255 represents a color with maximum intensity.

Syntax:

<font color="rgb(128,128,0)" 

Hex number:

We use hex numbers to define the color of the text in an HTML document. The Hex color code is the same as the RGB code. The hex code means hexadecimal consisting of sixteen values. It contains the digits from 0 to 9 and letters from A to F. For example, #RRGGBB is the hex code, where the first two values represent red, the two middle values represent green, and the last two values represent blue. We combine these three values to make different colors in HTML. #808080 is an example of a hex code representing the color Grey.

The RGB code (0, 0, 0) has the hexadecimal code, #000000 which represents black. The RGB code (0, 0, 0) means low intensity, while the RGB code (255, 255, 255) has the hexadecimal code, #FFFFFF which represents white color, means high intensity.

Syntax:

<font color="#808080"> 

HSL and HSLA Values

We use HSL and HSLA values to define the color of the text in an HTML document. HSL stands for hue, saturation, and lightness. HSLA stands for hue, saturation, and lightness with an Alpha.

Hue represents degrees from 0 to 360, which means red, 120 means green, and 240 means blue.

Saturation defines the saturation of the color. 0% illustrates black and white defines Grey, and 100% represents the full color.

Lightness also represents the percentage. 0% represents black, and 100% represents white.

For example, hsl(0, 100%, 50%) represents the red color.

We use HSLA values for defining the opacity. In HSLA, A stands for Alpha whose range is from 0 to 1, i.e., we can set the decimal value of Alpha to an integer between 0 and 1 only.

Syntax:

<font color=" hsl(60, 100%, 50%)." 

Examples of HTML Font Color

Example 1:

In this example, we are using the color name to set the color of the text.

<!DOCTYPE html>    
<html>     
<head>
    <title> Example 1 of HTML Font Color </title>    
</head>    
<body>   
<font color="purple">
<center>
    <h1> Color Name Type </h1>
    <p> This paragraph represents purple color using the color name type. </p>
</center>  
</font>     
</body>    
</html>

Output:

As you can see, the text color becomes purple.

HTML Font Color

Example 2:

This example demonstrates the use of RGB and RGBA values. We are using a <font> element in which we will use the color attribute to give the color to the element. We will also use CSS code to provide color to the text.

<!DOCTYPE html>    
<!DOCTYPE html>    
<html>     
<head>
    <title> Example 2 of HTML Font Color </title>  
    <style>
        .value1{
            width: 200px;
            height: 150px;
            border: 2px solid black;
            color: rgb(69, 82, 226);
            margin: auto;
        }
        .value2{
            width: 200px;
            height: 150px;
            border: 2px solid black;
            color: rgb(69, 82, 226, 0.6);
            margin: auto;
        }
    </style>  
</head>    
<body>   
<font color="rgb(0, 1, 0)">
<center>
    <h1> RGB and RGBA value </h1>
    <p> This paragraph represents a color using RGB value. </p>
</center>  
<div class="value1"> Using RGB value </div> <br> <br>
<div class="value2"> Using RGBA value </div>  
</body>    
</html>

Output:

The output shows colored text. The heading and paragraph get the color using the color attribute inside the <font> tag. We have also used CSS to create two <div> tags with colored text.

As you can see, <div> with class value1 shows the blue text, whereas <div> with class value2 shows the same blue text, but the text color is lighter due to the RGBA value.

HTML Font Color

Example 3:

This example illustrates the use of hex numbers in the HTML document. We will also use CSS to provide text color to the element.

<!DOCTYPE html>    
<html>     
<head>
    <title> Example 3 of HTML Font Color </title>  
    <style>
        .value{
            width: 500px;
            height: 50px;
            border: 2px solid black;
            color: #508080;
            margin: auto;
        }
    </style>   
</head>    
<body>   
<font color="#888000">
<center>
    <h1> Hex Number </h1>
    <p> This paragraph represents a color using Hex code. </p>
</center>  
</font> 
<div class="value"> Setting color using hexadecimal code. </div>    
</body>    
</html>

The output shows the heading and paragraph with the text color. Using CSS, we will also style <div> tag.

HTML Font Color

Example 4:

This example demonstrates the use of HSL and HSLA values.

<!DOCTYPE html>    
<html>     
<head>
    <title> Example 4 of HTML Font Color </title>    
</head>    
<body>   
<font color="hsla(9, 100%, 64%, 1)">
<center>
    <h1> HSL and HSLA value </h1>
    <p> This paragraph represents a color using HSL value. </p>
</center>  
</font>     
</body>    
</html>

Output:

The output shows a heading, paragraph, and two <div> elements. We will use the style as an attribute and define the property inside the element where we want to apply the color.

As you can see, the <p> tag has been given pink color using the style attribute. The <div> element shows the color applied using the HSL value. The other <div> element shows color applied using the HSLA value where A means Alpha which defines opacity. When we apply the HSLA value, the color of the text fades.

HTML Font Color

Example 5:

This example illustrates the different types of font color, which specifies the different colors of the text of the HTML document. We will use color names, hex numbers, RGB and RGBA numbers, and HSL and HSLA values.

<!DOCTYPE html>
<html>
  
<head>
    <title>
        Example 5 of HTML Font Color
    </title>
</head>
  
<body>
<div> 
    <font size="15"
          color="yellow">
          <p> This color is applied to the text using color name type. </p>
    </font>
</div>
<div> 
    <font size="15"
          color="#808000">
          <p> This color is applied to the text using hexadecimal code. </p>
    </font>
</div>
<div> 
    <font size="15"
          color="rgb(0,1,0)">
          <p> This color is applied to the text using RGB and RGBA number type. </p>
    </font>
</div>  
<div> 
    <font size="15"
          color="hsl(0, 100%, 0%)">
          <p> Font color HSL and HSLA value types are not supported by HTML5. </p>
    </font>
</div>
</body>
</html>

Output:

The output shows the different colors which are applied using different color types.

HTML Font Color

Browser Support:

It supports the following browsers:

  • Google Chrome
  • Opera
  • Mozilla Firefox
  • Safari
  • Internet Explorer

Related Topics

HTML Anchor

HTML Anchor The HTML anchor tags define a hyperlink that links to other pages on one page. It can create hyperlinks to any web page and files, locations or any other...

3 minutes read.

HTML <svg> tag

SVG is used to determine the vector-based graphics in XML format. What is SVG? We utilize SVG tag to specify visuals for the website. The attribute of SVG in a HTML document...

2 minutes read.

Html &lt;dd> Tag

In an HTML description list, an item's definition or description is indicated using the definition description ("dd" tag). A <dd> tag can contain paragraphs, line breaks, images, links, and lists. It...

4 minutes read.

HTML Ordered List

We use <ol> tag to make an ordered list in html. An ordered list is made to make a list of items in ordered form, ordered list can be either...

3 minutes read.

HTML5 Formatting

HTML Formatting HTML Formatting is a method of text formatting for a better appearance and look. HTML allows us to format text without using the CSS. HTML includes a lot of formatting tags....

6 minutes read.

Responsive HTML5 and CSS3 Tutorial

Introduction to HTML5 Tutorial HTML5 is the latest and upgraded version of HTML. HTML is a hypertext markup language. Technically, it is not a programming language. It is a markup language. HTML...

17 minutes read.

Caption Tag in HTML

Caption Tag in HTML: The < caption > tag in HTML describes the heading of a table in the HTML text. Browsers typically make the text found above the table...

4 minutes read.

HTML Id Attribute

The HTML id attribute represents the unique identifier for an element of the HTML document. Each element has its unique identifier. The id attribute is a global attribute that can be...

12 minutes read.

HTML Video

HTML VIDEO: HTML5 has introduced the <video> tag to embed video into the webpage directly without using the plug-ins.   Syntax: <video attributes >     <source src="address" type="video/mp4">     Your browser does not support the video tag.   </video> <video width="320" height="240" controls>     <source src="mountain.mp4" type="video/mp4">     Your browser does not support the video tag.   </video> Output: ← Prev ...

1 minute read.

HTML Event Attributes

HTML Event Attributes If a browser responds to the user behavior, an event is called. For example, if we click on the submit button, a box of details will appear on...

4 minutes read.

HTML5 Button Tag

HTML Button Tag The < button > tag is used on the webpage to construct a clickable button inside the HTML. Within the < button>....</button > tag, we can place content...

2 minutes read.

HTML Images

HTML has <img> tag to display image on the web pages or web application. This tag is an empty tag i.e. we don't have to close this tag while using. SYNTAX: <img src="source address" attributes="alt, height, width"> Example: <html>   <body>   <center>Image tag Example</center>   <img src="https://www.tutorialandexample.com/resources/images/favicon.png"    alt="tutorialandexample"/>   </body>   </html> Output: Image...

1 minute read.

HTML Data Tag

HTML Data Tag: The HTML < data > tag is used to transmit its content to a machine-readable version. The data are presented in a particular format. It is useful...

3 minutes read.

HTML Headings

The titles and subtitles of our webpages are known as HTML headings. Let’s not talk about webpages but giving heading to almost everything like normal paragraphs, articles or let it...

2 minutes read.

HTML Links

It consist of anchor element which is used to create a link between a source anchor and destination anchor. The anchor tag can be embedded between text, image, video or...

2 minutes read.

HTML5 Tags

HTML5 Tags A list of newly included tags is provided in HTML5. These HTML 5 tags (elements) provide a better structure for the document. This list shows description of all HTML...

3 minutes read.

HTML SVG

HTML SVG: SVG stands for Scalable Vector Graphics which defines the graphics for the web. It is a language for describing 2-D graphics in XML. Each drawn shape in SVG is...

1 minute read.

HTML Hide Element

The HTML hide element is used to hide the element. We place the hidden attribute inside those elements which we want to hide. The hidden attribute is a Boolean attribute. The...

3 minutes read.

HTML References

BASIC HTML TAGS TAGS DESCRIPTION <!DOCTYPE> Defines Document Type <html> Defines Html document <head> Defines Header of document <title> Defines Title of document <body> Describe all the content of document <h1> to <h6> Defines Html Heading <p> Write Paragraph in this tag <br> Line break <!--...--> Comment in Html FORMATTING TAGS TAGS DESCRIPTION <abbr> Defines...

3 minutes read.

How to insert spaces/tabs in text using HTML/CSS

What is HTML? HTML or HyperText Markup Language is used to design web pages. It was released in 1993. The file extension name for HTML file is “.html”. An HTML file...

4 minutes read.