Please enable JavaScript to use CodeHS

Color & Design

Hex Code Resource

Turn RGB sliders into a hex color code. See how red, green, and blue mix into the #RRGGBB codes used on every website.

Hex Colors ~8 min Middle / High school
The Big Idea

What are hex codes?

On the web, colors are often written as hex codes: a # followed by six characters. Those six characters are really three two-digit numbers written in base 16.

The first two digits describe red, the next two describe green, and the last two describe blue. Each pair can range from 00 (0 in decimal, fully off) to FF (255 in decimal, fully on).


Interactive

Try it: Hex Code Resource

Move the red, green, and blue sliders to mix a color, then copy the hex code to use in your own CSS. Click Random Color to explore new combinations.


How It Works

RGB to hex conversion

Each slider goes from 0 to 255. To turn a decimal number into two hex digits, the tool divides by 16. The quotient becomes the first digit and the remainder becomes the second digit.

For example, 255 in decimal is FF in hex, 127 is 7F, and 0 is 00. Putting the three pairs together gives a six-character color code like #7F7F7F.


Check Yourself

Quick quiz

1. In #RRGGBB, what does RR stand for?

2. What color is #000000?

3. What color is #FFFFFF?


Keep exploring

Explore more color and design tutorials.

Part of the Color & Design tutorial series.