The RGB-to-HSL formula normalizes 8-bit red, green, and blue channels to 0–1, then derives hue from the dominant channel, saturation from the channel range, and lightness from the maximum and minimum channels.

Use it when you have an RGB triplet and need HSL values for a color picker, stylesheet, graphics control, or teaching example. RGB records the amount of red, green, and blue; HSL describes the same color through hue, saturation, and lightness. Conventional HSL notation uses degrees for hue and percentages for saturation and lightness.

Keep one boundary clear: HSL and HSV are different models. HSL lightness comes from the average of the maximum and minimum channels, while HSV value is simply the maximum normalized channel. The related RGB to HSV Converter later in this article is appropriate only for an HSV destination.

convert rgb to hsl formula
Convert RGB to HSL Formula: A Practical Guide

What each HSL component represents

HSL separates a color’s position on the color wheel from two properties that control how intense and light it appears.

  • Hue (H) is the color’s position on a 0–360° wheel.
  • Saturation (S) describes color intensity relative to lightness. At zero saturation, the result is a neutral gray.
  • Lightness (L) describes the balance between black and white. Zero is black, while 100% is white.

When the red, green, and blue channels are equal, the color is achromatic. Hue has no visual meaning in that case, so the formula uses 0° as a conventional placeholder. Saturation is also zero, while lightness still reflects the shared channel level.

Model What it describes Conventional numeric fields Key distinction
RGB Amounts of red, green, and blue Three channels, normally 0–255 Additive channel representation
HSL Hue, saturation, and lightness H: 0–360°, S and L: 0–100% Lightness uses the maximum and minimum
HSV Hue, saturation, and value H: 0–360°, S and V: 0–100% Value uses the maximum

Prepare the RGB channels for calculation

For an ordinary 8-bit RGB color, let the input channels be R, G, and B, each ranging from 0 through 255. Convert them to the same 0–1 scale before comparing their values:

  • r = R ÷ 255
  • g = G ÷ 255
  • b = B ÷ 255

Next, find the largest normalized channel, the smallest normalized channel, and the difference between them:

  • M = max(r, g, b)
  • m = min(r, g, b)
  • Δ = M − m

Keep these normalized values for every remaining step. Using the original 0–255 channels in the hue or saturation equations would produce values outside the expected range.

Calculate hue from the dominant channel

When Δ is not zero, the largest channel determines which hue formula applies:

  • If red is largest: H = 60 × (((g − b) ÷ Δ) mod 6)
  • If green is largest: H = 60 × (((b − r) ÷ Δ) + 2)
  • If blue is largest: H = 60 × (((r − g) ÷ Δ) + 4)

Here, “mod 6” means the nonnegative remainder from 0 through 5. It keeps the red-channel formula on the correct part of the wheel even when the intermediate difference is negative. Normalize the final hue so that 0 ≤ H < 360.

If Δ is zero, all three channels are equal. Hue is visually undefined, so use H = 0 as a placeholder rather than dividing by zero.

Calculate saturation and lightness

Calculate lightness from the two extreme channels:

L = (M + m) ÷ 2

For saturation, first check whether Δ is zero. If it is, set S to zero. Otherwise, use the branch that corresponds to the lightness level:

  • When L ≤ 0.5: S = Δ ÷ (M + m)
  • When L > 0.5: S = Δ ÷ (2 − M − m)

These ratios produce saturation from 0 to 1. Multiply S and L by 100 to express them as percentages, while hue remains in degrees. Handling Δ = 0 before applying either fraction also prevents division-by-zero problems for black and white.

Convert RGB to HSL step by step

This single calculation demonstrates the complete formula using an RGB triplet of 51, 153, and 204.

  1. Normalize the channels. The normalized values are r = 51 ÷ 255 = 0.2, g = 153 ÷ 255 = 0.6, and b = 204 ÷ 255 = 0.8.
  2. Find the extremes and range. The maximum is M = 0.8, the minimum is m = 0.2, and the difference is Δ = 0.8 − 0.2 = 0.6.
  3. Calculate lightness. Using L = (M + m) ÷ 2 gives L = (0.8 + 0.2) ÷ 2 = 0.5, or 50%.
  4. Select the correct hue branch. Blue is the largest channel, so H = 60 × (((0.2 − 0.6) ÷ 0.6) + 4) = 200°.
  5. Calculate saturation. Because L is not greater than 0.5, use S = Δ ÷ (M + m), giving S = 0.6 ÷ (0.8 + 0.2) = 0.6, or 60%.
  6. Write the final result. The converted color is HSL(200°, 60%, 50%).

Match the output scale to its destination

A mathematically correct conversion can still be copied incorrectly if the destination uses different units. Check whether a control expects degrees and percentages, fractional values from 0 to 1, or a compact integer encoding.

Destination Representation to verify Safe action
Conventional HSL control Hue in degrees, with saturation and lightness as percentages Use the HSL result and its stated notation
Fraction-based API Some fields may require zero-to-one fractions Convert only the fields identified as fractions
HSV control Hue in degrees, with saturation and value as percentages or fractions Use HSV output; do not substitute HSL lightness for value
Compact integer format Hue may use a 0–179 or 0–255 integer scale Follow the destination’s documented scale instead of copying degrees unchanged

If the destination explicitly expects HSL, use an HSL converter rather than relabeling the value component of an HSV result. The names are similar, but the numerical meanings are not.

Use the RGB to HSV Converter for an HSV workflow

For a destination that genuinely expects HSV, the RGB to HSV Converter handles the HSV version of the workflow. It calculates HSV, not HSL, so do not relabel its value as lightness.

  1. Enter whole-number red, green, and blue channel values from 0 through 255.
  2. Select Convert to HSV.
  3. Read hue in degrees plus saturation and value as percentages.
  4. Check whether the destination expects degrees and percentages, zero-to-one fractions, or a compact integer range before copying the values.

The converter accepts only finite whole-number channels in that range. Decimal values, empty fields, negative numbers, and values above 255 produce an explicit error instead of being silently rounded or clamped. Its interface displays two decimal places for readability, while the internal result remains unrounded until formatting. Achromatic colors return saturation zero and the conventional placeholder hue of 0°.

It runs entirely in the browser and does not save a color history. The input is treated as an sRGB-style triplet; the converter does not read embedded image profiles, convert wide-gamut color spaces, or handle alpha.

The output range follows Android’s Color.colorToHSV reference, and the implementation is independently checked against R’s rgb2hsv documentation.

Avoid HSL and HSV mix-ups

  • Do not confuse L with V. HSL lightness averages the maximum and minimum channels, while HSV value uses the maximum normalized channel.
  • Do not paste percentages into fractional fields. A destination that requires zero-to-one saturation or lightness needs the fraction form.
  • Do not treat achromatic hue as meaningful. Equal RGB channels have no visual hue, regardless of the placeholder recorded in the output.
  • Do not round earlier than necessary. Displayed decimal places may be sufficient for a color picker, but code with tighter precision requirements needs the unrounded result.
  • Do not assume conversion establishes accessibility. HSL coordinates describe color, not text readability.

If the color will be used for text or interface controls, test the actual foreground and background pair with the Color Contrast Checker rather than inferring contrast from the conversion.

Related reading: How to Choose the Right Approach to Convert CMYK to RGB.

Related reading: Convert RGB to HSV: Degrees, Percentages, and Fractions.