StringMash.com

HSV to RGB converter

Hue, saturation and value to rgb(), with the working.

Conversion
11 characters
Updates as you type
Hex#3366CC
RGBrgb(51, 102, 204)
HSLhsl(220, 60%, 50%)
HSV (HSB)hsv(220, 75%, 80%)
CMYKcmyk(75%, 50%, 0%, 20%)
Nearest CSS nameroyalblue
Contrast with white5.37:1 (AA)
Contrast with black3.91:1 (AA large text only)
The swatch and working are below

Show the steps
Aa blackAa white
  1. Write saturation and value as fractions: S = 0.75, V = 0.8. The hue is H = 220°.
  2. Chroma: C = V × S = 0.8 × 0.75 = 0.6.
  3. X = C × (1 − |(H ÷ 60) mod 2 − 1|) = 0.6 × 0.333 = 0.2.
  4. m = V − C = 0.8 − 0.6 = 0.2.
  5. H ÷ 60 = 3.667, which is from 3 to 4, so red, green and blue start as (0, X, C) = (0, 0.2, 0.6).
  6. Add m to each and multiply by 255: red 51, green 102, blue 204. Rounded, rgb(51, 102, 204).
  7. Contrast: 5.37:1 against white and 3.91:1 against black, so white text reads better on it.

Using the converter

Type the hue in degrees and the saturation and value as percentages, such as 220, 75, 80. Percent and degree signs are optional, and hsv(220, 75%, 80%) or hsb(220, 75%, 80%) work too.

The answer is an rgb() value. The rows give the hex code and the same colour in HSL and CMYK.

The HSV to RGB formula

Write saturation S and value V as fractions from 0 to 1. Chroma is C = V × S, the gap between the strongest and weakest channel. The middle channel is X = C × (1 − |(H ÷ 60) mod 2 − 1|), and m = V − C is the amount added to all three.

Which channel gets C and which gets X depends on the hue, in six sectors of 60°. Add m to each, multiply by 255 and round.

The six hue sectors

HueRed, green, blue before adding mRuns from
0° to 60°C, X, 0Red to yellow
60° to 120°X, C, 0Yellow to green
120° to 180°0, C, XGreen to cyan
180° to 240°0, X, CCyan to blue
240° to 300°X, 0, CBlue to magenta
300° to 360°C, 0, XMagenta to red

A worked example

Take hsv(220, 75%, 80%). C = 0.8 × 0.75 = 0.6. H ÷ 60 = 3.667, and 3.667 mod 2 = 1.667, so X = 0.6 × (1 − 0.667) = 0.2. Then m = 0.8 − 0.6 = 0.2.

220° falls in the cyan to blue sector, so the channels start as (0, X, C) = (0, 0.2, 0.6). Adding m gives (0.2, 0.4, 0.8), and × 255 that is rgb(51, 102, 204).

HSV values in RGB

HSVRGBHex
hsv(0, 0%, 100%)rgb(255, 255, 255)#FFFFFF
hsv(0, 0%, 50%)rgb(128, 128, 128)#808080
hsv(0, 100%, 100%)rgb(255, 0, 0)#FF0000
hsv(120, 100%, 50%)rgb(0, 128, 0)#008000
hsv(240, 100%, 100%)rgb(0, 0, 255)#0000FF
hsv(220, 75%, 80%)rgb(51, 102, 204)#3366CC
hsv(32, 100%, 100%)rgb(255, 136, 0)#FF8800
hsv(300, 50%, 75%)rgb(191, 96, 191)#BF60BF
hsv(180, 25%, 90%)rgb(172, 230, 230)#ACE6E6
hsv(45, 80%, 60%)rgb(153, 122, 31)#997A1F

HSV, HSB and HSL

HSV and HSB are two names for one model. Hue, saturation and value is the same thing as hue, saturation and brightness, and the numbers match.

HSL is different. Its third number, lightness, puts the pure colour at 50% and white at 100%, while HSV puts the pure colour at 100% value, and white is 0% saturation at 100% value. Their saturations differ too, so hsv(220, 75%, 80%) is hsl(220, 60%, 50%). CSS reads hsl() but has no hsv(), so use hex to HSL for a stylesheet.

Questions

What happens with a saturation of 0?

C is 0, so all three channels equal V × 255. The colour is a grey, and the hue makes no difference.

What if the hue is over 360?

Hue goes round in a circle, so 400° is the same as 40° and −20° is the same as 340°.

Why did my numbers come out as rgb() of different values?

If the three numbers go in without hsv(), this page reads them as HSV. Check the order is hue, saturation, value.

Sources

Added and reviewed . What's new