RGB to HEX Converter

red 5 0 x 16 + 5 05
green 90 5 x 16 + 10 5A
blue 255 15 x 16 + 15 FF

#055AFF

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.

  1. Type the three channel values into the box. rgb(5, 90, 255), 5 90 255 and 5,90,255 all read.
  2. Turn each value into hexadecimal digits, red first, then green, then blue.
  3. Pad any single digit with a leading zero, so 5 becomes 05.
  4. Join the three pairs behind a #, with the digits in uppercase.
  5. 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 Values and Hex Pairs
ChannelHex pair
000
1610
3220
4830
6440
8050
9660
11270
12880
14490
160A0
176B0
192C0
208D0
224E0
240F0
255FF

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.

red 5 0 x 16 + 5 05
green 90 5 x 16 + 10 5A
blue 255 15 x 16 + 15 FF

#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.

Load this value in the converter

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.

Reference values
WhatValue
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

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.