Home › Color Converter (HEX ⇄ RGB ⇄ HSL)
Color Converter (HEX ⇄ RGB ⇄ HSL)
How the color formats relate
HEX and RGB are two spellings of the same thing: the amount of red, green and blue light on a 0–255 scale. HEX writes each channel as two hexadecimal digits (#0369a1), RGB writes them as decimals (rgb(3, 105, 161)). HSL describes the same color as a hue angle on the color wheel (0–360°, red = 0, green = 120, blue = 240), a saturation percentage and a lightness percentage. The converter goes HEX/RGB → HSL with the standard formulas from the CSS Color specification and rounds HSL to whole numbers, so a round trip may differ by 1 in a channel.
Examples
| HEX | RGB | HSL |
|---|---|---|
#ff0000 | rgb(255, 0, 0) | hsl(0, 100%, 50%) |
#808080 | rgb(128, 128, 128) | hsl(0, 0%, 50%) |
#1e90ff | rgb(30, 144, 255) | hsl(210, 100%, 56%) |
Gotchas
- Modern CSS syntax:
rgb(3 105 161 / 50%)(space-separated, slash for alpha) is equivalent torgba(3, 105, 161, 0.5). Both are accepted here. - Contrast is computed on opaque colors. A semi-transparent color's real contrast depends on what is behind it, so alpha is ignored in the contrast check.
- Named colors such as
rebeccapurpleare also accepted, since the browser resolves them for us.
Frequently asked questions
How do I convert HEX to RGB?
Split the 6-digit HEX code into three pairs and convert each pair from base 16 to base 10. #1E90FF becomes 1E=30, 90=144, FF=255, so rgb(30, 144, 255). A 3-digit code like #0af is shorthand for #00aaff.
What does the alpha channel in 8-digit HEX mean?
The last two digits of #RRGGBBAA are opacity from 00 (fully transparent) to FF (fully opaque). For example #00000080 is black at about 50% opacity, the same as rgb(0 0 0 / 0.5). All modern browsers support 8-digit HEX in CSS.
Why use HSL instead of RGB?
HSL (hue, saturation, lightness) matches how people think about color. Keeping the hue and saturation and changing only the lightness gives you consistent tints and shades for hover states or a design palette, which is awkward to do with RGB numbers.
What contrast ratio do I need for accessible text?
WCAG 2.x level AA requires a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text (about 24px, or 18.66px bold). Level AAA requires 7:1 and 4.5:1. The tool shows the ratio of your color against white and black.