Design & Accessibility
HEX vs RGB vs HSL: CSS Color Formats Explained
Compare HEX, RGB, and HSL color notation, convert between formats, and choose the representation that best fits design tokens, CSS components, and color adjustments.
In this article
HEX vs RGB vs HSL: CSS Color Formats Explained
The same browser color can be represented in several ways.
For example, a design might specify a color using:
#ff8800
rgb(255, 136, 0)
hsl(...)HEX, RGB, and HSL describe color through different notation systems.
Duck Cloud provides HEX to RGB, RGB to HEX, HEX to HSL, and HSL to HEX converters.
HEX colors
HEX notation commonly looks like:
#ff8800The six hexadecimal digits represent red, green, and blue channels.
HEX is compact and widely used in:
- design tools;
- CSS;
- brand guidelines;
- design tokens;
- documentation.
It is especially convenient when a team already thinks in hexadecimal color values.
RGB colors
RGB exposes the red, green, and blue channel values directly:
rgb(255, 136, 0)Each channel commonly ranges from 0 to 255 in this notation.
RGB can be easier when:
- values come from image or graphics APIs;
- you are manipulating individual color channels;
- a library returns RGB values.
Use HEX to RGB when translating a design-system HEX token into channel values.
HSL colors
HSL represents:
- hue;
- saturation;
- lightness.
Designers and developers often find HSL intuitive when generating related colors.
Changing lightness can produce lighter or darker variations while keeping a similar hue.
Use HEX to HSL to inspect a HEX color in HSL terms.
Which format should you use?
There is no single best format.
Use the representation that makes the operation easiest.
HEX is compact for fixed tokens.
RGB is direct for channel-based processing.
HSL can be convenient for systematic hue, saturation, and lightness adjustments.
A design system may store one format internally and expose generated variants through CSS variables.
Alpha transparency
Modern CSS supports color formats with alpha transparency.
Transparency changes the final visible color because the foreground blends with the background.
That means accessibility contrast must be tested against the actual composited background, not the original foreground color in isolation.
Use Duck Cloud's Contrast Checker on the final effective colors.
Conversion should preserve the intended color
Converting between formats should preserve the rendered color within the precision of the representation.
If a conversion appears visibly different, check:
- rounding;
- alpha;
- color profile;
- incorrect channel order;
- invalid input.
The Color Picker is useful for selecting a browser color and copying its HEX or RGB form.
Design tokens
A maintainable site might define:
--color-brand: #ff8800;
--color-text: #1a1a1a;
--color-surface: #ffffff;Components consume those tokens rather than scattering hard-coded values across dozens of files.
This makes later brand adjustments much easier.
Generate related color treatments
If you are building gradients, convert and inspect your colors, then use the CSS Gradient Generator to create a two-color linear gradient.
Keep effects intentional. A gradient should not reduce text readability or make controls difficult to recognize.
Accessibility still matters
Color format does not determine accessibility.
#777777 and its equivalent RGB/HSL representations have exactly the same contrast relationship with a given background.
Changing notation does not fix insufficient contrast.
Change the actual color values and test again.
Color workflow checklist
- Start from the approved brand/design value.
- Convert only when another representation is useful.
- Store colors as reusable tokens.
- Review alpha blending.
- Test text contrast.
- Test dark mode separately.
- Keep component states consistent.
- Avoid scattering near-identical hard-coded colors.
HEX, RGB, and HSL are different ways of describing the same color space for everyday CSS work. Use whichever notation makes your design system easier to understand and maintain.