PureDevTools

Color Converter

Convert between HEX, RGB, and HSL — with real-time preview and WCAG contrast checking

All processing happens in your browser. No data is sent to any server.

Supports #RGB and #RRGGBB formats

Converted Values

HEX
#3b82f6
RGB
rgb(59, 130, 246)
HSL
hsl(217, 91%, 60%)

WCAG Contrast

vs White

3.68:1AA Large

vs Black

5.71:1AA

Understanding Color Formats in Web Development

Color representation is one of the most fundamental aspects of web and UI development. Browsers, design tools, and CSS all support multiple color formats — and knowing how to convert between them is a daily skill for developers and designers alike. This tool lets you convert between HEX, RGB, and HSL formats instantly in your browser.

HEX Color Codes

HEX (hexadecimal) is the most commonly recognized color format in web development. A HEX code like #3b82f6 consists of three pairs of base-16 digits representing the Red, Green, and Blue channels respectively.

HEX codes are used in CSS color properties, HTML attributes, design tokens, and SVG files. They are compact and universally supported.

RGB — Red, Green, Blue

RGB defines a color by specifying the intensity of its Red, Green, and Blue channels, each as an integer from 0 to 255. In CSS, RGB colors are written as rgb(59, 130, 246).

RGB is the native model for digital screens. Mixing all three channels at maximum (rgb(255, 255, 255)) produces white; setting all to zero produces black. RGB is additive — adding more light makes colors brighter.

When to use RGB over HEX: when your code needs to manipulate individual channels mathematically, such as creating color variations in JavaScript animations or generating dynamic palettes.

HSL — Hue, Saturation, Lightness

HSL is a human-friendly alternative to RGB that separates the concepts of hue, saturation, and lightness:

HSL is particularly useful for creating color palettes programmatically. Need a lighter version of a color? Increase the L value. Need a muted tone? Decrease S. This intuitive control makes HSL the preferred format in CSS design systems and component libraries.

How to Convert HEX to RGB

The conversion from HEX to RGB is straightforward:

  1. Remove the # prefix
  2. Split into three pairs: RR, GG, BB
  3. Parse each pair as a base-16 integer

For example: #ff5733 → R: 0xff = 255, G: 0x57 = 87, B: 0x33 = 51 → rgb(255, 87, 51)

How to Convert RGB to HSL

RGB to HSL involves normalizing channel values to the 0–1 range, then computing the lightness (average of max and min channels), saturation (based on the lightness and channel spread), and hue (angle derived from which channel is dominant).

The formula handles edge cases: when all channels are equal (grayscale), saturation is 0 and hue is undefined (set to 0°).

WCAG Contrast Ratio Checker

The Web Content Accessibility Guidelines (WCAG) define minimum contrast ratios between text and background colors to ensure readability for users with low vision:

LevelRatioUsage
AA≥ 4.5:1Normal text
AA Large≥ 3:1Large text (18pt+ or 14pt bold)
AAA≥ 7:1Enhanced accessibility

This tool calculates your color’s contrast ratio against both pure white (#ffffff) and pure black (#000000) using the WCAG relative luminance formula, helping you choose accessible text and background color combinations.

Frequently Asked Questions

What is the hex to rgb formula? Split the HEX code into three 2-character groups and convert each from base-16 to decimal. For example, #ff8800 → R: 255, G: 136, B: 0.

How do I convert RGB to hex in CSS? Use the rgb() function directly in CSS, or convert each channel to a 2-digit hex string and concatenate with a # prefix. This tool does the conversion instantly.

What does HSL stand for? Hue, Saturation, Lightness. It is a cylindrical color model that separates chromatic information (hue and saturation) from luminance (lightness), making it more intuitive for design work than RGB.

Is this color converter accurate? Yes. The conversion algorithms use standard mathematical formulas. HSL values are rounded to the nearest integer, which may introduce rounding differences of ±1 unit, consistent with how CSS engines handle rounding.

Does this tool send my colors to a server? No. All conversions happen entirely in your browser using JavaScript. No data is transmitted to any server.

Related Tools