🎨 Hex to RGB Converter

Convert HEX colors to RGB, HSL, HSV, CMYK — with shades, tints, contrast checker & CSS export.

Enter HEX Color Code
#
Valid 6-digit HEX color
#6F42C1
Adjust RGB Channels
R 111 44%
G 66 26%
B 193 76%
A 100 100%
Sample Colors:
Recent Colors
Shades (mixed with black)
Tints (mixed with white)
Click any swatch to load that color

Understanding Color Formats

HEX → RGB Conversion

A HEX color like #6F42C1 encodes three bytes in base-16. Split into pairs: 6F = 111 red, 42 = 66 green, C1 = 193 blue. Each pair converts: multiply the first digit by 16 and add the second (both in decimal). Short hex like #FC0 expands to #FFCC00 by doubling each digit.

RGB → HSL Conversion

HSL (Hue, Saturation, Lightness) maps RGB to a perceptual color wheel. Hue is the angle (0°–360°), Saturation is color intensity (0–100%), and Lightness is brightness (0% = black, 50% = pure color, 100% = white). HSL is more intuitive than RGB for designers adjusting color themes.

WCAG Contrast Ratios

WCAG 2.1 requires a minimum contrast ratio of 4.5:1 for normal text (AA) and 3:1 for large text (18pt+ or 14pt bold). AAA compliance needs 7:1 for normal and 4.5:1 for large text. Ratios are computed from relative luminance values derived from linearized RGB channels.

CMYK for Print

CMYK (Cyan, Magenta, Yellow, Key/Black) is a subtractive model used in print. Converting from RGB: normalize each channel to 0–1, find K = 1 − max(R,G,B), then C = (1−R−K)/(1−K) and so on. Note that screen-to-print CMYK conversion is an approximation — professional print work requires ICC color profiles.

The practical reasons you need to convert between HEX and RGB
HEX and RGB represent the same color. The format only matters because different tools, languages, and APIs expect different things.

CSS happily accepts both — #6F42C1 and rgb(111, 66, 193) are interchangeable in a stylesheet. But step outside CSS and the format starts mattering. Canvas API and WebGL work natively with 0–1 float values derived from RGB. Android XML resources use #AARRGGBB with the alpha byte first. PHP's imagecolorallocate() takes three separate integers. Most charting libraries (D3, Chart.js) expect hex strings without the hash or want rgb() notation. Knowing the conversion math means you're not blocked when a library expects a format you don't have.

ContextFormat expectedNote
CSS / HTML attributes#RRGGBB or rgb() or hsl()All three are valid. Named colors too. Use whichever is most readable for the context.
HTML Canvas 2D API#RRGGBB stringctx.fillStyle = '#6F42C1'. The canvas will also parse most CSS color strings.
WebGL / shadersFloat vec3 or vec4 (0.0–1.0)Divide each RGB channel by 255. R=111 becomes 0.435.
Android XML#AARRGGBBAlpha is the first byte, not the last. Easy to mix up when coming from CSS.
iOS / Swift UIColorFloat 0.0–1.0 per channelUIColor(red: 0.435, green: 0.259, blue: 0.757, alpha: 1.0)
Python (Pillow / matplotlib)RGB tuple (111, 66, 193) or float tuplePillow uses integers 0–255; matplotlib uses floats 0–1.
OpenCVBGR tuple, not RGBOpenCV reads color channels in Blue-Green-Red order. Swap R and B when converting.
Things that catch people out with hex colors
Small things, but they each cause enough "why is this broken" moments to be worth knowing.
8-digit hex alpha goes last in CSS, first in Android

CSS Color 4 added 8-digit hex support: #RRGGBBAA where the last two digits are the alpha channel. So #6F42C180 is 50% transparent purple. Android XML does the opposite — #AARRGGBB. If you're copying hex values between CSS and Android code, the alpha byte is in a different position and you will get the wrong color if you don't swap it.

3-digit hex doubles each digit — it doesn't halve the value

#F06 expands to #FF0066, not #F00066. Each single digit becomes a two-digit pair by repeating: F→FF, 0→00, 6→66. This means #F06 and #FF0066 are the same color, but #F16 has no 3-digit shorthand because you can't express F1 as a single repeated hex digit.

HEX is case-insensitive but your linter might not be

#6f42c1 and #6F42C1 are identical to every browser. But if your team uses a CSS linter like Stylelint with the color-hex-case rule, mixing cases will trigger warnings. Pick one convention for your project — most style guides prefer uppercase for HEX — and stick with it.

The hash symbol is CSS syntax, not part of the color value

When passing a hex color to a JavaScript function or API, whether to include the # depends on the API, not on the color itself. ctx.fillStyle = '#6F42C1' needs the hash; parseInt('6F42C1', 16) doesn't. D3's d3.color('#6F42C1') accepts either. Check the docs for whatever you're calling.

Other color tools
Questions
For the common ones, yes — memorise that FF=255, CC=204, 99=153, 66=102, 33=51, 00=0. These cover most of the greys and flat-UI colors. For arbitrary values: each hex digit is 0–15, so multiply the left digit by 16 and add the right. B4: B=11, so 11×16=176, plus 4 = 180. With a bit of practice you can estimate values in the 80–200 range reasonably quickly without a tool.
Neither is wrong — they're different coordinate systems for the same color space. HSL (Hue, Saturation, Lightness) is what CSS uses. HSV/HSB (Hue, Saturation, Value/Brightness) is what Photoshop, Figma, and most graphic software use. The two models place "full color" at different points: in HSL, maximum saturation at 50% lightness gives the pure hue; in HSV, maximum saturation at 100% value gives the pure hue. If you copy an HSV value from Figma and paste it as HSL in CSS, the color will be wrong.
Almost certainly not — the hex or rgb value is identical on both. What you're seeing is color profile differences. Most monitors are calibrated to sRGB; wide-gamut displays (especially Apple's P3 screens) render colors in a wider space. A saturated red that fills the sRGB gamut looks noticeably brighter and more saturated on a P3 display. Browsers on macOS attempt to manage this, but the rendering still varies. For pixel-perfect color consistency across devices, you'd need ICC profile-managed workflows — beyond CSS's scope.
Two things. First, oklch gives you access to colors outside the sRGB gamut — the vivid greens and cyan-blues that P3 and Rec.2020 displays can show but sRGB can't represent. Second, adjusting lightness in oklch is perceptually uniform: going from L=0.4 to L=0.5 looks like roughly the same brightness step regardless of hue. In HSL, the same L change looks much brighter for yellow than for blue. This makes oklch useful for programmatically generating accessible color scales. Browser support: Chrome 111+, Firefox 113+, Safari 15.4+. If you need IE11 or very old browsers, stick to hsl.