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.
| Format | Value |
|---|---|
| Hex | #1E90FF |
| RGB | rgb(30, 144, 255) |
| HSL | hsl(210, 100%, 56%) |
| CMYK (approximate) | cmyk(88%, 44%, 0%, 0%) |
| Contrast on white | 3.24 : 1 |
| Contrast on black | 6.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).
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.
| Channel | Pair | Left digit × 16 | Right digit | Value |
|---|---|---|---|---|
| Red | 1E | 1 × 16 = 16 | 14 | 30 |
| Green | 90 | 9 × 16 = 144 | 0 | 144 |
| Blue | FF | 15 × 16 = 240 | 15 | 255 |
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 code | Expanded | RGB |
|---|---|---|
| #F80 | #FF8800 | rgb(255, 136, 0) |
| #0AF | #00AAFF | rgb(0, 170, 255) |
| #369 | #336699 | rgb(51, 102, 153) |
| #FFF | #FFFFFF | rgb(255, 255, 255) |
| #000 | #000000 | rgb(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 | Hex byte | Decimal | Example code |
|---|---|---|---|
| 100% | FF | 255 | #FF8800FF |
| 90% | E6 | 230 | #FF8800E6 |
| 80% | CC | 204 | #FF8800CC |
| 70% | B3 | 179 | #FF8800B3 |
| 60% | 99 | 153 | #FF880099 |
| 50% | 80 | 128 | #FF880080 |
| 40% | 66 | 102 | #FF880066 |
| 30% | 4D | 77 | #FF88004D |
| 20% | 33 | 51 | #FF880033 |
| 10% | 1A | 26 | #FF88001A |
| 0% | 00 | 0 | #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 name | Hex | RGB | HSL |
|---|---|---|---|
| white | #FFFFFF | rgb(255, 255, 255) | hsl(0, 0%, 100%) |
| black | #000000 | rgb(0, 0, 0) | hsl(0, 0%, 0%) |
| red | #FF0000 | rgb(255, 0, 0) | hsl(0, 100%, 50%) |
| lime | #00FF00 | rgb(0, 255, 0) | hsl(120, 100%, 50%) |
| green | #008000 | rgb(0, 128, 0) | hsl(120, 100%, 25%) |
| blue | #0000FF | rgb(0, 0, 255) | hsl(240, 100%, 50%) |
| yellow | #FFFF00 | rgb(255, 255, 0) | hsl(60, 100%, 50%) |
| cyan (aqua) | #00FFFF | rgb(0, 255, 255) | hsl(180, 100%, 50%) |
| magenta (fuchsia) | #FF00FF | rgb(255, 0, 255) | hsl(300, 100%, 50%) |
| gray | #808080 | rgb(128, 128, 128) | hsl(0, 0%, 50%) |
| silver | #C0C0C0 | rgb(192, 192, 192) | hsl(0, 0%, 75%) |
| orange | #FFA500 | rgb(255, 165, 0) | hsl(39, 100%, 50%) |
| purple | #800080 | rgb(128, 0, 128) | hsl(300, 100%, 25%) |
| navy | #000080 | rgb(0, 0, 128) | hsl(240, 100%, 25%) |
| teal | #008080 | rgb(0, 128, 128) | hsl(180, 100%, 25%) |
| maroon | #800000 | rgb(128, 0, 0) | hsl(0, 100%, 25%) |
| olive | #808000 | rgb(128, 128, 0) | hsl(60, 100%, 25%) |
| rebeccapurple | #663399 | rgb(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.
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.
| Color | Hex | On white | On black |
|---|---|---|---|
| dodger blue | #1E90FF | 3.24 : 1 | 6.49 : 1 |
| orange | #FF8800 | 2.39 : 1 | 8.77 : 1 |
| red | #FF0000 | 4.00 : 1 | 5.25 : 1 |
| gray | #808080 | 3.95 : 1 | 5.32 : 1 |
| dark gray | #767676 | 4.54 : 1 | 4.62 : 1 |
| rebeccapurple | #663399 | 8.41 : 1 | 2.50 : 1 |
| yellow | #FFFF00 | 1.07 : 1 | 19.56 : 1 |
| blue | #0000FF | 8.59 : 1 | 2.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.
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.
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 255hex=1E90FF
printf '%d %d %d\n' 0x${hex:0:2} 0x${hex:2:2} 0x${hex:4:2}$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.
