RGB to HSL color conversion

Advanced RGB to HSL Converter

RGB to HSL Converter

Convert RGB color values to HSL and HEX

RGB Values

Red (0-255):
Green (0-255):
Blue (0-255):
#FF0000

Conversion Results

HEX:
#FF0000
HSL:
hsl(0, 100%, 50%)
Hue:
Saturation:
100%
Lightness:
50%
Hue: 0°
Saturation: 100%
Lightness: 50%



An RGB to HSL converter is a tool or algorithm that transforms colors from the RGB (Red, Green, Blue) color model to the HSL (Hue, Saturation, Lightness) model. This conversion is useful in digital graphics, web design, and image processing because HSL provides a more intuitive way to manipulate colors based on human perception rather than raw RGB values.


RGB Color Model


The RGB model defines colors using three components:

  • Red (R) – Intensity (0 to 255)
  • Green (G) – Intensity (0 to 255)
  • Blue (B) – Intensity (0 to 255)

HSL Color Model


The HSL model represents colors based on three components:


 1. Hue (H) – The color type (0° to 360°)

  • 0° = Red, 120° = Green, 240° = Blue

 2. Saturation (S) – The intensity of the color (0% to 100%)

  • 0% = Grayscale, 100% = Fully saturated

 3. Lightness (L) – The brightness of the color (0% to 100%)

  • 0% = Black, 50% = Pure color, 100% = White

RGB to HSL Conversion Algorithm

Step 1: Normalize RGB Values

Convert RGB values from 0–255 to 0–1:

R=R255,G=G255,B=B255

Step 2: Find Min and Max Values

Determine the minimum and maximum of the three components:

Min=min(R,G,B)Max=max(R,G,B)

Step 3: Calculate Lightness (L)

Lightness is the average of the min and max values:

L=Min+Max2

Step 4: Calculate Saturation (S)

  • If Min = Max, the color is grayscale (S = 0).

  • Otherwise:

    S={MaxMinMax+Minif L0.5MaxMin2(Max+Min)if L>0.5

Step 5: Calculate Hue (H)

  • If Max = Min, hue is undefined (grayscale, H = 0).

  • Otherwise:

    Compute hue based on which component is the max:H={60°×(GBMaxMin)+0°if Max=R60°×(BRMaxMin)+120°if Max=G60°×(RGMaxMin)+240°if Max=B
  • Adjust negative hue: If H < 0, add 360° to wrap it correctly.

Step 6: Convert HSL to Percentage/Range

  • Hue (H) remains in degrees (0°–360°).

  • Saturation (S) & Lightness (L) are converted to percentages (0%–100%).


Example Conversion

Convert RGB(255, 0, 0) (Pure Red) to HSL:

  1. Normalize RGB:

    R=1.0,G=0.0,B=0.0
  2. Find Min & Max:

    Min=0.0,Max=1.0
  3. Calculate Lightness (L):

    L=0.0+1.02=0.5(50%)
  4. Calculate Saturation (S):

    S=1.00.01.0+0.0=1.0(100%)
  5. Calculate Hue (H):

    Max=R,so:H=60°×(0.00.01.00.0)+0°=0°
  6. Final HSL:

    HSL(0°,100%,50%)