A Codrenix Toolbox guide
HEX, RGB, and HSL in a practical color workflow
Convert color values accurately, choose the right representation, and check contrast beyond the swatch.
By Codrenix Team · Published · Updated
Color values are often passed between design tools, CSS, spreadsheets, and image software in different forms. HEX, RGB, and HSL describe related aspects of a color, but each makes some decisions easier than others. Conversion helps keep a color consistent across tools; it does not guarantee that the color is accessible, looks identical on every display, or works against every background.
Choose a representation for the decision
HEX notation is compact and convenient for sharing an exact sRGB color in CSS or a design handoff. RGB exposes red, green, and blue channel values, which can be helpful when matching software APIs or adjusting a channel by a known amount. HSL separates hue, saturation, and lightness, making it easier to create a lighter tint or a less saturated variant while keeping the approximate hue. Pick the representation that helps with the current task, not because one is universally superior.
A common six-digit HEX value encodes three channel pairs, each from 00 to FF. Three-digit shorthand expands each nibble, so #369 corresponds to #336699, not to an arbitrary three-channel decimal value. Some formats also include alpha transparency, which changes how the color composites over a background. Check whether a field accepts alpha and whether it expects eight-digit HEX, an RGB alpha channel, or a separate opacity setting before pasting a value.
Understand rounding during conversion
RGB channels are often integers from 0 to 255, while HSL values may be represented as percentages and degrees. Converting between them can involve rounding, so converting a rounded HSL value back to RGB may differ by one channel value from the original. That small difference is expected in many tools. If exact repeatability matters, retain the original value or compare the final rendered color rather than expecting every rounded notation to round-trip character for character.
Use consistent ranges and syntax. A design token might store red as 0.2 on a zero-to-one scale, while a CSS field expects 51 on a zero-to-255 scale. Mixing these conventions can produce an almost-black color or an invalid value. Read the label next to a color input, and when copying a value into code, verify the prefix and separators. A plausible-looking swatch is not enough to prove the numeric interpretation is correct.
Use HSL for controlled variations, not magic
HSL is convenient for generating a family of colors: hold hue steady, reduce saturation for a quieter surface, or raise lightness for a pale background. For a dashboard with a blue accent, creating 10%, 20%, and 30% lightness variants gives a designer a predictable starting point. However, equal numeric changes in HSL lightness do not always look equally bright across different hues. Blue, yellow, and red at the same lightness can have very different perceived luminance.
A simple HSL adjustment should be reviewed in its actual interface, next to text, icons, and neighboring colors. Some displays and design environments apply color management, and different screen brightness settings alter perception. Avoid choosing a success or warning color solely from a saturated hue slider; pair color with clear labels or icons so meaning is not carried by color alone. HSL supports exploration, while visual testing decides whether a palette works.
Check text contrast against its real background
A swatch that looks distinct on a white page may be difficult to read when used for small text on a tinted card. Contrast depends on both foreground and background colors, and accessible guidance uses relative luminance rather than a casual visual guess. Evaluate the actual text color, background, font size, and state. A link that passes on a plain surface may fail over an image, gradient, or translucent overlay used on the live page.
Do not assume that increasing HSL lightness automatically improves contrast. If the foreground and background move closer in luminance, readability can get worse even when the foreground looks brighter in isolation. Check normal text and larger display text separately against the standard your project follows. Include hover, disabled, focus, and error states in the review. A contrast checker is a useful measurement tool, but it cannot judge whether a color communicates the intended meaning or suits the product.
Account for transparency and the surrounding surface
An alpha value describes how opaque a foreground color is; the final visible color depends on what sits behind it. A translucent black overlay at 20% can look different over white, a photograph, or a colored card. Converting only the foreground from HEX to RGB does not reproduce the composited result. When debugging a visual mismatch, inspect the complete CSS cascade, opacity, blend mode, and actual underlying surface rather than comparing one color field.
Design systems should name the context of a token when that context changes its use. A color called `mutedTextOnLight` is more informative than a generic gray if it was tuned for a particular background. Test tokens on the light and dark surfaces where they are meant to appear. If a component supports themes, check both themes and any semi-transparent overlays. Record the base value and the intended use so another teammate does not reuse an acceptable color in a context where it fails.
Make color handoffs repeatable
In a handoff, provide one canonical value and identify its color space, such as an sRGB HEX value, plus the token name if the project has one. A screenshot is helpful for showing intent but cannot reliably provide an exact color because compression, display calibration, and scaling can alter sampled pixels. When the value is important, copy it from the source design token and verify it in the implementation. That avoids accumulating slightly different blues across buttons and links.
For a palette change, check representative states in the actual product rather than approving a list of converted values alone. Ask whether the primary action stands out, body copy remains legible, and chart colors are distinguishable for users with color-vision differences. Save the original token set before broad edits and compare the updated implementation at normal zoom. A converter keeps notation aligned; careful context checks keep the resulting interface understandable and visually consistent.
Worked examples
Create a pale background from a brand blue
HSL makes controlled variations easier to explore, but equal hue and a higher lightness do not guarantee sufficient text contrast. Test the foreground and background together before adding the value as a token.
Input
A button uses HEX #3366CC; the design calls for a softer panel tint that still reads as blue.Output
Convert to HSL, raise lightness and reduce saturation for a candidate tint, then check the panel with its intended text color.Diagnose a link that disappears on a card
The same foreground can pass in one context and fail in another. Check the real rendered background, including transparency, and retain a non-color cue such as an underline for links.
Input
A link looks clear on the white page but becomes difficult to read on a light gray card.Output
Measure the link's contrast against the card background and choose a darker link color or a different surface.