HEX RGB HSL Color Converter

Convert colors between HEX, RGB and HSL formats in real time. Use the visual picker or type the value directly. Ideal for web developers and designers.

Color Converter

Type in any field to update the others automatically.

Each color format has its ideal context in CSS

HEX, RGB and HSL represent exactly the same colors; they are just different notations for the same sRGB color space. The choice between them does not change how a color looks on screen, but it matters a lot for code maintenance, readability and how easy it is to create programmatic color variations.

Designers and tools like Figma work mostly with HEX and RGB. But in CSS code, especially when building design systems with themes and dynamic palettes, HSL offers a considerable advantage: it is intuitive to create lighter or darker variants of a color simply by adjusting the lightness value.

HEX: the common language between design and development

The hexadecimal format was born with the web and is still the most widespread. Each pair of hexadecimal digits (00 to FF, decimal 0 to 255) represents the intensity of one color channel: red, green and blue respectively. #FF0000 is pure red, #00FF00 is pure green and #0000FF is pure blue. Mixing these three additive primaries produces every other color.

HEX is compact (7 characters including the #) and is the default format in the palettes of design systems like Material Design, Tailwind and Ant Design. When you receive color specs from a designer, HEX is the most likely format, but for implementing dynamic themes in CSS, converting to HSL often results in code that is easier to maintain.

RGB: granular control of the color channels

The RGB (Red, Green, Blue) model is the additive color model used by screens. Each channel goes from 0 to 255, for more than 16 million combinations. In CSS, the notation rgb(255, 0, 128) and the modern rgb(255 0 128) are equivalent. With rgba(), a fourth parameter from 0 to 1 controls transparency.

RGB is useful when you need to manipulate individual channels, for example in animations that gradually change a color in JavaScript, or when mixing colors programmatically. For CSS themes, though, HSL is more intuitive to manipulate because "making a color lighter" simply means increasing L, without recalculating all three channels.

HSL: the developers' favorite model for themes

HSL (Hue, Saturation, Lightness) describes colors the way people think about them: which color it is (hue), how vivid it is (saturation) and how light or dark it is (lightness). This makes building coherent palettes far more intuitive: to generate 9 variants of a design-system color, you keep H and S constant and space L at regular intervals.

With CSS custom properties, a powerful strategy is to store only the HSL components: --primary-h: 220; --primary-s: 70%; --primary-l: 50%;. Then you use hsl(var(--primary-h) var(--primary-s) var(--primary-l)) and can change the lightness for hover, focus and disabled variants without redefining the whole color.

Accessibility and color contrast

The WCAG 2.1 guidelines require a minimum contrast of 4.5:1 between text and background for level AA, and 7:1 for level AAA. Contrast is calculated from the relative luminance of the colors, which is derived from the RGB values. When choosing text and background colors, checking contrast is essential, especially when creating lighter variants with HSL, where it is easy to lose contrast without noticing.

A practical tip: when using HSL for themes, avoid very high L (above 90%) for text elements and very low L (below 15%) for backgrounds in light mode. In dark mode, flip the logic. Always validate contrast with dedicated tools after defining your palette.

Frequently asked questions

What is the difference between HEX, RGB and HSL?

HEX represents the color with 6 hexadecimal digits (two for red, two for green, two for blue), such as #FF5733. RGB uses three decimal values from 0 to 255 for the same channels, such as rgb(255, 87, 51). HSL defines the color by hue (0-360°), saturation (0-100%) and lightness (0-100%), such as hsl(14, 100%, 60%). All three formats represent the same colors, just with different notations.

When should you use each color format in CSS?

HEX is the most common in design systems and design files: compact and familiar to designers. RGB is useful when you need to manipulate color channels dynamically or add transparency with rgba(). HSL is ideal for creating color variations programmatically: it is intuitive to adjust a color's lightness or saturation without changing the hue. CSS custom properties with HSL are a popular strategy for dynamic themes.

What do H, S and L mean in HSL?

H (Hue) is the position on the color spectrum in degrees (0° and 360° are red, 120° is green, 240° is blue). S (Saturation) is the color intensity: 0% is fully gray, 100% is the most vibrant color. L (Lightness) is how light the color is: 0% is black, 100% is white, 50% is the pure color. To create a palette of shades of one color, keep H and S fixed and vary only L.

What are shorthand HEX colors like #fff?

3-digit HEX is a shorthand where each digit is doubled. #fff equals #ffffff (white), #000 equals #000000 (black), #f0a equals #ff00aa. The shorthand only works when each pair of digits is identical. It is supported by all browsers and is a valid way to reduce size in CSS.

How do modern CSS color functions relate to these formats?

Modern CSS introduced new color functions: oklch() and oklab() for perceptually uniform manipulation, color() for wide-gamut color spaces such as display-p3, and lch() and lab(). The oklch() function is gaining adoption because it lets you build palettes with perceptually consistent lightness, something HSL does not guarantee. But HEX, RGB and HSL remain the most compatible and widely used formats.

How do you add transparency to colors in CSS?

For transparency, use rgba(255, 87, 51, 0.5) for 50% opacity in RGB, hsla(14, 100%, 60%, 0.5) in HSL, or 8-digit HEX where the last two digits represent the alpha channel (#FF573380 for 50%). Modern CSS also accepts rgb() and hsl() with four space-separated values: rgb(255 87 51 / 50%). The opacity property in CSS also works, but it affects the entire element including its children.