Color Converter
Convert colors between HEX, RGB, RGBA, HSL, and preview contrast.
Client-Side Execution & Privacy Guarantee
This utility executes 100% locally in your web browser. Your inputs, tokens, queries, and data payloads are never transmitted to any external server or backend.
Design and development tools use several notations for the same color. HEX is compact for style sheets, RGB and RGBA expose the channel values used by graphics APIs, and HSL separates hue from saturation and lightness so adjustments stay intuitive.
The converter accepts any of these forms and produces the others together with a contrast preview against black and white. Conversions follow the standard sRGB formulas published in the CSS Color Module, so results match what browsers compute.
HEX and RGB
A six-digit HEX color #RRGGBB encodes each channel as two hexadecimal digits. Conversion to RGB is direct: interpret each pair as an integer in the range 0–255. Three-digit shorthand #RGB expands by doubling each digit. Eight-digit HEX appends an alpha channel.
RGB notation rgb(r, g, b) or the modern space-separated form rgb(r g b) uses the same 0–255 integers. Percentage values are accepted and scaled by 2.55. RGBA adds a fourth alpha component in the range 0–1 or as a percentage.
HSL conversion
HSL represents hue as an angle 0–360°, saturation and lightness as percentages. To convert from RGB, normalize the channels to 0–1, compute max and min, then lightness = (max + min) / 2. Saturation is (max – min) / (1 – |2L – 1|) when max ≠ min, otherwise 0. Hue is derived from the channel that holds the maximum.
The reverse conversion computes chroma, an intermediate X value, and a match value, then adds the lightness offset. Rounding to the nearest integer for the RGB channels is performed only at the final step so intermediate precision is retained.
Contrast preview
Relative luminance is calculated from the sRGB channels after gamma expansion. The contrast ratio against black or white is (L1 + 0.05) / (L2 + 0.05) where L1 is the lighter luminance. Ratios of 4.5:1 and 7:1 are the common WCAG AA and AAA thresholds for normal text.
The preview is informational; it does not replace a full accessibility audit that also considers font size, weight, and surrounding colors. Alpha is ignored for the contrast calculation unless you composite the color against an explicit background first.
When to use this tool
- You have a HEX value from a design tool and need the corresponding RGB or HSL for code.
- You want to adjust lightness or saturation and see the HEX that results.
- You need a quick contrast check of a foreground color against black or white.
- You are converting between the notations required by different CSS or graphics libraries.
- You received an RGBA value and need the opaque HEX equivalent after compositing.
How to use the Color Converter
- Enter a color in any supported notation: #RGB, #RRGGBB, #RRGGBBAA, rgb(), rgba(), hsl(), or hsla().
- The other notations update immediately.
- Inspect the contrast ratios shown against black and white.
- Copy the format you need for your style sheet or API call.
- For alpha colors, note that contrast is computed on the opaque equivalent unless a background is supplied.
- Use the HSL form when you want to create lighter or darker variants by changing only the lightness component.
- Verify the final HEX in the target environment; minor rounding differences can appear with very high-precision source values.
Worked examples
HEX to RGB and HSL
#3A7CA5
rgb(58, 124, 165) hsl(203, 48%, 44%)
58 = 0x3A, 124 = 0x7C, 165 = 0xA5. Hue falls in the blue range.
RGB to HEX
rgb(255, 99, 71)
#FF6347
Classic tomato red. Each channel converts directly to two hex digits.
Common mistakes and tips
- Three-digit HEX is exactly equivalent to the six-digit form with doubled digits; #abc is #aabbcc.
- HSL lightness is not perceptual lightness; a yellow and a blue with the same L value do not appear equally bright.
- When copying RGBA into a context that expects opaque color, composite against the intended background first.
- Contrast ratios are most meaningful for text; large bold text may pass AA at 3:1.
- Browser and design-tool HEX values are usually sRGB; conversions assume that color space.
Frequently asked questions
Why do HSL values sometimes differ by one percent from another tool?
Rounding of the final saturation or lightness percentage can differ by one unit depending on whether the implementation rounds half away from zero or to even. The underlying channel values remain identical.
Does the converter support OKLCH or other modern spaces?
No. Only HEX, RGB/RGBA, and HSL/HSLA are converted.
How is alpha handled in contrast calculations?
Alpha is ignored unless you first composite the color over a solid background. The preview therefore shows the contrast of the fully opaque color.
Can I enter a CSS color name?
Named colors are not accepted; supply a HEX, RGB, or HSL value.
Are the formulas identical to those in CSS Color Level 4?
Yes. RGB–HSL conversion follows the algorithms given in the CSS Color Module.