# Color Converter

> Paste one color code and read it in HEX, RGB, HSL, HSV and CMYK at once, with the working shown, e.g. rgb(255, 87, 51) becomes #FF5733.

Use it online (free, runs in your browser): https://directory.milunir.com/color-tools/color-converters/color-converter/

Paste a color code in any of five notations and the converter writes it in the other four. rgb(255, 87, 51) becomes #FF5733, hsl(11, 100%, 60%), hsv(11, 80%, 100%) and plain cmyk(0%, 66%, 80%, 0%). The steps show each base-16 pair and the max and min channels used for hue.

A brand color rarely arrives in the notation you need: a style guide gives #1A73E8, a CSS file uses hsl(), Photoshop shows HSB, and a print brief asks for CMYK. This converter reads whichever code you paste, detects the notation from its prefix, and prints the same color in HEX, RGB, HSL, HSV and CMYK, with the arithmetic behind each figure. A short list of hue-rotated matches comes with it, each HEX ready to copy. The CMYK line is the naive device-independent split (K = 1 − brightest channel); it ignores ink, paper and ICC profiles, so a printer working from a FOGRA or GRACoL profile will quote different percentages for the same swatch.

## How to use

1. **Paste a code**: Type #663399, #F53, rgb(102, 51, 153), hsl(270, 50%, 40%), hsv(…) or cmyk(…); the prefix tells the converter which notation it is.
2. **Read the other notations**: HEX is the headline, RGB and HSL sit under it, and the steps list HSV and CMYK with the working.
3. **Optionally pick matching colours**: Choose complementary, analogous, triadic, split complementary or square to list hue-shifted partners with a copy button on each HEX.

## Examples

### Purple #663399 and its complement

- Colour code: #663399
- Matching colours: Complementary

Result: HEX code: #663399 RGB: rgb(102, 51, 153) HSL: hsl(270, 50%, 40%)

The CSS named colour rebeccapurple sits at 270° on the wheel; its complement is the olive green at 90°.

### An orange typed as RGB, triadic scheme

- Colour code: rgb(255, 87, 51)
- Matching colours: Triadic

Result: HEX code: #FF5733 RGB: rgb(255, 87, 51) HSL: hsl(11, 100%, 60%)

The RGB triple becomes #FF5733, and the triadic scheme adds two colours 120° and 240° further round the wheel.

### CSS green from HSL to CMYK

- Colour code: hsl(120, 100%, 25%)
- Matching colours: Analogous

Result: HEX code: #008000 RGB: rgb(0, 128, 0) HSL: hsl(120, 100%, 25%)

hsl(120, 100%, 25%) is the CSS keyword green; on a plain conversion it needs full cyan and yellow with half black.

## How it works

`L = (max + min) ÷ 2; S = (max − min) ÷ (1 − |2L − 1|); K = 1 − max; partner hue = base hue + 30°, 90°, 120°, 150°, 180°, 210° or 270°`

- `max, min`: largest and smallest of the red, green and blue channels, scaled 0 to 1
- `K`: the black share in plain CMYK; C, M, Y are then (1 − channel − K) ÷ (1 − K)

HEX writes the red, green and blue bytes in base 16, two digits each. HSL and HSV follow the CSS Color Module Level 4 algorithm: hue is 60° times the position of the strongest channel relative to the others, lightness is the midpoint of max and min, and value is simply max. Going back from HSL or HSV to RGB reverses those steps, and CMYK to RGB is R = 255 × (1 − C) × (1 − K). Matching colours keep saturation and lightness and only add an angle to the hue.

Sources:

- [CSS Color Module Level 4](https://www.w3.org/TR/css-color-4/), W3C

## When not to use it

- Do not hand the CMYK percentages to a press as final; ask for a profile-based conversion.
- It does not match codes to Pantone, PMS or RAL books; those are licensed swatch lists, not formulas.
- It reads typed codes only and cannot sample a color from an image or PDF.

## Common mistakes

- Confusing HSL with HSV: hsl(0, 100%, 50%) and hsv(0, 100%, 100%) are the same red.
- Dropping a digit, so #08000 is rejected instead of read as #008000.
- Typing RGB channels as percentages; each channel here runs 0 to 255.

## Questions

### What is the formula to convert RGB to hex?

Write each channel, 0 to 255, as a two-digit base-16 number and join them after a #. For rgb(255, 87, 51): 255 ÷ 16 = 15 remainder 15, so FF; 87 = 5 × 16 + 7, so 57; 51 = 3 × 16 + 3, so 33. The result is #FF5733.

### What is the HSL to RGB formula?

Compute chroma C = (1 − |2L − 1|) × S, then X = C × (1 − |(H ÷ 60) mod 2 − 1|) and m = L − C ÷ 2. Pick the (C, X, 0) order for the hue's 60° sector, add m to each, and multiply by 255. hsl(120, 100%, 25%) gives C = 0.5, m = 0, so rgb(0, 128, 0).

### How do you convert hex to HSL by hand?

First turn the hex pairs into RGB and divide by 255. Lightness is (max + min) ÷ 2, saturation is (max − min) ÷ (1 − |2L − 1|), and hue depends on which channel is largest. #663399 gives max 0.6 (blue), min 0.2, so L = 40%, S = 50% and hue 270°.

### What is the CMYK to RGB formula?

Each channel is 255 × (1 − ink) × (1 − K), with inks as fractions. cmyk(0, 66, 80, 0) gives R = 255, G = 255 × 0.34 = 87 and B = 255 × 0.2 = 51, so rgb(255, 87, 51). This is the naive formula; profile-managed software such as Illustrator or InDesign can return slightly different values.

### How do I convert CMYK to a hex code?

Convert CMYK to RGB first with 255 × (1 − ink) × (1 − K), then write each channel in base 16. cmyk(100%, 0%, 100%, 50%) becomes rgb(0, 128, 0) and therefore #008000. Paste the cmyk() code and the converter does both steps and shows them.

### How do I convert hex to HSV?

Read the hex as RGB fractions. Value is the largest channel, saturation is (max − min) ÷ max, and hue uses the same rule as HSL. #FF5733 has max 1 and min 0.2, so V = 100%, S = 80% and hue about 11°: hsv(11, 80%, 100%). Photoshop calls this HSB.

### Can I convert CMYK to Pantone with a formula?

No. Pantone (PMS) colors are a licensed set of physical ink swatches, so there is no equation from CMYK to a Pantone number; matching needs Pantone's own guides or software. This converter covers the five open notations: HEX, RGB, HSL, HSV and CMYK.

## Use from code or an AI agent

Free JSON API, no key needed. The answer is in `result.stats.primary`.

```bash
curl -X POST https://api.tools-directory.workers.dev/v1/tools/color-converter \
  -H 'Content-Type: application/json' \
  -d '{"inputs":{"color":"#663399","harmony":"complementary"}}'
```

- Inputs (JSON Schema): https://directory.milunir.com/api/v1/tools/color-converter.json
- MCP server: https://api.tools-directory.workers.dev/mcp (tool `color_converter`)
- Docs: https://directory.milunir.com/docs/
