Color Converter

Convert between HEX, RGB, and HSL color formats

What Is a Color Converter?

A color converter translates one color notation into another. A designer hands you #FF6B35. Your charting library wants rgb(255, 107, 53). You’d like to build hover states by nudging lightness in hsl(). All three describe the same color, and doing the conversion by hand gets tedious after the first one.

This converter accepts every notation CSS understands for sRGB colors. That’s 3-, 4-, 6- and 8-digit HEX, rgb() and rgba(), hsl() and hsla(), the modern space-separated CSS Color 4 syntax, and all 148 named colors. One input gives you every other format, a preview swatch, a contrast check and ready-made CSS custom properties.

HEX, RGB and HSL Explained

HEX

A HEX color is RGB written in base 16: #RRGGBB, where each pair runs from 00 (0) to FF (255). Three short forms and extensions exist:

  • 3 digits #RGB: each digit is doubled, so #F63 means #FF6633. This only works when both digits of every pair are the same.
  • 8 digits #RRGGBBAA: a fourth pair sets alpha. #FF6B3580 is the same orange at about 50% opacity.
  • 4 digits #RGBA: the short form of the above, so #F638 means #FF663388.

HEX is case-insensitive, and it’s the most compact form, which is why design tools and style guides default to it.

RGB

rgb(255, 107, 53) gives the red, green and blue channels directly as numbers from 0 to 255. Percentages also work, so rgb(100% 42% 21%) scales each channel to 0-255. RGB maps straight onto how screens mix light, but it’s hard to tweak by hand. Making that orange “a bit darker” means changing all three numbers by different amounts.

HSL

hsl(16, 100%, 60.4%) describes the same orange as a hue angle on the color wheel (0° red, 120° green, 240° blue), a saturation (0% gray to 100% vivid) and a lightness (0% black, 50% pure color, 100% white). It’s the friendliest format for building palettes. Keep hue and saturation fixed and step lightness to get a tint and shade scale for buttons, borders and backgrounds.

How to Use This Color Converter

  1. Type or paste a color into the input. You can paste a whole CSS declaration such as background-color: #ff6b35;. The property name, !important and the trailing semicolon are stripped.
  2. Press Convert or Ctrl+Enter. You can also click the color swatch next to Convert to open your system color picker. It converts as you drag.
  3. Read off HEX, RGB, HSL, the CSS Color 4 forms, the matching or nearest named color, contrast against white and black, and three CSS variables. Copy everything with the Copy button or Ctrl+Shift+C. Ctrl+L clears the input.

If a channel is out of range, for example rgb(300, 0, 0), the tool clamps it the same way browsers do (red becomes 255) and adds a note saying so. That way the HEX and RGB lines always describe the same color.

Converting HEX to RGB (and Back) by Hand

Each HEX pair is one byte. For #FF6B35:

PairHexCalculationDecimal
RedFF15 × 16 + 15255
Green6B6 × 16 + 11107
Blue353 × 16 + 553

Going the other way, divide each channel by 16. The quotient is the first digit and the remainder is the second: 107 ÷ 16 = 6 remainder 11, which is 6B. The Number Base Converter does the same base-16 arithmetic for any number.

HSL takes more math: you normalize the channels to 0-1, find the largest and smallest, and derive hue from which channel dominates. That’s the conversion people usually reach for a tool to do.

Why HSL Round Trips Drift

Convert #FF6B35 to HSL, round to whole numbers, and you get hsl(16, 100%, 60%). Convert that back and you get #FF6933, not #FF6B35. Nothing is broken. The rounding is too coarse. One percent of lightness is about 2.5 steps on the 0-255 scale, so dropping the 0.4% moves the green and blue channels.

We tested this on 300,000 random colors. Whole-number HSL failed to reproduce the original HEX code about 9 times in 10. With one decimal place, which is what this converter prints (hsl(16, 100%, 60.4%)), every one of those colors came back exactly. If you store design tokens in HSL, keep the decimal.

Modern CSS Color Syntax (CSS Color 4)

CSS Color Module Level 4 simplified the functional notations, and every current browser supports them:

  • Spaces instead of commas: rgb(255 107 53), hsl(16 100% 60.4%).
  • Alpha after a slash: rgb(255 107 53 / 50%) or / 0.5.
  • rgba() and hsla() are now aliases of rgb() and hsl(). Both forms accept alpha.
  • Hue units: deg (the default), turn, rad and grad, so hsl(0.5turn 50% 50%) is the muted cyan #40BFBF.

The converter reads both the legacy comma syntax and the modern syntax and outputs both. Use the legacy form if your code passes through an older CSS minifier or preprocessor that doesn’t understand the slash.

The newer color spaces in CSS Color 4 and 5, such as oklch(), lab(), color(display-p3 ...) and color-mix(), can describe colors outside sRGB. This tool covers the sRGB formats (HEX, RGB, HSL) that the vast majority of stylesheets, design tokens and APIs still exchange.

Named Colors

CSS has 148 named colors, from aliceblue to yellowgreen. If your input matches one exactly, the converter shows its name. Otherwise it shows the nearest named color as a rough description. A few quirks are worth knowing:

  • gray and grey are both valid, and so is every *gray/*grey pair.
  • darkgray (#A9A9A9) is lighter than gray (#808080). That’s a leftover from the X11 color list the names came from.
  • rebeccapurple (#663399) was added in CSS Color 4 in memory of Rebecca Meyer.
  • transparent is rgba(0, 0, 0, 0): black at zero opacity, which matters when you animate or blend from it.

Contrast and Readable Text

For every color, the tool computes the WCAG 2 contrast ratio against white and against black and tells you which text color reads better on it. WCAG AA requires 4.5:1 for normal text and 3:1 for large text (24px, or about 18.7px bold). AAA requires 7:1. Bright brand oranges are a classic trap: #FF6B35 gives white text only 2.84:1, while black text reaches 7.41:1. Contrast is computed on the opaque color. With transparency, the real result depends on whatever is behind the element.

Using the CSS Variable Output

The output includes three custom properties:

--color: #ff6b35;
--color-rgb: 255, 107, 53;
--color-hsl: 16 100% 60.4%;

--color-rgb holds the bare channels so you can add opacity later: rgba(var(--color-rgb), 0.15) for a translucent background or a box shadow. --color-hsl uses the space syntax so hsl(var(--color-hsl) / 50%) works too. Both are handy for gradients and hover states without defining a second variable.

Common Color Conversion Errors

  • Alpha in the wrong place. CSS puts alpha last (#RRGGBBAA). Android color resources and Flutter’s Color(0xAARRGGBB) put it first. Pasting an Android #80FF6B35 into CSS gives you a completely different color.
  • 0-1 versus 0-255 alpha. rgba(255, 107, 53, 128) isn’t half-transparent. Alpha above 1 is clamped to fully opaque. Use 0.5 or 50%.
  • Missing percent signs in hsl(). The comma syntax requires % on saturation and lightness, so browsers may ignore hsl(16, 100, 60) and leave the property unset. This converter accepts both, but write the % in your CSS.
  • 5- or 7-digit HEX. Usually a copy-paste that lost a character. Only 3, 4, 6 and 8 digits are valid.
  • Values over 255. Browsers clamp rgb(300, 0, 0) to rgb(255, 0, 0) silently. The converter does the same but tells you.

Frequently Asked Questions

How do I convert HEX to RGB?

Split the six hex digits into three pairs and convert each pair from base 16 to base 10. For #FF6B35, FF = 255, 6B = 107 and 35 = 53, so the RGB value is rgb(255, 107, 53). Paste the code into this converter and it shows RGB, HSL and the CSS Color 4 forms at once.

What is the difference between RGB and HSL?

Both describe the same sRGB colors. RGB gives the amount of red, green and blue light (0-255 each). HSL gives hue as an angle on the color wheel (0-360 degrees), plus saturation and lightness as percentages. HSL is easier to adjust by hand: to make a darker shade, lower the lightness and keep the hue.

What is an 8-digit HEX color?

An 8-digit HEX code such as #FF6B3580 adds an alpha (opacity) pair after the red, green and blue pairs. 00 is fully transparent and FF is fully opaque, so 80 (128 of 255) is about 50% opacity. CSS also accepts the 4-digit short form, #RGBA. All current browsers support both.

Why does converting HEX to HSL and back give a slightly different color?

HSL values are usually rounded to whole numbers, and one percent of lightness is about 2.5 RGB steps, so the rounding moves the color. In a test of 300,000 random colors, whole-number HSL changed the HEX value for about 9 out of 10. This tool prints HSL with one decimal place, which converted every one of those colors back to the exact same HEX code.

Can I convert rgba() to HEX?

Yes. Enter rgba(255, 107, 53, 0.5) or the modern rgb(255 107 53 / 50%) and the converter outputs the 8-digit HEX code #FF6B3580. Alpha is multiplied by 255 and rounded, so 0.5 becomes 128, which is 80 in hex.

How many named colors does CSS have?

CSS Color Module Level 4 defines 148 named colors, from aliceblue to yellowgreen, plus the keyword transparent. Some are spelling pairs (gray and grey, darkgray and darkgrey) and a few are aliases (aqua and cyan, fuchsia and magenta). This tool converts any of them and tells you when a color exactly matches a name.

Which text color is readable on my background color?

The converter calculates the WCAG contrast ratio of your color against white and against black and recommends the higher one. WCAG AA requires 4.5:1 for normal text and 3:1 for large text; AAA requires 7:1. For #FF6B35, white text only reaches 2.84:1 while black reaches 7.41:1, so black text is the readable choice.

Is my data safe?

Yes. All conversions happen in your browser with JavaScript. No color values or anything else you type are sent to a server.