How HSV to HEX conversion works
An HSV colour comes from a picker: a hue around the wheel, saturation across the square, value up the square. To turn it into a HEX code you rebuild the three channels: value sets the brightest one, saturation sets how far the dimmest one drops, and hue places the middle one.
- Scale S and V to 0–1.
- C = V × S; X = C × (1 − |(H ÷ 60) mod 2 − 1|); m = V − C.
- Pick (R′, G′, B′) by 60° sector, add m, multiply by 255 and round.
- Write each channel as two HEX digits.
Worked example: hsv(45, 100%, 100%) to HEX
Here is the converter's own calculation for hsv(45, 100%, 100%), step by step. The result, #FFBF00, is exactly what the tool above shows for this input.
- Chroma C = 1 × 1 = 1.
- X = 1 × (1 − |(45 ÷ 60) mod 2 − 1|) = 0.75.
- m = 1 − 1 = 0.
- 45° is in the 0–60° sector, so (R′, G′, B′) = (C, X, 0) = (1, 0.75, 0).
- Add m and multiply by 255: R = 255, G = 191, B = 0.
- Red 255 = 15 × 16 + 15 → FF; green 191 = 11 × 16 + 15 → BF; blue 0 = 0 × 16 + 0 → 00.
- Joined:
#FFBF00.
A value ramp in HSV and HEX
Hue 45° at full saturation, value stepping down from 100% to 20%.
| Colour | HSV | HEX |
|---|---|---|
| V 100% | hsv(45, 100%, 100%) | #FFBF00 |
| V 90% | hsv(45, 100%, 90%) | #E6AC00 |
| V 80% | hsv(45, 100%, 80%) | #CC9900 |
| V 70% | hsv(45, 100%, 70%) | #B38600 |
| V 60% | hsv(45, 100%, 60%) | #997300 |
| V 50% | hsv(45, 100%, 50%) | #806000 |
| V 40% | hsv(45, 100%, 40%) | #664D00 |
| V 30% | hsv(45, 100%, 30%) | #4D3900 |
| V 20% | hsv(45, 100%, 20%) | #332600 |
Precision test: every HSV value through the converter
Every whole-number HSV value becomes a HEX code that converts back to the same colour (100% of 3,672,360). They produce 2,193,881 distinct codes, about 13% of all HEX colours, so if you need one specific HEX code, pick it in HEX rather than via HSV.
Method: every whole-number HSV value, through the converter's own code and back, compared on the 0–255 scale (how we test).
| Measure | Result |
|---|---|
| HSV values tested | 3,672,360 |
| Distinct HEX results | 2,193,881 |
| Came back exactly | 100% |
| Largest change (0–255 levels) | 0 |
| Average change | 0 |
Last updated · Source: Pixohub exhaustive test of lib/color-math.ts
Where you'll use HSV to HEX
Handing picker colours to developers
Designers often read H, S and B from Photoshop or Procreate. Developers need HEX for CSS and design tokens, and this conversion gives exactly the colour the picker showed.
Generating a value scale
Holding hue and saturation and lowering V produces darker shades of the same colour, as in the value ramp below. These are darker but not greyer, unlike lowering HSL lightness past 50%.
Writing colour constants in code
Even if your colour logic is HSV-based, config files and CSS expect HEX.
Common mistakes
- Typing HSB values from Photoshop into an HSL field: the colour will change.
- Forgetting that V = 0% is always black, whatever H and S are.
- Rounding before the final step, which can shift the HEX by one in a channel.
- Expecting the HEX to round-trip to the same HSV: some HEX codes come back as a neighbouring HSV value.