Color Code Converter: RGB, HEX, HSL, CMYK

HEX
RGB
HSL
CMYK

Color Code Converter: RGB, HEX, HSL, CMYK

What is Color Code Conversion?

Color code conversion is the process of transforming color representations between different color models. Each model represents colors in a unique way, and converting between them allows for versatile color manipulation across various applications.

Color Models

This converter supports four popular color models:

  • RGB (Red, Green, Blue): Additive color model used in digital displays.
  • HEX: Hexadecimal representation of RGB, commonly used in web design.
  • HSL (Hue, Saturation, Lightness): Intuitive model for adjusting color properties.
  • CMYK (Cyan, Magenta, Yellow, Key/Black): Subtractive color model used in printing.

Conversion Formulas

The conversion between these color models involves various mathematical formulas. Here are simplified examples:

RGB to HEX:

\[ \text{HEX} = \text{#RRGGBB} \]

Where RR, GG, and BB are two-digit hexadecimal values for each component.

RGB to HSL:

\[ H = \text{arctan2}(\sqrt{3}(G-B), 2R-G-B) \]

\[ S = \frac{\max(R,G,B) - \min(R,G,B)}{\max(R,G,B)} \]

\[ L = \frac{\max(R,G,B) + \min(R,G,B)}{2} \]

RGB to CMYK:

\[ K = 1 - \max(R,G,B) \]

\[ C = \frac{1-R-K}{1-K} \]

\[ M = \frac{1-G-K}{1-K} \]

\[ Y = \frac{1-B-K}{1-K} \]

Usage Example

Let's convert the color red across different models:

  • RGB: (255, 0, 0)
  • HEX: #FF0000
  • HSL: (0°, 100%, 50%)
  • CMYK: (0%, 100%, 100%, 0%)

Visual Representation

RGB HEX

This diagram shows the color red represented in RGB and HEX formats. The HSL and CMYK representations would visually appear the same, as they all describe the same color.