正在加载,请稍候…

Color Formats Explained: HEX, RGB, HSL, and How to Convert Between Them

Learn about web color formats: HEX, RGB, RGBA, HSL, HSLA — and how to convert between them instantly with our free online color converter tool.

Color Models and Why We Convert Between Them

Color can be represented in multiple mathematical models, each optimized for different use cases. Converting between models is essential for web development, graphic design, print production, and data visualization.

The Main Color Models

RGB (Red, Green, Blue)

The additive color model used by screens. Colors are created by mixing light:

  • Range: Each channel 0-255 (8-bit) or 0-100%
  • Used in: CSS, HTML, JavaScript, image files
  • Example: rgb(255, 87, 51) = a vivid orange

RGB maps directly to how monitors work — each pixel has red, green, and blue subpixels whose intensities combine to create the perceived color.

HEX (Hexadecimal)

A compact representation of RGB using base-16:

  • Format: #RRGGBB where each pair is 00-FF
  • Shorthand: #RGB when both digits are identical (#FF6600 = #F60)
  • Used in: CSS, HTML, design tools, SVG
  • Example: #FF5733 = rgb(255, 87, 51)

HSL (Hue, Saturation, Lightness)

More intuitive for humans to work with:

  • Hue: Color angle 0-360° (0=red, 120=green, 240=blue)
  • Saturation: 0% (gray) to 100% (full color)
  • Lightness: 0% (black) to 100% (white), 50% is "normal"
  • Used in: CSS (natively supported), design systems, color pickers

HSL shines for programmatically generating color variations — changing only lightness creates tints and shades without color shift.

HSV/HSB (Hue, Saturation, Value/Brightness)

Similar to HSL but used in most design software color pickers:

  • Value/Brightness: 0% (black) to 100% (pure color)
  • Used in: Photoshop, Illustrator, Figma color pickers

CMYK (Cyan, Magenta, Yellow, Key/Black)

The subtractive color model for print:

  • Range: Each component 0-100%
  • Used in: Print design, professional publishing
  • Note: RGB to CMYK conversion is not mathematically perfect — use ICC profiles for accurate print color

Lab (Lab*)

Perceptually uniform color space:

  • L: Lightness 0-100
  • a: Green to red axis (-128 to 127)
  • b: Blue to yellow axis (-128 to 127)
  • Used in: Color science, image processing, perceptual color differences

Conversion Formulas

HEX to RGB

Split the hex string into pairs, convert each from hex to decimal:

  • #FF5733 → R=255 (0xFF), G=87 (0x57), B=51 (0x33)

RGB to HSL

Convert each RGB value to 0-1 range, then calculate:

  • Find max and min values of R, G, B
  • Lightness = (max + min) / 2
  • Saturation depends on whether max equals min
  • Hue depends on which channel is maximum

RGB to CMYK

Convert RGB (0-255) to fractions (0-1), then:

  • K (black) = 1 - max(R, G, B)
  • C = (1 - R - K) / (1 - K)
  • M = (1 - G - K) / (1 - K)
  • Y = (1 - B - K) / (1 - K)

Color Spaces and Profiles

Beyond color models, color spaces define how a color model maps to actual physical colors:

  • sRGB: Standard for web and most consumer displays
  • Adobe RGB: Wider gamut for professional photography
  • P3/DCI-P3: Wide gamut for cinema and modern displays
  • CMYK profiles: Varies by printer, ink, and paper type

When designs move between web (sRGB) and print (CMYK), colors can shift noticeably. Soft-proofing in design software helps preview how colors will appear in print.

Using the Color Converter Tool

Our tool:

  1. Enter any color format — HEX, RGB, HSL, HSV, or CMYK
  2. See all representations — instantly converts to all other formats
  3. Visual color preview — see the actual color
  4. Copy any format — one-click copy in CSS-ready syntax
  5. Color picker integration — visually select colors
  6. Accessibility check — WCAG contrast ratios against white and black backgrounds

Use it for converting between design tool and CSS representations, preparing colors for print, and ensuring consistent color values across different parts of a project.