Color Converter
Convert colors between HEX, RGB, HSL, and HSV with a live preview.
What this tool does
Color values in digital design are expressed in multiple formats: HEX (hexadecimal RGB), RGB (red, green, blue channels 0-255), HSL (hue, saturation, lightness), and HSV (hue, saturation, value). This tool converts between all these formats in real time, with a live preview swatch so you can see the exact color you are working with.
HEX is the most common format in CSS and web design, with three or six hex digits representing the RGB channels. RGB is the native format for screens and image files. HSL and HSV are more intuitive for humans because they separate the hue (the actual color) from the saturation and lightness/value, making it easier to create color variations and harmonies.
Usage Example
/* Same color in different formats */
:root {
--primary: #10B981; /* HEX */
--primary: rgb(16, 185, 129); /* RGB */
--primary: hsl(160, 84%, 39%); /* HSL */
}
/* HEX with alpha (8 digits) */
--primary-50: #10B98180; /* 50% opacity */
/* Modern CSS color() function */
--primary: color(display-p3 0.06 0.73 0.51); /* Wide gamut */Common Edge Cases
- The 3-digit HEX shorthand (#RGB) expands to 6 digits by duplicating each digit: #FA3 becomes #FFAA33. Use this shorthand only for designer-friendly values, not in code that may be parsed by tools.
- HSL hue is a degree on the color wheel (0-360), while saturation and lightness are percentages. Hue values outside 0-360 wrap around, so 400 is equivalent to 40.
- RGBA and HSLA have an alpha channel (0 = transparent, 1 = opaque). The 8-digit HEX format (#RRGGBBAA) is now widely supported and is the recommended approach in modern CSS.
- sRGB is the default color space for most displays, but newer wide-gamut displays support P3 and Rec.2020. The CSS color() function allows specifying colors in any color space.
- Converting between color spaces (sRGB, linear, P3) requires gamma correction. The naive formula (R/255) is incorrect for color math; use proper gamma functions for blending and interpolation.
FAQ
- Which color format should I use?
- Use HEX for most CSS because it is compact and well-supported. Use RGB or HSL when you need to manipulate individual channels in JavaScript. Use HSL for design tools because it is more intuitive for creating color variations.
- What is the difference between HSL and HSV?
- HSL (Hue, Saturation, Lightness) treats white and black as the extremes of lightness, producing vivid colors in the middle. HSV (Hue, Saturation, Value) treats black as the minimum value, producing vivid colors at the top. HSL is more common in CSS; HSV is more common in design tools like Photoshop.
- How do I ensure color accessibility?
- Use the WCAG contrast ratio formula: (L1 + 0.05) / (L2 + 0.05) where L is the relative luminance. Text needs 4.5:1 for normal text and 3:1 for large text. Use a contrast checker tool before shipping.