All Tools

Color HEX, RGB & HSL Converter

How It Works / Formula

HEX to RGB: Extract each color channel (RR, GG, BB) and convert from hexadecimal to decimal.

RGB to HSL: Use the following formulas:

R' = (R / 255), G' = (G / 255), B' = (B / 255)

Cmax = max(R', G', B'), Cmin = min(R', G', B')

Δ = Cmax - Cmin

L = (Cmax + Cmin) / 2

H = 0 if Δ = 0

H = 60 * ((G' - B') / Δ) if Cmax = R'

H = 60 * ((B' - R') / Δ + 2) if Cmax = G'

H = 60 * ((R' - G') / Δ + 4) if Cmax = B'

S = 0 if L = 0 or L = 1

S = Δ / (1 - abs(2 * L - 1)) if L ≠ 0 and L ≠ 1

Examples

HEX: #38bdf8 -> RGB: 56, 190, 248 -> HSL: 203.6, 89.2%, 57.8%

RGB: 255, 0, 0 -> HEX: #ff0000 -> HSL: 0, 100%, 50%

RGB: 0, 255, 0 -> HEX: #00ff00 -> HSL: 120, 100%, 50%