🎨 Color Converter
Convert between HEX, RGB, and HSL color formats with live preview. Runs entirely in your browser.
Understanding CSS Color Formats – HEX vs RGB vs HSL
Colors on the web are represented in several formats. Each has advantages depending on your use case. Understanding when to use HEX, RGB, or HSL helps you write cleaner CSS and communicate colors effectively with designers and design tools.
HEX Color Codes Explained
A HEX color code is a 6-digit hexadecimal number prefixed with #, for example #4f46e5. Each pair of digits represents Red, Green, and Blue channel intensity from 00 (0) to FF (255). HEX is the most common color format in CSS, design tools (Figma, Sketch, Photoshop), and brand guidelines. Shorthand like #fff expands to #ffffff. HEX with alpha: #4f46e580 (8-digit HEX).
RGB and RGBA Color Values
RGB defines colors using Red, Green, and Blue channel values from 0 to 255: rgb(79, 70, 229). RGBA adds an alpha channel for opacity: rgba(79, 70, 229, 0.5). RGB is useful when you need to programmatically adjust individual channels — for example, lightening a color by increasing all three values proportionally.
HSL and HSLA Color Values
HSL represents colors as Hue (0–360° on the color wheel), Saturation (0–100%), and Lightness (0–100%): hsl(244, 76%, 59%). HSL is the most intuitive format for humans — you can easily create color variations by adjusting saturation or lightness while keeping the hue constant. This makes HSL ideal for building color palettes, theming systems, and CSS custom properties.
When to Use Each Color Format
- HEX — Best for static color values, brand colors, and sharing with designers. Universal support in all browsers and design tools.
- RGB/RGBA — Best when you need alpha transparency or programmatic color manipulation in JavaScript.
- HSL/HSLA — Best for CSS theming, generating color variations (light/dark modes), and creating harmonious palettes. Easily adjust lightness for hover states:
hsl(244, 76%, 69%).
Color Conversion Formulas
Converting between HEX and RGB is straightforward (parse hex pairs into decimal). Converting between RGB and HSL involves calculating the hue from min/max channel values, saturation from the chroma, and lightness as the midpoint between min and max. This tool handles all conversions instantly with live preview.