RGB to Hex Converter

Hex colour code#3FA7D6
RGBrgb(63, 167, 214)
HSLhsl(199, 65%, 54%)
CMYKcmyk(71%, 22%, 0%, 16%)
How this was calculated
  1. Each channel in base 16: 63 = 3F, 167 = A7, 214 = D6 — joined: #3FA7D6.
  2. The same colour in HSL is hsl(199, 65%, 54%).
  3. For print, the CMYK equivalent is cmyk(71%, 22%, 0%, 16%).

This RGB to hex converter takes red, green, and blue channel values and translates them into the six-character hexadecimal colour codes used across web design and CSS. Hex colour codes write each RGB channel as two base-16 digits, formatted as hex = '#' + hex(R) + hex(G) + hex(B), with each channel padded to two digits. Enter any valid RGB triplet and the tool returns the matching hex string instantly. For verified reference, RGB (63, 167, 214) converts to #3FA7D6, RGB (255, 99, 71) converts to #FF6347 — the CSS colour named tomato — and RGB (34, 139, 34) converts to #228B22, known as forest green.

The base-16 method is the accepted standard because it maps each 0–255 channel directly onto a two-digit value that browsers and design software parse without ambiguity. This page goes beyond the result: it shows the formula, step-by-step workings, worked examples, and sources so you can verify every conversion yourself. The same page also documents related conversions, including HSL — where lightness is the midpoint of the max and min normalised channels, saturation is the range divided by a lightness-dependent denominator, and hue is the 0–360 degree angle set by the largest channel — and CMYK, where K = 1 − max channel and C, M, Y are each (1 − channel − K) / (1 − K), a naive device conversion printers use as a starting point.

Worked examples

A steel blue

Primary result: #3FA7D6 — in HSL that is hsl(199, 65%, 54%); for print, cmyk(71%, 22%, 0%, 16%). (63 · 167 · 214)

Hex colour code#3FA7D6
RGBrgb(63, 167, 214)
HSLhsl(199, 65%, 54%)
CMYKcmyk(71%, 22%, 0%, 16%)

Tomato

Primary result: #FF6347 — the CSS named colour tomato, hsl(9, 100%, 64%). (255 · 99 · 71)

Hex colour code#FF6347
RGBrgb(255, 99, 71)
HSLhsl(9, 100%, 64%)
CMYKcmyk(0%, 61%, 72%, 0%)

Forest green

Primary result: #228B22 — hsl(120, 61%, 34%), a pure-hue green darkened toward black. (34 · 139 · 34)

Hex colour code#228B22
RGBrgb(34, 139, 34)
HSLhsl(120, 61%, 34%)
CMYKcmyk(76%, 0%, 76%, 45%)

Reading a hex code

A hex colour code is a compact way to write RGB values using base-16 digits. The format is hex = '#' + hex(R) + hex(G) + hex(B), with each channel padded to two digits. That gives you three pairs of characters after the hash: the first pair for red, the second for green, and the third for blue. For example, RGB (63, 167, 214) is #3FA7D6. The '3F' sets the red channel, 'A7' sets the green, and 'D6' sets the blue.

Each RGB channel ranges from 0 to 255, which is 256 possible values. Base-16 digits run from 0 through 9 and then A through F, giving 16 values per digit. A single hex digit can only represent 16 values, but two hex digits can represent 16 times 16, or 256 values. That is exactly the range needed for one RGB channel. This is why every channel is written with two digits, and why a channel value below 16 gets padded with a leading zero. The red value 34 in RGB (34, 139, 34) becomes '22' in hex, not '2'. Without the padding, the code would be ambiguous: a parser would not know where one channel ends and the next begins.

Hex digits use the letters A through F to stand for the values 10 through 15. These letters are case-insensitive, so #3FA7D6 and #3fa7d6 are the same colour. Browsers, design tools, and any reliable rgb to hex converter treat uppercase and lowercase hex codes identically. You will often see uppercase in documentation and lowercase in CSS files, but the choice is a style preference, not a functional one. The CSS colour tomato, RGB (255, 99, 71), is #FF6347. Written as #ff6347, it produces the same result: hsl(9, 100%, 64%).

Once you know the pattern, reading a hex code is a matter of splitting it into pairs. Take #228B22, the code for forest green. The '22' is red at 34, '8B' is green at 139, and the final '22' is blue back at 34. The low red and blue values combined with the higher green value produce a dark, natural green: hsl(120, 61%, 34%). Whether you are working from RGB to hex or back the other way, the two-digit-per-channel structure stays the same. That consistency is what makes hex codes a reliable shorthand for colour across HTML, CSS, and design software.

Worked examples

Hex colour codes write each RGB channel as two base-16 digits, so the full format is hex = '#' + hex(R) + hex(G) + hex(B), with each channel padded to two digits. The table below shows three verified conversions side by side with their HSL and CMYK equivalents, so you can see how the same colour maps across systems. These are the exact values our rgb to hex converter produces for each input.

For HSL conversion, the channels are first normalised to 0-1. Lightness is the midpoint of the max and min channels. Saturation is the range divided by a lightness-dependent denominator. Hue is the angle around the colour wheel (0-360 degrees) set by which channel is largest. So a colour like RGB (63, 167, 214) lands at hsl(199, 65%, 54%) because blue is the largest channel, pulling the hue toward 199 degrees.

CMYK conversion follows the formula K = 1 − max channel, and C, M, Y are each (1 − channel − K) / (1 − K). The CMYK values shown here are the naive device conversion printers use as a starting point, not a colour-managed proof. That means they are useful for quick reference but will not match a calibrated press exactly. RGB (63, 167, 214) converts to cmyk(71%, 22%, 0%, 16%) under this method, with 0% yellow because the blue channel is the strongest and leaves no yellow component in the naive formula.

Two of the colours in the table also carry familiar CSS names. RGB (255, 99, 71) is #FF6347 — the CSS colour named tomato — with HSL values hsl(9, 100%, 64%). RGB (34, 139, 34) is #228B22 (forest green), hsl(120, 61%, 34%). The first sits at the warm end of the wheel with full saturation, while the second sits at 120 degrees, the green primary, with lower lightness and moderate saturation.

RGB inputHexHSLCMYK
(63, 167, 214)#3FA7D6hsl(199, 65%, 54%)cmyk(71%, 22%, 0%, 16%)
(255, 99, 71)#FF6347hsl(9, 100%, 64%)—
(34, 139, 34)#228B22hsl(120, 61%, 34%)—

RGB vs HSL vs CMYK

RGB, HSL, and CMYK each describe the same colour in different terms, and each model is useful in a different context. An rgb to hex converter works specifically with RGB, the model screens use to mix light. Red, green, and blue channels combine additively: the more light each channel contributes, the brighter the result. Hex colour codes simply write each RGB channel as two base-16 digits, so hex = '#' + hex(R) + hex(G) + hex(B), each channel padded to two digits. That makes hex a compact, human-readable label for the exact values a display renders.

HSL describes colour the way people tend to talk about it: by hue, saturation, and lightness. That makes HSL the useful representation when you want to reason about a colour's character rather than its raw light output. The conversion is straightforward once the RGB channels are normalised to 0-1. Lightness is the midpoint of the max and min channels. Saturation is the range divided by a lightness-dependent denominator. Hue is the angle around the colour wheel (0-360 degrees) set by which channel is largest. For example, RGB (63, 167, 214) converts to hsl(199, 65%, 54%), while RGB (255, 99, 71) — the CSS colour named tomato — converts to hsl(9, 100%, 64%). RGB (34, 139, 34), known as forest green, converts to hsl(120, 61%, 34%).

CMYK is the model print relies on. Instead of mixing emitted light, printing subtracts ink from white paper using cyan, magenta, yellow, and black. The conversion from RGB is mechanical: K = 1 − max channel, and C, M, Y are each (1 − channel − K) / (1 − K). The same RGB (63, 167, 214) that displays as #3FA7D6 converts to cmyk(71%, 22%, 0%, 16%). CMYK values here are the naive device conversion printers use as a starting point, not a colour-managed proof, because real presses depend on inks, paper, and profiles that shift the final result.

Knowing which model to reach for comes down to the task. RGB and its hex shorthand are the right choice for anything on a screen, from web styles to game development. HSL is the right choice when you need to build palettes, shift lightness for accessibility, or describe a colour by feel. CMYK is the right choice when preparing artwork for professional print, with the understanding that a naive conversion is only the first step toward what the press will actually produce.

Three-digit shorthand hex

Most hex colour codes use six digits, but an RGB to hex converter will also accept a three-digit shorthand. The shorthand works by doubling each digit, so #F63 expands to #FF6633. This means the first digit of each pair is the same as the second, and the full code is reconstructed from just three characters instead of six.

Because each digit is doubled, the shorthand can only represent colours where every channel has identical digit pairs. A channel value like FF (255 in decimal) qualifies because both digits are the same, but a value like A7 (167 in decimal) does not, because A and 7 differ. This limits the palette to 4,096 colours instead of the 16,777,216 available with six-digit codes.

For example, tomato (#FF6347) cannot be shortened, because its green channel 63 and blue channel 47 have unmatched digits. Likewise, #3FA7D6 and #228B22 cannot be shortened, since A7 and 8B each contain two different digits. A colour like #FF6633, however, can be written as #F63, since FF, 66, and 33 all consist of doubled digits.

When using an RGB to hex converter, entering a three-digit code should produce the same result as its six-digit expansion. The tool treats #F63 and #FF6633 as the same colour, with both mapping to RGB (255, 102, 51). This doubling rule is part of the CSS specification, so it applies consistently across web browsers and design software.

FAQs

How do I convert RGB to hex?

Write each channel in base 16, padded to two digits, and join them after '#'. For example, 63 = 3F, 167 = A7, 214 = D6, giving #3FA7D6. Each of the three RGB values becomes a two-character hex pair, and you simply place them in red, green, blue order after the hash symbol.

What is RGB (255, 99, 71) in hex?

RGB (255, 99, 71) converts to #FF6347 — the colour CSS calls tomato. The red channel 255 becomes FF, the green channel 99 becomes 63, and the blue channel 71 becomes 47, giving you the full hex code #FF6347.

Why do hex codes have letters?

Base 16 needs digits beyond 9, so A-F stand for 10-15; each channel pair runs from 00 (0) to FF (255). The letters simply represent values that cannot be written with a single decimal digit, letting every channel be expressed as exactly two characters.

What is the difference between hex and RGB?

None in content — a hex code is exactly the RGB values written in base 16 instead of decimal. #228B22 and rgb(34, 139, 34) are the same colour. The only difference is the notation: hex uses base 16 while RGB uses base 10, but both describe identical red, green, and blue values.

How do I get CMYK from RGB?

K = 1 − max(R,G,B) (normalised); then C = (1 − R − K)/(1 − K), and similarly for M and Y. For example, (63, 167, 214) gives cmyk(71%, 22%, 0%, 16%). First normalise your RGB values to a 0-1 range, then apply the formulas to get each CMYK percentage.

Can every RGB colour be printed in CMYK?

No — the CMYK gamut is smaller, so saturated screen colours (like bright greens and blues) shift when printed; the CMYK here is the standard naive conversion. Some vivid RGB colours simply cannot be reproduced with CMYK inks, meaning those colours will appear duller or different on paper than they do on screen.

Sources

Related calculators

Contrast Ratio Calculator (WCAG)
WCAG 2.1 contrast ratio between two RGB colours, with relative luminance for each and pass/fail against the AA and AAA thresholds for normal and large text.
Screen Size Calculator
Real width, height and area behind a screen's diagonal size and aspect ratio — so a 55-inch TV and a 55-inch ultrawide stop looking the same on paper.
PPI Calculator
Pixels per inch of any screen from its resolution and diagonal size — with total megapixels and dot pitch, so sharpness claims can be checked in seconds.