GamutDesk Logo
GamutDesk

RGB to HSL Converter

Convert RGB color values to cylindrical HSL with step-by-step mathematical decomposition, W3C CSS Level 3/4 syntax, and Tailwind arbitrary class exports.

Client-Side ArchitecturePrivate Client-Side Processing
RGB Input Channels (0 - 255)
Red (R)
Green (G)
Blue (B)
max(R,G,B)0.922
min(R,G,B)0.145
Delta (Chroma)0.776
Target Hue
hsl(221deg 83% 53%)
Developer Export Format
hsl(221deg 83% 53%)
Hue (Angle)221°
Saturation83%
Lightness53%

Technical Specification & Mathematical Principles

Step-by-Step Algebraic Decomposition (RGB to HSL)

Converting non-linear sRGB coordinates into the cylindrical HSL (Hue, Saturation, Lightness) color space follows five deterministic algebraic steps:

Step 1: sRGB Channel Normalization

Scale integer byte coordinates from [0, 255] to real values [0.0, 1.0]:

R' = R / 255, G' = G / 255, B' = B / 255
Step 2: Extremes & Chroma Span Identification

Identify the maximum and minimum channel components and calculate chromatic span (Delta Δ):

C_max = max(R', G', B')
C_min = min(R', G', B')
Δ = C_max - C_min
Step 3: Lightness (L) Midpoint Calculation

Lightness represents the average of the most and least luminous channels:

L = (C_max + C_min) / 2
Step 4: Saturation (S) Scaling

If Δ = 0, the color is achromatic gray with S = 0%. Otherwise, saturation scales relative to maximum available chroma at lightness L:

S = Δ / (1 - |2L - 1|) = Δ / (2 - C_max - C_min)  [for L > 0.5]
S = Δ / (C_max + C_min)  [for L ≤ 0.5]
Step 5: Hue (H) Radial Degree Segment Calculation

Hue is evaluated across six 60-degree sextants depending on which color channel is maximal:

If Δ = 0: H = 0°
If C_max = R': H = 60° × (((G' - B') / Δ) mod 6)
If C_max = G': H = 60° × (((B' - R') / Δ) + 2)
If C_max = B': H = 60° × (((R' - G') / Δ) + 4)
If H < 0°: H = H + 360°
Looking to convert back? Switch to our HSL to RGB Converter, or convert HSL coordinates back to HEX for compact CSS declarations.

Need adjacent palette tones? Explore 30-degree hue offsets with our tool for analogous color harmonies.

Frequently Asked Questions

Why does the algorithm evaluate max and min channels first?
The maximum and minimum channel values establish both the lightness midpoint L = (max + min) / 2 and the chroma span delta = max - min. If delta is 0, the color is completely achromatic (gray).
How is Hue calculated when multiple channels are equal?
If max is Red, Hue is proportional to (G - B); if max is Green, to (B - R) + 2; and if Blue, to (R - G) + 4. When all three are equal, Hue is undefined and standardized to 0°.
What is the difference between CSS Level 4 and Level 3 HSL syntax?
CSS Color Module Level 4 introduces space-separated syntax with degree units (e.g., hsl(140deg 20% 50%)), whereas Level 3 syntax uses commas (e.g., hsl(140, 20%, 50%)). Both produce identical rendered colors in all modern browsers.
Can I use Tailwind CSS arbitrary values for HSL colors?
Yes, you can write bg-[hsl(140,20%,50%)] or text-[hsl(140,20%,50%)] in Tailwind CSS. Note that spaces must be omitted or replaced with underscores inside arbitrary Tailwind brackets.

Related Design & Color Instruments