Why the calculation is structured this way
RGB channels describe intensity coordinates; hexadecimal writes those byte values in base sixteen. HSL derives hue, saturation and lightness from channel extrema. Its lightness is not relative luminance for WCAG. When saturation is zero, visible hue is indeterminate and a formatter chooses a conventional number.
A second scenario you can verify
HEX #ff8000 has RGB channels 255, 128 and zero. With normalized extrema one and zero, HSL lightness is 50% and saturation 100%; hue is about 30.1176 degrees because the green byte is 128 rather than the exact half 127.5. Rounding hue to 30 is a display choice.
What changes the interpretation
Alpha compositing, wide-gamut profiles and CMYK printing need additional models. Two equally named HSL lightness values can have very different contrast on white. Inspect the actual foreground/background pair and do not infer accessibility from the swatch alone.
Check round trips without confusing notation with display fidelity
A round trip from HEX to RGB should preserve the exact integer channels for supported opaque colors. A round trip through a rounded HSL display can differ by a channel because hue, saturation or lightness was rounded. That is a presentation boundary, not proof that the original two notations identify different colors when represented at sufficient precision.
For pure green #00ff00, channels are zero, 255 and zero, giving HSL hue 120 degrees, saturation 100% and lightness 50%. For #808080, equal channels mean saturation zero and lightness about 50.196078%. A formatter can choose hue zero for that gray, but choosing 120 at zero saturation describes the same visible achromatic result. Hue is indeterminate there.
Hue wraps around the color circle. Zero degrees and 360 degrees identify the same red direction under a normalized hue convention, while saturation and lightness percentages have their own bounds. Converting an arbitrary CSS color string requires a declared parser scope. Unsupported alpha, named profiles or printing values should not silently become a guessed opaque color.
Contrast requires a foreground/background pair and a luminance model. HSL lightness is not the luminance used by WCAG, and a conversion cannot determine whether text is readable simply by seeing that lightness is fifty percent. Test the actual combination, font and states rather than relying on a favorable-looking swatch.
Display calibration, gamut and lighting can affect physical appearance after the numerical value is converted. Printing introduces ink and profile considerations beyond RGB notation. Save the source value and the chosen precision so a conversion is reproducible, but do not describe that reproducibility as a guarantee of identical appearance on every screen or a print color match.
Input reference and units
These values reproduce the model’s demonstration. Replace them with your own records or measurements; they are not recommended targets.
On a small screen, swipe horizontally to see all columns. With a keyboard, focus the table and use the arrow keys.
| Parameter | Demonstration value | How to enter it |
|---|---|---|
| HEX or RGB color | #0080FF | Enter hex or rgb color without adding a unit suffix. Scope: Accepts #RGB, #RRGGBB, integer rgb(r,g,b), and comma-separated hsl(h,s%,l%); HSL supports signed degree hues. |
Color Code Converter: calculation relationships
Convert HEX, RGB or HSL notation into all three formats. HSL hue wraps around 360 degrees; saturation and lightness are percentages, and RGB output rounds to 8-bit channels. Accepts #RGB, #RRGGBB, integer rgb(r,g,b), and comma-separated hsl(h,s%,l%); HSL supports signed degree hues. HSL conversion rounds to 8-bit sRGB channels; alpha, CSS color profiles, percent RGB and modern space/slash syntax are outside this parser.
Hex pairs encode RGB channel integers from 0 to 255. #FF8000 becomes rgb(255,128,0); short #f80 instead expands to #FF8800, not #FF8000. HSL describes hue, saturation and lightness for the same channels, with hue undefined for a neutral gray and shown as zero by convention. Alpha and color-profile conversion are outside this parser. HSL input is also accepted: hsl(120,100%,50%) becomes #00FF00. Hue is wrapped by 360 degrees; saturation and lightness must stay in 0–100%, and RGB channels are rounded to integers.
hex = base16(R,G,B); HSL = hue, saturation and lightness from normalized RGB
- value: HEX or RGB color. Enter hex or rgb color without adding a unit suffix. Scope: Accepts #RGB, #RRGGBB, integer rgb(r,g,b), and comma-separated hsl(h,s%,l%); HSL supports signed degree hues.
- Result units: stated beside each output
- Calculation relationship: hex = base16(R,G,B); HSL = hue, saturation and lightness from normalized RGB
- Supported domain: see the limits below
Worked example
Color Code Converter baseline input: HEX or RGB color: #0080FF. Output: HEX = #0080FF; RGB = rgb(0, 128, 255); HSL = hsl(209.88, 100.00%, 50.00%). Substitute these values into the displayed equation to reproduce the result.
Reproduce the default scenario
This reproduces the default inputs in the reference table above; it is not an additional independent example. Displayed rounding may differ from intermediate precision.
- HEX
- #0080FF
- RGB
- rgb(0, 128, 255)
- HSL
- hsl(209.88, 100.00%, 50.00%)
Common questions and boundary checks
Does #abc equal #aabbcc?
Yes. Each short-HEX digit expands by repetition.
Can I enter HSL?
Yes within the supported opaque HSL syntax and bounds.
Is HSL lightness WCAG luminance?
No. Contrast requires a different linearized-sRGB calculation.
Why does gray show a hue number?
At zero saturation hue is indeterminate; the formatter supplies a convention.
Does this produce a print color match?
No. Printing profiles and ink models are separate from opaque sRGB notation.
Sources and content notes
Toolify describes the implemented algorithm and its assumptions. Sources below support the topic or applicable rules; they do not endorse this calculator. Examples are illustrative, and published rules take precedence over simplified estimates.
Report a formula, example or translation issue through our contact page. Include the tool name, inputs and expected result so it can be reproduced. Contact Toolify