About this tool
Convert colors between HEX, RGB and HSL. Enter #RGB, #RRGGBB, rgb() or hsl() to see all three formats with a swatch — handy for front-end work and picking colors from designs.
Typical uses
- Turn a HEX value from a design into RGB
- Convert an HSL color to HEX for CSS
- Preview what a color value looks like
How to use
Enter a color as #RGB, #RRGGBB, rgb(...) or hsl(...).
Convert to see HEX, RGB and HSL values and a color swatch.
Only opaque colors are handled; #RRGGBBAA and rgba() with alpha are unsupported.
What the input box accepts and rejects
The “Color” box understands four notations: 3- or 6-digit hex (the # is optional, case does not matter, surrounding spaces are trimmed), comma-separated rgb(r, g, b), and hsl(h, s%, l%) with percent signs. Function names are case-insensitive. These are the actual results of pressing “Convert” (on success the three result lines are joined with ·):
| Input | Result or message | Note |
|---|---|---|
| #2563EB | #2563EB · rgb(37, 99, 235) · hsl(221.2, 83.2%, 53.3%) | The default value |
| 2563eb | #2563EB · rgb(37, 99, 235) · hsl(221.2, 83.2%, 53.3%) | No # and lowercase are fine; HEX output is always uppercase |
| #abc | #AABBCC · rgb(170, 187, 204) · hsl(210.0, 25.0%, 73.3%) | Short form doubles each digit: abc equals AABBCC |
| bad | #BBAADD · rgb(187, 170, 221) · hsl(260.0, 42.9%, 76.7%) | A word spelled with a–f is read as a color |
| rgb(37, 99, 235) | #2563EB · rgb(37, 99, 235) · hsl(221.2, 83.2%, 53.3%) | The legacy CSS comma syntax |
| RGB(37,99,235) | #2563EB · rgb(37, 99, 235) · hsl(221.2, 83.2%, 53.3%) | Uppercase function names work |
| hsl(221.2, 83.2%, 53.3%) | #2563EB · rgb(37, 99, 235) · hsl(221.2, 83.2%, 53.3%) | Pasting the tool’s own HSL line back gives the original color |
| hsl(360, 100%, 50%) | #FF0000 · rgb(255, 0, 0) · hsl(0.0, 100.0%, 50.0%) | Hue 360 is the same red as hue 0 |
| #2563EB80 | Use #RGB, #RRGGBB, rgb(r,g,b), or hsl(h,s%,l%). | 8-digit hex with alpha is refused |
| #ABCD | Use #RGB, #RRGGBB, rgb(r,g,b), or hsl(h,s%,l%). | 4-digit hex is refused as well |
| rgb(37 99 235) | Use #RGB, #RRGGBB, rgb(r,g,b), or hsl(h,s%,l%). | The newer space-separated CSS syntax is refused; use commas |
| rgba(37, 99, 235, 1) | Use #RGB, #RRGGBB, rgb(r,g,b), or hsl(h,s%,l%). | rgba() is always refused, even with alpha 1 |
| rgb(37%, 0%, 0%) | Use #RGB, #RRGGBB, rgb(r,g,b), or hsl(h,s%,l%). | RGB percentages are not accepted |
| rgb(10.5, 0, 0) | Use #RGB, #RRGGBB, rgb(r,g,b), or hsl(h,s%,l%). | RGB takes integers only; a decimal gives the format message, not the range message |
| rgb(-1, 0, 0) | Use #RGB, #RRGGBB, rgb(r,g,b), or hsl(h,s%,l%). | A negative value also gives the format message |
| rgb(300, 0, 0) | RGB channels must be integers from 0 to 255. | Only values above 255 give the range message |
| hsl(217, 91, 60) | Use #RGB, #RRGGBB, rgb(r,g,b), or hsl(h,s%,l%). | Saturation and lightness need % |
| hsl(217deg, 91%, 60%) | Use #RGB, #RRGGBB, rgb(r,g,b), or hsl(h,s%,l%). | No deg unit on the hue |
| hsl(-30, 50%, 50%) | Use #RGB, #RRGGBB, rgb(r,g,b), or hsl(h,s%,l%). | A negative hue gives the format message; CSS would wrap it to 330 |
| hsl(361, 50%, 50%) | HSL ranges: hue 0–360, saturation and lightness 0–100%. | Hue above 360 gives the range message |
| blue | Use #RGB, #RRGGBB, rgb(r,g,b), or hsl(h,s%,l%). | CSS color names are not supported |
- CSS Color 4 allows hex with 3, 4, 6 or 8 digits, space-separated rgb() with “/ alpha”, treats rgba() as an alias of rgb(), allows an angle unit on the hue and normalizes hues outside 0–360 into that range. This tool implements only the opaque, comma-separated subset, so rewrite those forms first: rgb(37 99 235) becomes rgb(37, 99, 235), and hsl(217deg 91% 60%) becomes hsl(217, 91%, 60%).
- Word trap: bad → #BBAADD, facade → #FACADE, decade → #DECADE. Only 3- and 6-letter words pass as colors. If you paste an English word by mistake, the tool will not complain.
- Color names (blue, tomato …) and CSS variables are not read. Copy the computed rgb() value from the browser’s developer tools instead.
How the three result lines are produced
Whatever you type is first turned into integer RGB channels from 0 to 255, and all three lines come from those: HEX in uppercase, rgb(r, g, b) with a space after each comma, and hsl(h, s%, l%) with one decimal place each. The default #2563EB gives #2563EB, rgb(37, 99, 235) and hsl(221.2, 83.2%, 53.3%). “Copy” copies all three lines at once; the swatch is painted with the HEX value.
- HSL input is rounded to whole RGB channels, so the HSL shown back can differ from what you typed: hsl(0, 0%, 50%) gives #808080 and is shown as hsl(0.0, 0.0%, 50.2%); hsl(120, 100%, 25%) gives #008000 and is shown as hsl(120.0, 100.0%, 25.1%). That is the precision of 8-bit RGB, not a conversion error.
- One decimal place is enough to get back: for every one of the 16,777,216 RGB colors, pasting the hsl(...) line from the result back into the box returns the original HEX.
- Whole numbers are not enough: hsl(221.2, 83.2%, 53.3%) rounded to hsl(221, 83%, 53%) gives #2463EB, not #2563EB. Of the 4,096 three-digit hex colors, 3,046 (about 74%) change color when their HSL is rounded to integers. Hand colors to developers as HEX or RGB, and keep at least one decimal in HSL.
- Greys (R = G = B) show hue and saturation as 0.0. Hue means nothing for a grey; only lightness changes it.
Every message and what causes it
A successful conversion shows “Converted.”. These are all the other messages:
| Message | Cause and fix |
|---|---|
| Use #RGB, #RRGGBB, rgb(r,g,b), or hsl(h,s%,l%). | The text is none of the four notations: a color name, 4- or 8-digit hex, rgba(), space-separated rgb()/hsl(), a decimal or negative RGB value, hsl without %, a hue with deg or a negative hue |
| RGB channels must be integers from 0 to 255. | An rgb() channel is an integer above 255, for example rgb(300, 0, 0) |
| HSL ranges: hue 0–360, saturation and lightness 0–100%. | The hsl() syntax is right but the hue is above 360, or saturation or lightness is above 100% |
| Color changed. Convert again. | You edited the box after converting; the old result and swatch were cleared, so press Convert again |
To check whether text on a background is readable, paste the HEX straight into the contrast checker; it accepts exactly the same notations.
Sources
Frequently asked questions
Is transparency supported?
Only opaque colors; #RRGGBBAA and rgba() with alpha are unsupported.
Which inputs are accepted?
#RGB, #RRGGBB, rgb(...) and hsl(...).
How do I check contrast?
Use the color contrast checker.
Suggest an improvement to this tool
Missing an option, something awkward to use, or a wrong result? Let us know.