How do I convert HEX to RGB and HSL?
To convert a HEX color to RGB, split it into three 2-digit pairs and convert each from hexadecimal to decimal (0-255); to get HSL, calculate hue, saturation, and lightness from those RGB values. Example: #4F46E5 converts to rgb(79, 70, 229) and hsl(243, 75%, 59%).
Steps to convert HEX to RGB and HSL
- Remove the # symbol and split the 6-digit HEX code into three 2-digit pairs (for #4F46E5: 4F, 46, E5).
- Convert each hexadecimal pair to a decimal number from 0 to 255 (4F=79, 46=70, E5=229) to get the RGB values.
- Divide each RGB value by 255 to normalize it to a 0-1 range, then find the maximum and minimum of the three.
- Lightness is the average of the max and min; saturation and hue are calculated from the difference between max and min using standard HSL formulas.
- Round hue to whole degrees (0-360) and saturation and lightness to whole percentages (0-100%) for display.
HEX to RGB to HSL
RGB channel = parseInt(hex pair, 16) · Lightness = (max(R,G,B) + min(R,G,B)) / 2, normalized 0-1
- R, G, B = red, green, blue channel values, each 0-255
- H, S, L = hue in degrees (0-360), saturation and lightness in percent (0-100%)
Common color conversions
What is #FF0000 in RGB?
#FF0000 is rgb(255, 0, 0) — pure red, with the red channel at its maximum and green and blue at zero.
What is #FFFFFF in RGB?
#FFFFFF is rgb(255, 255, 255) — pure white, with all three channels at their maximum.
What is #000000 in RGB?
#000000 is rgb(0, 0, 0) — pure black, with all three channels at zero.
What is rgb(0, 128, 0) in hex?
rgb(0, 128, 0) is #008000 — a medium green, since 128 in decimal is 80 in hexadecimal.
What is #FFA500 in RGB?
#FFA500 is rgb(255, 165, 0) — standard orange.
What is #00FF00 in RGB?
#00FF00 is rgb(0, 255, 0) — pure green, with only the green channel at its maximum.
What is #0000FF in RGB?
#0000FF is rgb(0, 0, 255) — pure blue, with only the blue channel at its maximum.
What is rgb(255, 255, 0) in hex?
rgb(255, 255, 0) is #FFFF00 — pure yellow, mixing full red and full green.
Example color conversions
| HEX | RGB | HSL |
|---|
| #4F46E5 | rgb(79, 70, 229) | hsl(243, 75%, 59%) |
| #FF0000 | rgb(255, 0, 0) | hsl(0, 100%, 50%) |
| #00FF00 | rgb(0, 255, 0) | hsl(120, 100%, 50%) |
| #1D4ED8 | rgb(29, 78, 216) | hsl(224, 76%, 48%) |
| #FFFFFF | rgb(255, 255, 255) | hsl(0, 0%, 100%) |
Frequently asked questions
What is the difference between HEX, RGB, and HSL?
HEX and RGB describe a color the same way, as red, green, and blue light amounts, just in different notations (base-16 vs base-10). HSL describes the same color by hue (the color itself), saturation (intensity), and lightness (how light or dark), which is often more intuitive for adjusting a color by hand.
Why does white show 0% saturation?
Saturation measures how far a color is from gray. Pure white, black, and every shade of gray in between have equal red, green, and blue values, so their saturation is always 0%, regardless of lightness.
Can I enter a 3-digit HEX code like #FFF?
This tool expects the full 6-digit HEX format (#RRGGBB). A 3-digit shorthand like #FFF is CSS shorthand for #FFFFFF, where each digit is doubled; expand it to 6 digits before entering it here.
How is hue calculated when red, green, and blue are all different?
Hue depends on which channel, red, green, or blue, has the highest value, and is calculated from the relative position of the other two channels. The result is an angle on a 360-degree color wheel, where 0 degrees is red, 120 is green, and 240 is blue.
This tool converts standard 6-digit HEX colors used on the web; it does not support alpha (transparency) channels, named CSS colors, or color spaces beyond sRGB such as HSV or LAB.
Sources: W3C CSS Color Module Level 4