RGB to HEX Converter
Going the other way? Convert a hex colour code back to RGB →
How do you convert RGB to hex?
RGB channel values pack into a hex colour code: rgb(5, 90, 255) is #055AFF. Write each channel as two hexadecimal digits, pad a single digit with a leading zero, and join the three pairs behind a #. Red goes first, then green, then blue.
- Type the three channel values into the box. rgb(5, 90, 255), 5 90 255 and 5,90,255 all read.
- Turn each value into hexadecimal digits, red first, then green, then blue.
- Pad any single digit with a leading zero, so 5 becomes 05.
- Join the three pairs behind a #, with the digits in uppercase.
- Copy the code, or swap the direction to read a code back as channel values.
Channel Values and Hex Pairs
Every channel value has one two-digit form. The table runs the range at a readable step and shows where the leading zero appears, which is the step people leave out most often.
| Channel | Hex pair |
|---|---|
| 0 | 00 |
| 16 | 10 |
| 32 | 20 |
| 48 | 30 |
| 64 | 40 |
| 80 | 50 |
| 96 | 60 |
| 112 | 70 |
| 128 | 80 |
| 144 | 90 |
| 160 | A0 |
| 176 | B0 |
| 192 | C0 |
| 208 | D0 |
| 224 | E0 |
| 240 | F0 |
| 255 | FF |
Worked Example: rgb(5, 90, 255) to HEX
rgb(5, 90, 255) has one channel that needs padding and one that sits at the top of the range. The working below takes each channel on its own and paints the colour beside the result.
#055AFF
Result: rgb(5, 90, 255) = #055AFF
Joined behind a #, the three pairs give #055AFF. The seeds below are the values this family works from, so the page that goes the other way starts from the same colour.
- rgb(5, 90, 255) as a hex colour code: #055AFF
- #FF0000 as RGB channels: rgb(255, 0, 0)
Check it in reverse
To verify the result by hand, read the hex code back as channel values and compare it with what you started from.
Worked examples: RGB to HEX
Each example gives the value first, then the working. Select a value to load it in the converter.
What is rgb(5, 90, 255) in hex?
rgb(5, 90, 255) is written #055AFF.
Three channels: 5 05, 90 5A, 255 FF. The 5 is the one that needs a leading zero.
Every example above reverses exactly — split the same code back into red, green and blue.
What an RGB Value Holds
Below are the rules this page follows, in the wording the site uses everywhere. The reference rows are the values the converter enforces: a channel outside the range is refused rather than pulled back into it, because a quietly corrected value is a wrong answer that looks right.
An RGB colour is three channel values - red, green and blue - and each one is a whole number from 0 to 255, where 0 is none of that channel and 255 is the most of it.
Three channels of 256 levels each give 256 x 256 x 256 = 16,777,216 colours, which is where the phrase 16.7 million colours comes from.
Going the other way, write each channel as two hex digits and pad a single digit with a leading zero, so 5 is 05 and 255 is FF.
iToolHub writes the hex colour code with a leading # and uppercase digits, padding each channel to two digits.
A hex colour code writes those three channels as three pairs of hexadecimal digits, #RRGGBB: the first pair is red, the second green, the third blue, and each pair runs from 00 to FF, which is 0 to 255.
The three-digit form is shorthand: each digit is doubled to give the six-digit form, so #123 is the same colour as #112233.
Each channel converts on its own: two hex digits are one channel, so FF is 255, 80 is 128 and 00 is 0. The channels never mix.
| What | Value |
|---|---|
| The channels | red, green, blue |
| How many channels | 3 |
| Lowest channel value | 0 |
| Highest channel value | 255 |
| Levels per channel | 256 |
| Bits per channel | 8 |
| Colours in total | 16777216 |
| The percentage endpoints | 0% = 0, 100% = 255 |
What Changes the Hex Code?
The Leading Zero
Going the other way, write each channel as two hex digits and pad a single digit with a leading zero, so 5 is 05 and 255 is FF. Without it the pairs stop lining up and a six-digit code collapses into five, which no reader and no stylesheet can take apart again.
Upper Case, Every Time
Hexadecimal is not case-sensitive, so FF and ff name one value. This site writes the digits in uppercase, which means two codes for one colour compare as the same string rather than as two.
Three Channels, and the Fourth Elsewhere
A hex colour code may also carry four or eight digits, where the last digit or pair is the alpha channel: 00 is fully transparent and FF fully opaque. This page writes three channels, so a fourth number is refused and named rather than silently dropped from the answer.
Common Mistakes
- Leaving the zero off a single digit. A channel of 5 is 05, and without the padding the pairs stop lining up.
- Sending a value above the top of the range. It is refused rather than pulled back, because a corrected value would look like an answer.
- Writing percentages. Only the two endpoints of the percentage form are stated here, so the values between them are refused rather than rounded on a guess.
- Adding a fourth number for opacity. The rgb() form here takes three channels, and the alpha belongs to the four- and eight-digit hex forms.
Frequently Asked Questions
Can you enter RGB as percentages?
No. 0% is 0 and 100% is 255, and no rounding rule is stated here for the values in between, so a percentage is refused rather than guessed at.
How do you write RGB with an alpha value?
Not as a fourth number here. A hex colour code may also carry four or eight digits, where the last digit or pair is the alpha channel: 00 is fully transparent and FF fully opaque.
Do you pad a single hex digit with a zero?
Going the other way, write each channel as two hex digits and pad a single digit with a leading zero, so 5 is 05 and 255 is FF.
What is the highest RGB channel value?
An RGB colour is three channel values - red, green and blue - and each one is a whole number from 0 to 255, where 0 is none of that channel and 255 is the most of it.
Yes. The same value converts straight back in the HEX to RGB direction.
The rest of the family sits on back to the colour converter.