Skip to content

RGB to HEX Converter

Type three channel values from 0 to 255 and get the six-digit hex code, in lower or upper case, with the HSL equivalent and a text color that reads on top of it.

Runs in your browserFree, no sign-upLast reviewed

Settings

Results update automatically as you type.

Colour

#4f46e5

Values

HEX
#4f46e5
RGB
rgb(79, 70, 229)
HSL
hsl(243, 75%, 59%)
Readable text on it
#ffffff

CSS

.element {
  color: #4f46e5;
  background: rgb(79, 70, 229);
}

Quick answers

How do I convert RGB to hex?
Convert each of the three numbers to two-digit base 16 and join them after a hash. Divide the value by 16: the whole part is the first digit and the remainder is the second, with 10 to 15 written as a to f. rgb(255, 99, 71) gives ff, 63 and 47, so the code is #ff6347.
What is rgb(255, 255, 255) in hex?
rgb(255, 255, 255) is #ffffff, white. 255 is ff in hexadecimal, and the pair is written three times, once per channel. It can also be shortened to #fff.
What is rgb(0, 0, 0) in hex?
rgb(0, 0, 0) is #000000, black. Each channel is 0, which is written as the two-digit pair 00. The shorthand is #000.
Is RGB the same as hex?
They are the same color written in two number systems. RGB lists the red, green and blue channels in decimal, 0 to 255. Hex lists the same three channels in base 16, 00 to ff. No color is gained or lost by switching between them.
Why does my hex code have only 5 digits?
A channel below 16 converts to a single hex digit and needs a leading zero. 5 is 05, 10 is 0a and 15 is 0f. rgb(5, 10, 15) is #050a0f, not #5af. Without the padding the code is either an invalid length, which browsers ignore, or a different color altogether.
Does it matter if a hex code is upper or lower case?
No. #FF6347 and #ff6347 are the same color everywhere hex codes are accepted. Choose one style for a project so the same color is always written the same way; the Uppercase output box switches between them.

How RGB to HEX Converter works

Enter a red, a green and a blue value and this RGB to HEX converter writes each one as a two-digit hexadecimal number and joins them behind a hash. rgb(79, 70, 229) becomes #4f46e5, rgb(255, 255, 255) becomes #ffffff and rgb(0, 0, 0) becomes #000000. The result updates as you type. You also get the same color as hsl(), a suggested white or near-black text color to put on it, and a short CSS rule that uses the code. Tick Uppercase output if your project writes codes as #4F46E5. Values must be between 0 and 255; anything outside that range is flagged, not silently changed.

RGB to hex color chart

Common RGB values and the hex code this tool returns for each, with the text color it suggests on that background.

ColorRGBHex codeReadable text on it
Black0, 0, 0#000000#ffffff
White255, 255, 255#ffffff#101828
Red255, 0, 0#ff0000#ffffff
Lime0, 255, 0#00ff00#101828
Blue0, 0, 255#0000ff#ffffff
Yellow255, 255, 0#ffff00#101828
Cyan0, 255, 255#00ffff#101828
Magenta255, 0, 255#ff00ff#ffffff
Orange255, 165, 0#ffa500#101828
Gold255, 215, 0#ffd700#101828
Pink255, 192, 203#ffc0cb#101828
Purple128, 0, 128#800080#ffffff
Green0, 128, 0#008000#ffffff
Navy0, 0, 128#000080#ffffff
Teal0, 128, 128#008080#ffffff
Brown165, 42, 42#a52a2a#ffffff
Dodger blue30, 144, 255#1e90ff#ffffff
Light blue173, 216, 230#add8e6#101828
Dark gray51, 51, 51#333333#ffffff
Mid gray128, 128, 128#808080#ffffff
Light gray204, 204, 204#cccccc#101828
Off-white250, 250, 250#fafafa#101828

RGB to hexadecimal formula

For each channel value n from 0 to 255: first digit = whole part of n / 16, second digit = remainder of n / 16. Write 10 as a, 11 as b, 12 as c, 13 as d, 14 as e and 15 as f. Hex code = # + red pair + green pair + blue pair.

Take rgb(79, 70, 229). 79 / 16 = 4 remainder 15, so the red pair is 4f. 70 / 16 = 4 remainder 6, so green is 46. 229 / 16 = 14 remainder 5, so blue is e5. Joined together that is #4f46e5. A second one: rgb(255, 215, 0). 255 / 16 = 15 remainder 15, giving ff. 215 / 16 = 13 remainder 7, giving d7. 0 is 00. The code is #ffd700. Every pair must be two characters, so a value under 16 always starts with 0.

Decimal to hex pairs for common channel values

A lookup for single channels. Find each of your three numbers and write the pairs in red, green, blue order.

DecimalHex pairDecimalHex pair
00012880
50515096
100a15399
150f191bf
1610192c0
3220200c8
5133204cc
6440230e6
10064240f0
10266250fa
1277f255ff

Multiples of 17 (0, 17, 34, 51 and so on up to 255) give repeated digits such as 11, 22 and 33. A color whose three channels are all multiples of 17 can be written as three-digit shorthand: rgb(17, 34, 51) is #112233, or #123.

Worked RGB to hex examples

The default indigo

Red 79, Green 70, Blue 229

HEX #4f46e5. HSL hsl(243, 75%, 59%). Readable text on it: #ffffff.

Upper case for a brand sheet

Red 255, Green 99, Blue 71, Uppercase output ticked

HEX #FF6347. The CSS block reads .element { color: #FF6347; background: rgb(255, 99, 71); }

Small values that need zero padding

Red 5, Green 10, Blue 15

HEX #050a0f. HSL hsl(210, 50%, 4%).

Each pair keeps its leading zero, which is the step most often missed when converting by hand.

A value out of range

Red 256, Green 0, Blue 0

No code. The tool shows the message Red must be between 0 and 255.

Negative numbers get the same message. Nothing is clamped to 255 behind your back.

A decimal channel from a calculation

Red 79.6, Green 70.4, Blue 229

HEX #5046e5.

Each channel is rounded to the nearest whole number first, so 79.6 is treated as 80 and 70.4 as 70.

Converting rgba(), percentages and other RGB formats

The tool takes three whole-number channels. Other ways of writing an RGB color need one extra step before or after.

  • rgba() with transparency: convert the three color channels here, then work out the alpha pair by hand. Multiply the alpha by 255, round, and convert to hex. An alpha of 0.5 gives 128, which is 80, so rgba(79, 70, 229, 0.5) is #4f46e580.
  • Percentages such as rgb(100%, 50%, 0%): multiply each percentage by 2.55 and round. 100% is 255, 50% is 128 and 0% is 0, so enter 255, 128 and 0 to get #ff8000.
  • Values from 0 to 1, as used in some graphics and game code: multiply each by 255 and round. 0.2, 0.4, 0.8 becomes 51, 102, 204, which is #3366cc.
  • Eyedropper readings from an image editor: enter the R, G and B readings as they are. For 8-bit images they are already on the 0 to 255 scale.
  • Going the other way: use the HEX to RGB Converter on this site to turn a code back into channel numbers.

How the Readable text on it suggestion is chosen

The tool calculates the WCAG relative luminance of your color, a brightness score from 0 for black to 1 for white that weights green most heavily and blue least. If the score is above 0.45 it suggests the near-black #101828; otherwise it suggests white, #ffffff. That is why yellow (255, 255, 0) and lime (0, 255, 0) get dark text while pure red and pure blue get white.

Treat it as a first pick, not a pass mark. The rule is a single cutoff, it does not report a contrast ratio, and for mid-tone backgrounds it does not always choose the stronger of the two. On rgb(128, 128, 128) it suggests white, which gives 3.95 to 1, while #101828 gives 4.49 to 1. On orange rgb(255, 128, 0) it suggests white at 2.52 to 1, while #101828 gives 7.05 to 1. For body text, test the final pair in the Colour Contrast Checker and look for a ratio of at least 4.5 to 1.

How to get your result

  1. 1

    Enter the Red, Green and Blue values, each a number from 0 to 255.

  2. 2

    Tick Uppercase output if you want #FF6347 in place of #ff6347.

  3. 3

    Read the HEX line in the Values panel. RGB and HSL forms of the same color sit beside it.

  4. 4

    Check Readable text on it to see whether the tool suggests white (#ffffff) or near-black (#101828) text for that background.

  5. 5

    Copy the CSS block, or download it as colour.css, if you want the code already placed in a rule.

Common questions

What is the highest value a channel can have?
255. One channel is stored in 8 bits, which gives 256 levels numbered 0 to 255, or 00 to ff in hex. Three channels together make 256 x 256 x 256 = 16,777,216 possible colors.
What happens if I leave a field empty?
An empty channel falls back to that field's starting value: 79 for Red, 70 for Green and 229 for Blue. Type 0 if you mean zero, so the result reflects the color you intend.
How do I turn an RGB color into a three-digit hex code?
Convert to six digits first. If each pair is a doubled digit, drop one of each: #ffcc00 becomes #fc0 and #112233 becomes #123. If any pair has two different digits, such as #4f46e5, there is no three-digit form. The tool always outputs the full six digits.
Can I paste a whole value such as rgb(255, 99, 71)?
Not in one go. There are three separate number fields, so enter 255, 99 and 71 individually. Pressing Tab moves from one field to the next.
Does hex support transparency?
Yes, through an eight-digit code in which the last pair is the alpha: 00 is fully transparent and ff is fully opaque. This tool produces six-digit codes only, so add the alpha pair yourself. Common pairs are 80 for 50%, bf for 75% and 40 for 25%.
Why is the HSL value sometimes one step off when I convert it back?
The HSL line is rounded to a whole degree and whole percentages, and that coarser grid cannot name every one of the 16.7 million RGB colors. rgb(79, 70, 229) reads as hsl(243, 75%, 59%), which converts back to rgb(80, 72, 229). The hex code is exact; use it as the reference value.
Should I use hex or rgb() in CSS?
Both work in every browser and give identical colors. Hex is shorter and is what most design tools export. rgb() is easier when a channel or the opacity is set by a variable or a calculation, because the numbers are in plain decimal.

Further reading

Looking for something else? Browse all color tools or see every tool.