Hex to RGB Converter

Hex to RGB converter: the first two digits of a hex color are red, the next two green, the last two blue, each from 00 to FF. #1E90FF is rgb(30, 144, 255). Enter a code with 3, 4, 6 or 8 digits, or a list, and read RGB, HSL and CMYK with the swatch.

Hex to RGB, HSL and CMYK
1 color
1 color converted
3, 4, 6 and 8 digits, with or without # · your input stays in this browser
#1E90FF
#1E90FF in every format
FormatValue
Hex#1E90FF
RGBrgb(30, 144, 255)
HSLhsl(210, 100%, 56%)
CMYK (approximate)cmyk(88%, 44%, 0%, 0%)
Contrast on white3.24 : 1
Contrast on black6.49 : 1

Hex to RGB: split the code into three bytes

A six-digit hex color code is three bytes written one after another: the first two digits are red, the next two green, the last two blue. Convert each pair from hexadecimal to a number from 0 to 255 and you have the RGB value. The code #1E90FF splits into 1E, 90 and FF, which are 30, 144 and 255, so it is rgb(30, 144, 255).

#1E90FF cut into red, green and blueThe hex code 1E90FF is three bytes. Red is 1E, which is 30 of 255; Green is 90, which is 144 of 255; Blue is FF, which is 255 of 255.Red1E30of 25512% of the channelGreen90144of 25556% of the channelBlueFF255of 255100% of the channel
#1E90FF is three bytes: 1E, 90, FF. As decimals they are 30, 144, 255, so the color is rgb(30, 144, 255). The bars show each value as a share of 255.

Nothing is lost or approximated in this step. Hex and RGB are two spellings of the same three numbers, the way 0x1E and 30 are two spellings of one number. The converter above does the splitting for you, and it also accepts several codes at once, one per line, which is useful when you are moving a whole palette out of a design file.

Converting by hand: sixteens and ones

Each pair has a left digit worth sixteen and a right digit worth one. Multiply the left digit by 16, add the right digit, and remember that A to F stand for 10 to 15. For 1E that is 1 × 16 + 14 = 30. For 90 it is 9 × 16 + 0 = 144, and for FF it is 15 × 16 + 15 = 255. The same arithmetic is explained digit by digit on the hex to decimal page, with longer values and signed readings.

Converting #1E90FF one channel at a time
ChannelPairLeft digit × 16Right digitValue
Red1E1 × 16 = 161430
Green909 × 16 = 1440144
BlueFF15 × 16 = 24015255

Two shortcuts help when you read codes at a glance. A pair starting with 0 is below 16, so it is a dark channel. A pair starting with F is 240 or more, so it is nearly full strength. FF is the maximum, 00 the minimum, and 80 sits close to the middle at 128.

Three-digit and four-digit shorthand codes

When both digits of every pair are the same, CSS lets you write each pair once. #F80 means #FF8800, and #0AF means #00AAFF. Expanding the code is a matter of doubling each digit; it is not the same as padding with zeros, which is the usual mistake. A four-digit code works the same way with a fourth digit for alpha, so #F80A is #FF8800AA. The W3C defines all four forms in CSS Color Module Level 4.

Short codes expanded and converted
Short codeExpandedRGB
#F80#FF8800rgb(255, 136, 0)
#0AF#00AAFFrgb(0, 170, 255)
#369#336699rgb(51, 102, 153)
#FFF#FFFFFFrgb(255, 255, 255)
#000#000000rgb(0, 0, 0)

A short code can describe only 4,096 colors, because each channel has 16 possible values (00, 11, 22 up to FF) instead of 256. A color such as #FF8801 has no short form. When you need the closest short code for a long one, round each channel to the nearest multiple of 17.

Eight-digit codes and the alpha channel

An eight-digit code ends with one more byte, the alpha channel, which sets opacity. 00 is fully transparent and FF fully opaque, and the scale is linear in between, so the byte divided by 255 is the opacity. #FF880080 is orange with alpha 80 = 128, which is 128 ÷ 255 = 0.502 or about 50%. In the rgb() form the same color is rgba(255, 136, 0, 0.502). Paste an eight-digit code into the converter and the swatch is drawn over a checkerboard so the transparency is visible.

Opacity percentages as alpha bytes
OpacityHex byteDecimalExample code
100%FF255#FF8800FF
90%E6230#FF8800E6
80%CC204#FF8800CC
70%B3179#FF8800B3
60%99153#FF880099
50%80128#FF880080
40%66102#FF880066
30%4D77#FF88004D
20%3351#FF880033
10%1A26#FF88001A
0%000#FF880000

The percentages in the first column are rounded: 90% is 229.5 and the table uses 230 (E6), and 50% is 127.5, which is why 80 is the usual choice for half-transparent. Browsers support four and eight digit hex colors, but email clients are less consistent, so mail templates are safer with a six-digit code or rgba().

Hex to HSL: hue, saturation and lightness

HSL describes the same color in terms people tend to reason about: the hue is a position on the color wheel in degrees, the saturation is how vivid the color is, and the lightness runs from black through the color to white. For #1E90FF the result is hsl(210, 100%, 56%). The steps start with the channels as fractions of 255: red 0.118, green 0.565, blue 1.000.

The largest fraction is 1.000 and the smallest 0.118, so the lightness is their average, 0.559, or 56%. The saturation is the spread divided by how far the lightness is from the middle: (1.000 − 0.118) ÷ (1 − |2 × 0.559 − 1|) = 1.00, which is 100%. Because blue is the largest channel, the hue is 240° adjusted by how much red and green differ: 60 × (4 + (0.118 − 0.565) ÷ 0.882) = 209.6, which rounds to 210°. Hues near 0° are red, 120° green and 240° blue, so 210° is a blue leaning toward cyan.

HSL is easier to adjust than hex. To make a button hover state darker you lower the lightness by a few points and keep the hue, whereas in hex every channel changes. The converter rounds hue to whole degrees and saturation and lightness to whole percent, which loses a little precision, so converting back may give a code one step off.

Hex to CMYK, and why the result is only an estimate

CMYK lists cyan, magenta, yellow and black ink as percentages. The simple conversion takes black as one minus the largest channel and derives the other three from what is left, which gives cmyk(88%, 44%, 0%, 0%) for #1E90FF. That formula assumes ideal inks, and it ignores the fact that an RGB screen and a printing press cover different ranges of color, called gamuts.

A print shop converts with an ICC profile for its paper and ink, and the numbers that come out of the profile are not the ones from the plain formula. Bright, saturated screen blues and greens are the usual casualty: the printed version is duller, whatever the percentages say. Treat the CMYK line as a starting point for a conversation with the printer.

Hex codes for common colors

People often search for the hex code for white, black or orange without caring about the arithmetic. The table lists the CSS color keywords that come up most, with the code behind each name. Two of them surprise newcomers: CSS green is the darker 008000, and the bright 00FF00 is called lime. White is FFFFFF because every channel is at its maximum, and black is 000000 because all three are off.

CSS color names with hex, RGB and HSL values
CSS nameHexRGBHSL
white#FFFFFFrgb(255, 255, 255)hsl(0, 0%, 100%)
black#000000rgb(0, 0, 0)hsl(0, 0%, 0%)
red#FF0000rgb(255, 0, 0)hsl(0, 100%, 50%)
lime#00FF00rgb(0, 255, 0)hsl(120, 100%, 50%)
green#008000rgb(0, 128, 0)hsl(120, 100%, 25%)
blue#0000FFrgb(0, 0, 255)hsl(240, 100%, 50%)
yellow#FFFF00rgb(255, 255, 0)hsl(60, 100%, 50%)
cyan (aqua)#00FFFFrgb(0, 255, 255)hsl(180, 100%, 50%)
magenta (fuchsia)#FF00FFrgb(255, 0, 255)hsl(300, 100%, 50%)
gray#808080rgb(128, 128, 128)hsl(0, 0%, 50%)
silver#C0C0C0rgb(192, 192, 192)hsl(0, 0%, 75%)
orange#FFA500rgb(255, 165, 0)hsl(39, 100%, 50%)
purple#800080rgb(128, 0, 128)hsl(300, 100%, 25%)
navy#000080rgb(0, 0, 128)hsl(240, 100%, 25%)
teal#008080rgb(0, 128, 128)hsl(180, 100%, 25%)
maroon#800000rgb(128, 0, 0)hsl(0, 100%, 25%)
olive#808000rgb(128, 128, 0)hsl(60, 100%, 25%)
rebeccapurple#663399rgb(102, 51, 153)hsl(270, 50%, 40%)

The keyword rebeccapurple, #663399, was added to CSS in 2014 in memory of Rebecca Meyer, the daughter of the CSS author Eric Meyer. The full list of named colors is in the CSS specification; the converter works with codes and does not look names up.

What a hex color code is

A hex color code is a number written in base 16 that packs the three channel values of an sRGB color into one short string. With 256 steps for each of red, green and blue there are 256 × 256 × 256 = 16,777,216 possible colors, and six hex digits are enough to name every one of them, since two digits cover exactly one byte. The code is commonly written with a leading # so a parser knows it is a color, but the # is not part of the number.

The reason this notation became standard on the web is its size and its fit to the hardware. Images and displays in ordinary 24-bit color store one byte per channel, so writing one byte per channel as two hex digits matches the stored data exactly. If you want the number system itself, the hexadecimal page covers the sixteen digits and place values, and the hex converter shows the same value in decimal and binary. Where the digits are bytes of text and not a color, use the hex code decoder.

Writing the same color in CSS

CSS accepts the hex, rgb(), hsl() forms and others for the same color, and they can be mixed freely in one stylesheet. The modern rgb() syntax uses spaces and a slash for alpha, while the older comma form is still valid everywhere. Both name the same pixels.

One color, four spellings (CSS Color Level 4)
color: #1e90ff;
color: rgb(30 144 255);
color: rgb(30 144 255 / 50%);
color: hsl(210 100% 56%);

Hex remains the form that design tools copy by default, and it is the shortest, which is why you will see it in most existing code. RGB and HSL are better when a value is computed or adjusted. See the color value reference on MDN for every notation.

Contrast: how readable the color is on white and black

The contrast ratio compares the relative luminance of two colors. It runs from 1:1 (identical) to 21:1 (black on white). The Web Content Accessibility Guidelines ask for at least 4.5:1 for normal text and 3:1 for large text and interface components, as set out in success criterion 1.4.3. The converter prints the ratio against white and against black for a single color; the table shows what typical colors score.

Contrast ratios against white and black (WCAG relative luminance)
ColorHexOn whiteOn black
dodger blue#1E90FF3.24 : 16.49 : 1
orange#FF88002.39 : 18.77 : 1
red#FF00004.00 : 15.25 : 1
gray#8080803.95 : 15.32 : 1
dark gray#7676764.54 : 14.62 : 1
rebeccapurple#6633998.41 : 12.50 : 1
yellow#FFFF001.07 : 119.56 : 1
blue#0000FF8.59 : 12.44 : 1

Two results are worth noticing. Plain #FF8800 orange on white is only 2.39:1, so orange text on a white page fails even the large-text threshold, and the same orange on black is comfortable. And #767676 is the lightest gray that still reaches 4.5:1 on white, which makes it a useful reference when picking secondary text.

Why 80 is not half as bright as FF

Hex 80 is 128, a little over half of 255, so it is natural to expect a gray of 80 to look half as bright as white. It does not. The sRGB encoding stores a curve, not a straight scale: values are spaced to match how the eye responds, and the light actually emitted grows faster than the code. The relative luminance of a gray 80 is about 0.216, a bit more than a fifth of white's 1.0.

Gray levels and their relative luminanceGray levels 00, 40, 80, C0, FF have relative luminance 0.000, 0.051, 0.216, 0.527, 1.000.00value 00.000luminance40value 640.051luminance80value 1280.216luminanceC0value 1920.527luminanceFFvalue 2551.000luminance
Equal steps in the hex value are not equal steps in light. The middle gray 80 reflects about a fifth of the light of white, which is why mixing colors by averaging hex values looks too dark.

This matters when you mix colors in code. The average of #000000 and #FFFFFF computed on the hex values is #808080, which looks darker than a physical half-and-half mix of light. Gradients, color blends and image resizing done directly on the encoded values come out too dark in the middle for the same reason, and careful software converts to linear light first. The standard behind the curve is IEC 61966-2-1; the W3C summarizes the formulas in the CSS Color specification.

RGB to hex: the same steps backwards

Going the other way, convert each channel to two hex digits and write them in the order red, green, blue. For rgb(255, 136, 0), 255 is FF, 136 is 88 (136 = 8 × 16 + 8) and 0 is 00, so the code is #FF8800. Always keep two digits: a channel value of 5 is 05, not 5, or the code shifts and a different color comes out. The decimal to hex page shows the repeated division behind each channel.

Type an rgb() value into the box above and the converter returns the hex code. It accepts the comma and space forms, with or without an alpha value, and it points out a channel above 255 instead of clamping it.

Converting hex colors in code

Every language has a base-16 parser, so the conversion is three calls. In JavaScript, slice the string into pairs and pass each to parseInt with radix 16. In a shell, printf reads a 0x prefix. In PowerShell, the Convert class does the same. All three give 30, 144 and 255 for 1E90FF.

JavaScript
const hex = "1E90FF";
const [r, g, b] = [0, 2, 4].map((i) => parseInt(hex.slice(i, i + 2), 16));
console.log(r, g, b); // 30 144 255
Bash
hex=1E90FF
printf '%d %d %d\n' 0x${hex:0:2} 0x${hex:2:2} 0x${hex:4:2}
PowerShell
$hex = '1E90FF'
0, 2, 4 | ForEach-Object { [Convert]::ToInt32($hex.Substring($_, 2), 16) }

The reverse in JavaScript is "#" + [255, 136, 0].map((v) => v.toString(16).padStart(2, "0")).join("").toUpperCase(), which returns #FF8800. The padStart call is what keeps small values to two digits.

Typical mistakes with hex colors

Most failed conversions come from the input and not the arithmetic. A code with five or seven digits is not a color: valid lengths are 3, 4, 6 and 8, and the converter reports the length it found. The letter O and the digit 0 look alike in many fonts, and a code with an O fails with the position of the offending character. A leading # is optional here, but copying one out of a URL can drag extra text along, so check what landed in the box.

One more trap sits in URLs. The # starts the fragment, so a color in a query string must be written as %23FF8800 or without the #, otherwise everything after it is cut off before it reaches the server. This page reads a starting value from the fragment, so a link ending in #FF8800 opens with that color, and the browser never sends a fragment to the server. Finally, do not expect a hex code and a printed color to match; the CMYK section above explains why.

Questions about converting hex to RGB

What is the RGB value of #FF0000?

255, 0, 0. FF is 255 for red, and both other pairs are 00, so the color is pure red at full strength: rgb(255, 0, 0).

How do I convert a 3-digit hex color to RGB?

Double each digit, then convert as usual. #F80 is #FF8800, which is rgb(255, 136, 0). The shortcut works only because each digit is repeated; a code like #FF8801 has no 3-digit form.

What does an 8-digit hex color mean?

The last two digits are the alpha channel, the opacity. #FF880080 is orange at about 50% opacity, because 80 is 128 out of 255. 00 is fully transparent and FF is fully opaque.

Does the # sign matter, and is the code case sensitive?

The # only marks the text as a hex color in CSS and HTML; the converter accepts a code with or without it. Upper and lower case mean the same thing, so #ff8800 and #FF8800 are one color.

How many colors can a hex code describe?

16,777,216. Each of the three channels has 256 values, and 256 × 256 × 256 is 16,777,216. Adding an alpha byte multiplies that by another 256 for transparency.

Is the CMYK result safe to send to a printer?

Use it as an estimate only. The conversion here is the plain formula without a color profile, and a printer works with an ICC profile for its ink and paper, so the real CMYK values usually differ.