As of now, we have studied that a color can be specified with its name and the RGB value. In this chapter, we will study how color can also be specified with a hexadecimal value.

Color in HTML with a hexadecimal number is represented with a format like #RRGGBB.

HEX Color

Here, RR represents intensity in hexadecimal numbers for the red color component.

GG represents the hex value for the green color and BB represents the hex value for the blue color.

Use below HEX color generator to set different intensity levels for red, green and blue colors to form a resultant color.







<!DOCTYPE html>
<title>HEX Color Example</title> </head>

<h1 style="color:#AB294E;">The heading color is set by HEX value #AB294E.</h1>
<p style="background-color:#AB294E;">This is a paragrah with background color #AB294E. The background-color property of the style attribute has value #AB294E.</p>


The hexadecimal value for each color can only be set between 00 and FF.

The decimal equivalent of HEX 00 is 0 and of HEX FF is 255.

If you notice, the hexadecimal color model is similar to the RGB color model we studied in the last chapter. The only difference is that the color combinations are represented with a hexadecimal number that starts with the symbol #.

<!DOCTYPE html>
<title>HEX & RGB Color Example</title> </head>

<h1 style="color:rgb(0,255,0);">This is a green color heading.</h1>
<p style="color:#00FF00;">This is a green-color paragraph. Notice that the color of the heading is set with an RGB value and color of the paragraph is set with a hexadecimal value.</p>


Black Color Hex Code

If we set the intensity of red, green and blue color to 00, the black color will be produced on the web page.

So the color code for black in hexadecimal representation will be #000000.

Black Color HEX

White Color Hex Code

If we set the intensity of all three colors to the maximum level which is FF then the white color is produced.

And hence the color code for white in hexadecimal representation is #FFFFFF.

White Color HEX

Red Color Hex Code

If we set the intensity for the red color to FF, the green color to 00 and the blue color to 00 then the red color is produced.

And hence the color code for red in hexadecimal representation is #FF0000.

Red Color HEX

Green Color Hex Code

Set red color = 00

green color = FF

blue color = 00

Hence, HEX code for the green color = #00FF00

Green Color HEX

Blue Color Hex Code

Set red color = 00

green color = 00

blue color = FF

Hence, HEX code for the blue color = #0000FF

Blue Color HEX
<!DOCTYPE html>
<title>HEX Color Example</title> </head>

<h1 style="background-color:#000000;color:#FFFFFF">Black Background Color #000000</h1>
<h1 style="background-color:#FF0000;">Red Background Color #FF0000</h1>
<h1 style="background-color:#00FF00;">Green Background Color #00FF00</h1>
<h1 style="background-color:#0000FF;">Blue Background Color #0000FF</h1>


Shades of Gray Color

If we set all three parameters to equal values, we produce different shades of gray color.


Below is a table of some favourite color names with their corresponding HEX and RGB code.

Color Name HEX Code RGB
Salmon #FA8072 rgb(250, 128, 114)
Crimson #DC143C rgb(220, 20, 60)
Pink #FFC0CB rgb(255, 192, 203)
Tomato #FF6347 rgb(255, 99, 71)
Orange #FFA500 rgb(255, 165, 0)
Khaki #F0E68C rgb(240, 230, 140)
Violet #EE82EE rgb(238, 130, 238)
Magenta #FF00FF rgb(255, 0, 255)
Purple #800080 rgb(128, 0, 128)
Teal #008080 rgb(0, 128, 128)
SkyBlue #87CEEB rgb(135, 206, 235)
LightGray #D3D3D3 rgb(211, 211, 211)

HEX color to RGB

To convert the hex color code to RGB value, we will first separate the intensities set in hex codes for corresponding red, green and blue color and write the decimal equivalent for the same.

For example, the hex color code for purple is #800080.

Now we know that the intensity for the red color is set to the hexadecimal number 80.

The decimal equivalent for 80 is 128. Hence the RGB color model will set the intensity for red to 128.

Similarly, the hex number for green is set to 00.

Hex 00 => 0 in decimal

Hence in the RGB color model, we will set the intensity for the green to 0.

Again the hex number for blue is set to 80 which is equivalent to the decimal number 128.

Hex 80 => 128 in decimal

Purple Color => #800080 => rgb(128,0,128)

<!DOCTYPE html>
<title>purple Color in HEX and RGB</title> </head>

<h1 style="background-color:purple">Purple Background Color by Name</h1>
<h1 style="background-color:#800080;">Purple Background Color by #800080</h1>
<h1 style="background-color:rgb(128,0,128);">Purple Background Color by rgb(128,0,128)</h1>


  • Disclaimer: is an independent private website and it is in no way affiliated to any Indian Government official website. The sole purpose of this website is to provide notifications regarding the latest results published. Though utmost care is being taken, we can not guarantee 100% correctness of information. Using this website confirms that you agree to all the terms and conditions.