Color Converter

Convert colors bidirectionally between HEX, RGB, HSL, and CMYK formats instantly. Built entirely offline in client-side memory.

Visual Picker
Click to pick a color
Invalid HEX format (use #RRGGBB or #RGB)
Invalid RGB format (use rgb(R, G, B) or R, G, B values 0-255)
Invalid HSL format (use hsl(H, S%, L%) or H, S, L values)
Invalid CMYK format (use cmyk(C%, M%, Y%, K%) or C, M, Y, K values)
Comprehensive Developer Guide Modern CSS Layout & Color Spaces Guide

Explore the underlying mathematics, RFC specifications, and production best practices in our deep-dive tutorial.

Read Guide →

Color Space Mathematics: HEX, RGB, HSL & CMYK

A color space is a mathematical model describing the way colors can be represented as tuples of numbers. In graphic design, UI engineering, and print production, working across multiple digital and physical media requires continuous conversion between additive and subtractive color spaces.

The primary color spaces supported in modern design include:

Our Color Converter translates colors across all spaces simultaneously, calculating WCAG contrast ratios and one-click CSS code copies.

Programmatic Color Space Conversion in JavaScript

// Convert HEX to RGB
function hexToRgb(hex) {
  const cleanHex = hex.replace(/^#/, '');
  const num = parseInt(cleanHex, 16);
  return {
    r: (num >> 16) & 255,
    g: (num >> 8) & 255,
    b: num & 255
  };
}

// Convert RGB to HSL
function rgbToHsl(r, g, b) {
  r /= 255; g /= 255; b /= 255;
  const max = Math.max(r, g, b), min = Math.min(r, g, b);
  let h, s, l = (max + min) / 2;

  if (max === min) {
    h = s = 0; // achromatic
  } else {
    const d = max - min;
    s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
    switch (max) {
      case r: h = (g - b) / d + (g < b ? 6 : 0); break;
      case g: h = (b - r) / d + 2; break;
      case b: h = (r - g) / d + 4; break;
    }
    h /= 6;
  }
  return { h: Math.round(h * 360), s: Math.round(s * 100), l: Math.round(l * 100) };
}

console.log(hexToRgb("#6366F1")); // { r: 99, g: 102, b: 241 }
console.log(rgbToHsl(99, 102, 241)); // { h: 239, s: 84, l: 67 }

WCAG 2.1 Color Contrast & Accessibility Standards

Web Content Accessibility Guidelines (WCAG) 2.1 establish strict minimum color contrast ratios between text and background to ensure readability for users with low vision or color blindness:

Next-Gen CSS Color Spaces: OKLCH & Display P3

CSS Color Module Level 4 introduces modern perceptual spaces like OKLCH and Display P3. OKLCH fixes long-standing visual luminance bugs in HSL, ensuring that colors with identical lightness values appear equally bright to human eyes across all hues.

CIE Lab, sRGB Gamut Clipping & Modern CSS OKLCH Perceptual Uniformity

Digital color displays historically operated within the legacy sRGB color space, designed around the cathode ray tube phosphors of the 1990s. While Hex and RGB formats represent color channels as 8-bit integers (0 to 255), they suffer from perceptual non-uniformity: changing the green channel by 20 units creates a vastly larger perceived brightness shift than changing the blue channel by 20 units.

Modern CSS Color Module Level 4 introduces OKLCH (Lightness, Chroma, Hue), which aligns color coordinates directly with human vision. In OKLCH, colors with identical Lightness values (e.g. L: 0.7) appear equally luminous to the human eye regardless of hue, revolutionizing algorithmic accessible UI theme generation and high-gamut Display P3 monitor support.

Color Space Conversion Coordinate Math

  • HEX to RGB: Bitwise mask extraction ((hex >> 16) & 255 for Red, (hex >> 8) & 255 for Green, hex & 255 for Blue).
  • RGB to HSL: Derives cylindrical coordinates by calculating min/max channel delta, normalizing Lightness to (max + min) / 2.
  • CMYK Printing Subtraction: Converts additive RGB light into subtractive printing inks using cyan, magenta, yellow, and black key extraction formulas.

Frequently Asked Questions

RGB is an emissive light model with a wide gamut of bright neon colors. CMYK is a reflective ink model with a narrower physical color gamut; some vivid RGB colors cannot be physically reproduced with printing inks.

The alpha channel specifies opacity, ranging from 0.0 (completely transparent) to 1.0 (completely opaque).

With HSL, keep the Hue and Saturation identical, and simply reduce the Lightness percentage by 10% to 15% (e.g. hsl(240, 80%, 50%) becomes hsl(240, 80%, 40%)).

Yes. Shorthand hex codes are automatically expanded to full 6-digit representations (#ffffff).

Yes. All transformations are computed locally using client-side JavaScript.