⤺ color picker
3

# What is a hex color code? Complete guide to hex colors

18-01-2022, posted by ColorsData Team Hex color code (hexadecimal notation) is a very common format for representing colors in the RGB color palette. It is used in HTML, CSS and graphics programs, among others.

## Hex color code notation

The color hexadecimal notation consists of six hexadecimal digits - #123ABC. Each hexadecimal digit can take values from 0 to 15, where digits represent values from 0 to 9 and letters:
A – 10,
B – 11,
C – 12,
D – 13,
E – 14,
F – 15.

The six hexadecimal digits form three bytes that represent the colors red, green, and blue according to the RGB model. Each byte consists of two hexadecimal digits and can take a value from 00 (0) to FF (255).
We can shorten the notation only if each byte consists of two identical digits, for example:
The fuchsia color (#FF00FF) can be written as #F0F.

## Converting hex color code to RGB values

To get an RGB value in the range of 0 to 255, you must for each byte:
• Multiply the first hexadecimal digit by 16
• Read the value of the second digit
• Sum the two numbers For the example, we will use the beautiful green color #6DC415.
Initially, we need to split the hex code into three bytes representing each of the RGB colors: # 6D | C4 | 15.

First byte 6D (Red):
6 -> 6 × 16 = 96
D -> 13
Red color -> 96 + 13 = 109

Second byte C4 (Green):
C -> 12 × 16 = 192
4 -> 4
Green color -> 192 + 4 = 196

Third byte 15 (Blue):
1 -> 1 × 16
5 -> 5
Blue color -> 16 + 5 = 21

To sum up:
#6DC415 => red: 109, green: 196, blue: 21.

## How many colors can we represent in hex codes?

Since each byte can be represented by 256 values (from 0 to 255) in hexadecimal we can write down 256 × 256 × 256 colors, for a total of 16,777,216. Interestingly, hexadecimal notation that takes into account transparency in the format #AARRGGBB, where AA stands for 'Alpha', or transparency (FF = 100%, 00 = 0% transparency), is becoming popular. In this case, the number of colors is 256 × 256 × 256 × 256, for a total of 4,294,967,296.

### Example of hex codes in the HTML color palette:

Red = #FF0000 = RGB(255, 0, 0)
Green = #008000 = RGB(1, 128, 0)
Blue = #0000FF = RGB(0, 0, 255)
White = #FFFFFF = RGB(255,255,255)
Black = #000000 = RGB(0,0,0)

## Example of using hex code in HTML and CSS

On each example, you will get the same red background color:

• Hex: <div style=”background-color:#FF0000″></div>
• RGB: <div style=”background-color:rgb(255, 0, 0)”></div>
• Name: <div style=”background-color:red”></div>

Note that the name can only be used in more than 100 of the 16,777,216 colors.

18-01-2022, posted by ColorsData Team