On this page
A colour can have several equally valid CSS spellings. The problem is rarely choosing the fashionable one; it is preserving the same colour while moving between design files, browser styles, and application settings. A reliable conversion workflow separates the underlying channels from the notation used to write them.
Start with one known colour
Paste a representative value into the colour converter, then compare its HEX, RGB, and HSL outputs. Use a medium blue such as #336699 rather than white or black, because coloured samples make channel mistakes easier to notice. Record the original alongside the converted value before editing anything.
HEX and RGB usually describe the same sRGB channel values in different notation. HEX encodes those channels with hexadecimal digits; RGB writes them as numbers or percentages. HSL expresses that same space through hue, saturation, and lightness. Changing notation alone does not expand the available gamut or improve visual quality.
Choose one canonical source for each stored colour. If developers copy HEX from one document and independently rounded HSL from another, small differences can accumulate. Keep original precision in the source and format values only when exporting them into a stylesheet or interface.
A useful test sheet has three identical rectangles, each using a different notation. Put them on the same neutral background without shadows or transparency. They should look identical when the conversions describe the same sRGB colour.
Decode HEX and RGB without guessing
A six-digit HEX value contains three pairs: red, green, and blue. Each pair runs from 00 to FF, equivalent to decimal 0 through 255. For #336699, those values are 51, 102, and 153. The shorthand #369 expands to #336699, not #030609 or a rounded approximation.
Eight-digit HEX adds alpha at the end. In #33669980, the final 80 means approximately 50.2% opacity, because 128 divided by 255 is slightly above one half. This ordering differs from formats that place alpha first. Never paste an eight-digit value between systems without checking the documented order.
The MDN HEX reference explains the supported lengths. For application settings, explicitly document whether a field accepts six digits, eight digits, or both. A label saying only “colour code” leaves too much room for incompatible assumptions.
Channel rounding matters at boundaries. A percentage RGB channel is converted relative to 255, not 100. If you round every intermediate result, a conversion round trip can return a neighbouring channel value. Keep calculation precision until the final display or serialized output.
Understand what HSL actually changes
HSL hue describes an angle around a colour wheel. Zero degrees is red, 120 degrees green, and 240 degrees blue. Saturation controls distance from grey within the HSL model; lightness runs from black through the colour to white. These controls make quick edits convenient, but they do not model human perception uniformly.
Two colours at 50% HSL lightness can have very different apparent brightness. Yellow often appears much brighter than blue at the same numerical setting. Consequently, equal lightness values are not a dependable way to make a balanced family of swatches. Use visual comparison and measured contrast for the actual role.
At zero saturation, hue has no visible effect. At zero or 100% lightness, saturation also stops changing the result. A converter may therefore return a different hue for grey without changing its appearance. Treat those coordinates as ambiguous rather than evidence of a broken conversion.
Read the MDN HSL documentation before building an editor around these controls. Decide how your interface handles hue wrapping, percentage units, and missing values, rather than letting separate components make inconsistent choices.
Write modern CSS consistently
Modern functional syntax separates channels with spaces and puts alpha after a slash. Legacy comma-separated syntax remains common, but consistency makes code reviews easier. The following declarations represent the same opaque colour, followed by a translucent variation:
.sample {
color: #336699;
border-color: rgb(51 102 153);
background-color: hsl(210 50% 40% / 20%);
}The background is deliberately not identical in appearance to the text: its alpha allows the backdrop to contribute. Alpha is not lightness, and a transparent blue over white does not equal the same transparent blue over grey. Preview the real surface before approving a converted colour.
For reusable values, store a complete CSS colour in a custom property unless your application explicitly needs separate channels. Splitting channels can help with older composition techniques, but it also couples every consumer to a particular colour model. A whole value is easier to replace later.
The CSS Color specification is the authoritative reference for syntax and conversion definitions. Use it to settle parsing questions; use a browser and a controlled comparison page to investigate rendering differences that are not explained by syntax alone.
Verify the conversion in its real context
After checking numerical equivalence, test the colour where people will actually see it. A blue link on white, a blue chart line on cream, and a translucent blue badge can require different treatment even if they share an original brand value. Conversion should preserve intent, not conceal a needed design decision.
Use the contrast checker to compare foreground and background pairs after any rounding or alpha compositing. Do not assume that preserving hue preserves legibility. A small numerical change can matter when a pair is already close to a required threshold.
When handing colours to another developer, include notation, alpha, and role together: for example, “opaque action foreground, #336699.” Avoid screenshots as the sole source of truth; compression, display settings, and sampling positions can all introduce ambiguity. Keep a machine-readable value beside the preview.
For a broader implementation approach, connect the approved values to semantic design tokens. The important distinction is between changing how a colour is written and changing what a colour means. Review those operations separately so a harmless format cleanup does not accidentally become a visual redesign.
Key takeaways
- Convert notation, not the intended appearance, when moving between HEX, RGB, and HSL.
- Preserve calculation precision and document eight-digit alpha ordering.
- Treat HSL lightness as a model coordinate, not perceived brightness.
- Compare transparent colours on their actual backgrounds.
- Store an authoritative value with its intended role and verify the exported result.
Reach designers & developers at work
Put your product next to the tools people use every day. One sponsor per placement, no tracking pixels.
Become a sponsor