Color converter

Type a color in any format (HEX, RGB, HSL, HSV, OKLCH, CMYK or a CSS name like teal), or use the picker. You get every other format, plus a contrast check against a background.

Contrast

How to use the color converter

  1. Type a value into Color in any supported format, such as #4f46e5, rgb(79, 70, 229), hsl(243, 75%, 59%), oklch(51.1% 0.23 277) or teal, or click the swatch beside it to use your system color picker.
  2. Read the HEX, RGB, HSL, HSV / HSB, OKLCH and CMYK versions in the table, and use each row's Copy button.
  3. Set Background (for contrast) to the color the text will sit on, by typing it or using its picker.
  4. Check the Contrast section: a live text sample, the contrast ratio, and pass or fail for WCAG AA and AAA at normal and large text sizes.

Color formats

FormatExampleUsed for
HEX#4F46E5CSS and design tools. 8-digit HEX adds transparency.
RGBrgb(79, 70, 229)Screens: red, green and blue light from 0 to 255.
HSLhsl(243, 75%, 59%)Adjusting colors by hand: hue, saturation, lightness.
HSV / HSBhsv(243, 69%, 90%)Color pickers in Photoshop and Figma.
OKLCHoklch(51.06% 0.2301 276.97)Modern CSS and Tailwind CSS v4: lightness, chroma and hue in a perceptually even space.
CMYKcmyk(66%, 69%, 0%, 10%)Print. This is a simple conversion; printers use color profiles for exact results.

The input box also accepts 3- and 4-digit shorthand HEX (#abc means #aabbcc), rgba() and hsla(), RGB channels as percentages, hue in deg, turn, rad or grad, the CSS space-separated syntax such as hsl(240 100% 50%), oklch() and oklab(), and all 148 CSS color names, such as rebeccapurple.

How the conversions work

Every format is converted to 8-bit RGB first, and the others are calculated from that.

Worked example

Take #4F46E5. The pairs 4F, 46 and E5 are 79, 70 and 229, so it is rgb(79, 70, 229). Scaled to 0–1 that is 0.310, 0.275 and 0.898. Blue is largest and green smallest, a difference of 0.624.

The tool shows hsl(243, 75%, 59%), hsv(243, 69%, 90%) and cmyk(66%, 69%, 0%, 10%). Against a white background its contrast ratio is 6.29:1: a pass for AA at both sizes and for AAA large text, but a fail for AAA normal text, which needs 7:1.

Quick contrast check

The contrast section compares your color with the background using the WCAG 2 ratio: AA needs 4.5:1 for normal text and 3:1 for large text, and AAA needs 7:1 and 4.5:1. For example, #767676 on white is 4.54:1, the lightest gray that passes AA. For the formula, user-interface components, transparent colors and suggested fixes, use the color contrast checker.

Common mistakes

Transparency

Alpha is stored in 8 bits in HEX, so rgba(0, 0, 0, 0.5) becomes #00000080, and converting back gives an alpha of 0.502. HSV and CMYK have no alpha, so they describe the solid color only.

Key terms

Hex color
A color written as a # followed by hexadecimal digits for red, green and blue, such as #4F46E5. Each pair runs from 00 to FF (0 to 255). An optional fourth pair sets opacity, and 3- or 4-digit shorthand doubles each digit.
RGB
A color model that mixes red, green and blue light, each channel usually from 0 to 255 on screens. rgb(0, 0, 0) is black and rgb(255, 255, 255) is white. HEX colors are the same values written in hexadecimal.
HSL
A color model of hue (an angle from 0 to 360 degrees on the color wheel), saturation and lightness, both as percentages. Lightness 0% is black, 100% is white and 50% is the most vivid color, which makes HSL handy for creating tints and shades in CSS.
HSV
Hue, saturation and value, also called HSB (brightness). Value is the strength of the largest RGB channel, so 100% value with full saturation is the purest form of a hue. It is the model behind the square-and-slider color picker used by many graphics apps.
CMYK
Cyan, magenta, yellow and key (black): the subtractive model used for printing with inks. Converting from RGB with a simple formula gives an approximation; accurate print colors need an ICC color profile for the specific press and paper.
Contrast ratio
A WCAG measure of how different two colors' brightness is, from 1:1 (identical) to 21:1 (black on white). It is calculated from the relative luminance of each color and used to judge whether text is readable against its background.
Relative luminance
The relative brightness of a color as WCAG defines it, from 0 for black to 1 for white. It linearizes the sRGB channels and weights them roughly 21% red, 72% green and 7% blue, and is the basis of the WCAG contrast ratio.
WCAG
The Web Content Accessibility Guidelines published by the W3C. Version 2 sets testable success criteria at levels A, AA and AAA, including minimum text contrast of 4.5:1 at AA. Many accessibility laws and policies point to WCAG 2.0, 2.1 or 2.2 level AA.
OKLCH
A CSS color format of lightness, chroma and hue, built on the OKLab color space published by Björn Ottosson in 2020. Equal steps in its lightness look roughly equal to the eye, which plain HSL does not manage. Tailwind CSS v4 defines its default palette in OKLCH.
Alpha channel
A fourth value alongside the color channels that sets opacity, from 0 (fully transparent) to 1 (fully opaque). In CSS it appears in rgba(), hsla() and 8-digit HEX, where 80 is about 50%.

Frequently asked questions

How do I convert HEX to RGBA?
Add a fourth pair of hex digits for opacity and type it above: #4F46E580 gives rgba(79, 70, 229, 0.502), because 80 in hex is 128 and 128 ÷ 255 is about 0.502. Six-digit HEX has no alpha, so it converts to plain rgb().
How do I convert RGB to CMYK?
Scale each channel to 0–1, set K = 1 − the largest channel, then C, M and Y are (1 − channel − K) ÷ (1 − K). rgb(79, 70, 229) becomes cmyk(66%, 69%, 0%, 10%). This simple formula is a starting point; print work should use your printer's color profile.
How do I convert HEX to RGB?
Split the six digits into three pairs and convert each from hexadecimal: #4F46E5 is 4F = 79, 46 = 70, E5 = 229, so rgb(79, 70, 229). Or type it in the box above.
Why does HSL to HEX not round-trip exactly?
HSL values are rounded to whole numbers, so converting back can be off by one or two in a channel. If you entered HEX or whole-number RGB, the HEX and RGB values shown are exact; values converted from HSL, HSV or CMYK are rounded to the nearest whole channel.
How do I convert HEX to OKLCH?
Type the HEX value above and read the OKLCH row. The channels are linearized, converted to the OKLab space and then expressed as lightness, chroma and hue, so #4F46E5 becomes oklch(51.06% 0.2301 276.97).
Does it support transparency?
Yes: 8-digit HEX (#RRGGBBAA), rgba() and hsla(). Contrast is only shown for solid colors, because the real contrast of a see-through color depends on what is behind it.
What is the difference between HSL and HSV?
Both describe a color by hue and saturation, but the third value differs. In HSL, lightness 100% is always white and 50% gives the most vivid color. In HSV, value 100% with full saturation is the pure, vivid color. CSS uses HSL; many design-tool pickers use HSV, sometimes called HSB.
How do I convert RGB to HEX?
Convert each channel from 0–255 to a two-digit hexadecimal number and join them after a #. For rgb(79, 70, 229), 79 is 4F, 70 is 46 and 229 is E5, giving #4F46E5. Pad single digits with a zero, so 10 becomes 0A. Type rgb(…) above to get it instantly.
How do I convert HEX to HSL?
Type it above and read the HSL row. By hand, scale each channel to 0–1: lightness is the average of the largest and smallest channel, saturation is their difference divided by 1 − |2L − 1|, and hue depends on which channel is largest. #4F46E5 is hsl(243, 75%, 59%).
Is the CMYK value accurate for printing?
Only roughly. It uses the simple textbook formula, which ignores the printer, inks, paper and color profile. Professional printing converts through an ICC profile such as FOGRA or GRACoL, which can give noticeably different percentages. Ask your printer for their profile and convert in your layout software.