The components of a hexadecimal color are indicated by the hexadecimal numerals RR (red), GG (green), and BB (blue) in the formula #RRGGBB.


HEX Color Values

In HTML, a color can be specified using a hexadecimal value in the form:

#rrggbb

Where rr (red), gg (green) and bb (blue) are hexadecimal values between 00 and ff (same as decimal 0-255).

For example, #ff0000 is displayed as red, because red is set to its highest value (ff), and the other two (green and blue) are set to 00.

Another example, #00ff00 is displayed as green, because green is set to its highest value (ff), and the other two (red and blue) are set to 00.

To display black, set all color parameters to 00, like this: #000000.

To display white, set all color parameters to ff, like this: #ffffff.

Experiment by mixing the HEX values below:

#ff6347

RED

ff

GREEN

63

BLUE

47

Example

#ff0000
#0000ff
#3cb371
#ee82ee
#ffa500
#6a5acd

Shades of gray are often defined using equal values for all three parameters:

Example

#404040
#686868
#a0a0a0
#bebebe
#dcdcdc
#f8f8f8

3 Digit HEX Value

A three-digit hex code may occasionally be visible in the CSS source.

Some 6-digit hex codes can be shortened to a 3-digit code.

The format of the three-digit hex code is as follows:

#rgb

where the red, green, and blue components with values ranging from 0 to f are denoted by the letters r, g, and b.

Only in the event that each component’s RR, GG, and BB values are identical can the three-digit hex code be utilized. Hence, #f0c can be expressed as #ff00cc if it exists.

Here’s an illustration:

Example

				
					body {
  background-color: #fc9; /* same as #ffcc99 */
}

h1 {
  color: #f0f; /* same as #ff00ff */
}

p {
  color: #b58; /* same as #bb5588 */
}
				
			
Share this Doc

HEX

Or copy link

Explore Topic