About the Color Converter
This Color Converter takes a six-digit HEX color, from typing or from a color picker, and shows the same color as CSS rgb() and hsl() values next to a large preview. It is built for front-end developers and designers who move between design files and stylesheets.
How it works
A six-digit HEX code is three pairs of base-16 digits, one each for red, green, and blue. The converter reads each pair as a number from 0 to 255, so #2563eb becomes red 37, green 99, and blue 235, written as rgb(37, 99, 235).
For HSL, the RGB values are scaled to 0-1. Lightness is the average of the largest and smallest channel. Saturation depends on the difference between those two channels relative to lightness, and hue is calculated from which channel is largest and how the other two compare, giving an angle on the color wheel. Hue is rounded to whole degrees, and saturation and lightness to whole percentages.
How to use
- 1
Type a six-digit code into the HEX field, such as #2563eb, or click the color swatch to open your browser's color picker.
- 2
Check the large preview box to confirm the color.
- 3
Read the HEX, RGB, and HSL rows below the preview.
- 4
Click the copy icon next to the format you need.
Worked examples
A blue brand color
Converting the default color for use in a CSS variable.
An orange accent
Getting HSL values so you can create a lighter tint.
Raising the lightness to 75% in hsl() gives a softer tint of the same hue.
A neutral gray
Checking a mid-gray from a style guide.
Grays have equal red, green, and blue, so saturation is 0% and hue has no effect.
Frequently asked questions
What's the difference between RGB and HSL?+
RGB defines a color by its red, green, and blue components, while HSL uses hue, saturation, and lightness. HSL is often easier when you want a lighter, darker, or more muted version of a color.
Which format should I use in my CSS?+
All three are valid in modern CSS. HEX is compact, rgb() is convenient when you add transparency, and hsl() is easiest for building shades. Pick the one that suits the edit you are making.
Can I enter a three-digit HEX code?+
Not directly. Expand it first by doubling each digit, so #0af becomes #00aaff, and the converter will read it.
Why does the result say Invalid?+
The HEX field must contain exactly six hexadecimal digits (0-9, a-f), with or without a leading #. Extra characters, a missing digit, or an alpha channel make it invalid.
Is the conversion exact?+
The RGB values are exact. HSL values are rounded to whole degrees and percentages, so they are very close but may differ by a fraction from the precise value.