RGB to HSL Converter

Turn rgb(r, g, b) values into HSL and back without opening a design tool or doing the math by hand. The converter is useful when you write modern CSS or work with color tokens that are easier to tweak in the HSL space.

Type a color in the RGB format and you will see the matching HSL triplet immediately. The reverse direction is also supported, so you can start from the syntax that matches your current file and then switch to the other one when needed.

On this page you will also find a short explanation of what RGB and HSL mean, a clear step by step formula, and a small reference table with frequently used colors written in both notations.

What Is RGB

The RGB model describes a color as a mix of three light components: red, green, and blue. Each channel is represented by an integer from 0 to 255, where 0 means no contribution from this channel and 255 means maximum intensity.

When the three channels are combined, they form the pixels you see on screens. For example, rgb(255, 255, 255) is white, rgb(0, 0, 0) is black, and rgb(0, 128, 255) is a saturated light blue.

Because RGB uses plain numbers, it works well for dynamic effects: gradients, animated transitions, or generated palettes can all be expressed as changes in three numeric channels.

What Is HSL

HSL stands for Hue, Saturation, and Lightness. It reorganizes the same color space used by RGB but uses parameters that are easier to read and reason about in design work.

Hue is measured in degrees from 0 to 360 along the color wheel. For instance, red is near 0, green is close to 120, and blue is around 240. Saturation and lightness are written as percentages from 0% to 100%.

A low saturation value moves the color closer to a neutral gray. Lightness controls how dark or bright the color is: 0% produces black, 50% gives a vivid version of the hue, and 100% yields white. Because of this, HSL often feels more intuitive for building palettes and state variations in user interfaces.

RGB to HSL Formula

rgb(r, g, b) -> hsl(h, s, l)

1) Normalize channels to [0, 1]:
   r' = r / 255
   g' = g / 255
   b' = b / 255

2) Find max and min:
   max = max(r', g', b')
   min = min(r', g', b')
   delta = max - min

3) Compute lightness:
   l = (max + min) / 2

4) Compute saturation:
   if delta == 0 then
     s = 0
   else
     s = delta / (1 - |2 * l - 1|)

5) Compute hue:
   if delta == 0 then
     h = 0
   else if max == r' then
     h = 60 * (((g' - b') / delta) mod 6)
   else if max == g' then
     h = 60 * (((b' - r') / delta) + 2)
   else if max == b' then
     h = 60 * (((r' - g') / delta) + 4)

6) Convert to final units:
   H = h             // degrees in [0, 360)
   S = s * 100       // percentage
   L = l * 100       // percentage

The algorithm keeps the original RGB information but expresses it in a different way. Lightness is based on the average of the brightest and darkest channel, saturation depends on how far the channels are spread out, and hue is determined by which component is dominant.

Example for rgb(79, 163, 194)
1) Normalize r, g, b to the [0, 1] range
2) Compute max, min, delta
3) Calculate h, s, l using the rules above
4) Rounded result:
   hsl(196, 49%, 54%)

How RGB to HSL Conversion Works Step by Step

Every RGB to HSL conversion follows the same structure: scale the channels, compare them to each other, and use the relationships between them to compute hue, saturation, and lightness.

rgb(26, 43, 60)
[26, 43, 60] -> hsl(h, s, l)

Let us look at the stages in more detail using rgb(26, 43, 60) as an example.

  • Step 1 — Normalize the channels:
    r' = 26 / 255
    g' = 43 / 255
    b' = 60 / 255
  • Step 2 — Find max, min, and lightness:

    The maximum and minimum channels tell you how bright the color can get. Their average becomes lightness, which roughly corresponds to how light or dark the color looks on screen.

    max = max(r', g', b')
    min = min(r', g', b')
    l = (max + min) / 2
  • Step 3 — Compute saturation and hue:

    If all three channels are almost the same, the color is close to gray and saturation is low. When one channel clearly dominates, saturation grows and the hue points to the segment of the color wheel where that channel is strongest.

    hsl(210, 39%, 17%)

You can apply the same method to any valid RGB color: normalize the values, compute lightness, derive saturation, and finally calculate hue from the dominant channel.

Choosing Between RGB and HSL

RGB and HSL describe the same colors but emphasize different aspects. RGB focuses on three numeric channels, while HSL focuses on the base hue, how intense the color is, and how light or dark it appears.

When RGB Is Handy

  • Low level work in graphics and code: many APIs and image formats work directly with RGB values.
  • Channel based effects: you can adjust a single channel in JavaScript or CSS when building filters, gradients, or transitions.
  • Interoperability with existing code: legacy styles and libraries often expect RGB or HEX values, so RGB is a natural starting point.

When HSL Is a Better Fit

  • Designing palettes and states: keeping hue fixed while changing saturation and lightness makes it easy to create hover, active, and disabled states from a single base color.
  • Exploring subtle variations: small changes in lightness often feel more predictable than direct tweaks to RGB channels.
  • Working with theming: HSL tokens are easy to read and adjust when you maintain both light and dark themes for an interface.

Summary

Use RGB when you need explicit channel control or when an API expects that format. Prefer HSL when you build palettes, define design tokens, or want color values that are easier for humans to adjust and discuss.

Practical Tips for Building HSL Palettes

Many teams store colors in one format but think about them in another. It is common to keep HEX or RGB values in code while exploring variants in HSL to get a more structured color system.

Keep Hue Stable for Brand Colors

  • Fix the hue, vary saturation and lightness: this produces shades that still feel like the same brand color but work for different UI roles such as backgrounds, borders, and accents.
  • Use low saturation for surfaces: muted versions of a hue are often more comfortable for panels and cards, while higher saturation works better for buttons and key highlights.

Move Between HSL and Other CSS Formats

  • Convert once for tokens: you can experiment with colors in HSL and then freeze the final values as HSL, RGB, or HEX in your design tokens.
  • Treat alpha separately: for transparency, you can use the hsla() or rgba() functions while still thinking about the base color in HSL.

Avoid Common Pitfalls

  • Mixing too many formats in one file: pick a primary notation for tokens and convert to others through utilities when you need them.
  • Ignoring contrast: when adjusting lightness, always check how text and icons look on top of the background color.
  • Using only lightness for depth: better palettes usually adjust both saturation and lightness instead of relying on a single slider.

With a consistent strategy for HSL and clear conversion rules, your color system becomes easier to reason about and maintain across different themes and components.

RGB to HSL Conversion Table

The table below lists a set of familiar colors in both RGB and HSL formats. Values are rounded for clarity, which makes the table convenient as a quick reference while you design or implement themes.

RGB to HSL Reference Table
DescriptionRGBHSL
Whitergb(255, 255, 255)hsl(0, 0%, 100%)
Blackrgb(0, 0, 0)hsl(0, 0%, 0%)
Redrgb(255, 0, 0)hsl(0, 100%, 50%)
Greenrgb(0, 255, 0)hsl(120, 100%, 50%)
Bluergb(0, 0, 255)hsl(240, 100%, 50%)
Yellowrgb(255, 255, 0)hsl(60, 100%, 50%)
Cyanrgb(0, 255, 255)hsl(180, 100%, 50%)
Magentargb(255, 0, 255)hsl(300, 100%, 50%)
Gray 1rgb(17, 17, 17)hsl(0, 0%, 7%)
Gray 2rgb(51, 51, 51)hsl(0, 0%, 20%)
Gray 3rgb(85, 85, 85)hsl(0, 0%, 33%)
Gray 4rgb(119, 119, 119)hsl(0, 0%, 47%)
Gray 5rgb(153, 153, 153)hsl(0, 0%, 60%)
Gray 6rgb(204, 204, 204)hsl(0, 0%, 80%)
Orangergb(255, 165, 0)hsl(39, 100%, 50%)
Purplergb(128, 0, 128)hsl(300, 100%, 25%)
Tealrgb(0, 128, 128)hsl(180, 100%, 25%)

For any other RGB triplet you can rely on the converter at the top of the page, which implements the standard RGB to HSL algorithm for valid inputs.

FAQ: RGB to HSL

  • Why would I convert RGB to HSL

    RGB is convenient for storage and low level graphics work, but HSL makes it easier to build structured palettes and talk about design decisions. Moving between the formats lets you combine predictable math with a more human friendly description of color.

  • What ranges do H, S, and L use

    Hue is written in degrees from 0 to 360. Saturation and lightness are percentages from 0 percent to 100 percent, which is why many design tools show them as sliders with a percentage label.

  • Does converting to HSL change the color

    No. HSL and RGB are just two different ways to encode the same color space. A valid RGB triplet and its HSL counterpart describe the same visual color on screen.

  • How is HSL different from HSV

    Both models share hue and saturation, but the third value is defined differently. HSL uses lightness, which compares the color to both black and white, while HSV uses value, which compares the color only to black.

  • Can I mix RGB, HSL, HEX, and other formats in one project

    Yes. A common approach is to choose one main notation for design tokens, such as HSL or HEX, and convert to RGB or other formats when a specific API requires it. The key is to keep conversions automatic and avoid manual recalculations.

Related Converters: