StringMash.com

RGB to HSV converter

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

Conversion
16 characters
Updates as you type
Hex#FF8800
RGBrgb(255, 136, 0)
HSLhsl(32, 100%, 50%)
HSV (HSB)hsv(32, 100%, 100%)
CMYKcmyk(0%, 47%, 100%, 0%)
Nearest CSS namedarkorange
Contrast with white2.39:1 (fails)
Contrast with black8.77:1 (AAA)
The swatch and working are below

Show the steps
Aa blackAa white
  1. Divide each channel by 255: red 1, green 0.533, blue 0. The largest is 1 and the smallest 0, so the chroma (their difference) is 1.
  2. Value (or brightness) is the largest: V = 1, so 100%.
  3. Saturation is the chroma divided by the value: S = 1 ÷ 1 = 1, so 100%.
  4. Hue: red is the largest, so H = 60 × (0.533 − 0) ÷ 1 = 32°. Rounded, 32°.
  5. Together: hsv(32, 100%, 100%). Many colour pickers show the same three numbers under the name HSB.
  6. Contrast: 2.39:1 against white and 8.77:1 against black, so black text reads better on it.

Using the converter

Type an RGB colour as rgb(255, 136, 0) or three numbers from 0 to 255. The HSV value appears with the hue in degrees and saturation and value as percentages, the way a colour picker shows them.

Hex codes, hsl() values and CSS names work too. Swap the boxes to go from HSV back to RGB.

The RGB to HSV formula

Divide red, green and blue by 255, so each is between 0 and 1. Call the largest M, the smallest m, and their difference the chroma C.

Value is M. Saturation is C ÷ M, or 0 for black. Hue depends on which channel is largest. If it's red, H = 60 × ((G − B) ÷ C), plus 360 if that comes out negative. If green, H = 60 × ((B − R) ÷ C + 2). If blue, H = 60 × ((R − G) ÷ C + 4).

A worked example

Take rgb(255, 136, 0). Divided by 255 that's 1, 0.533 and 0, so M = 1, m = 0 and C = 1.

Value is 1, or 100%. Saturation is 1 ÷ 1, also 100%. Red is the largest, so the hue is 60 × (0.533 − 0) ÷ 1 = 32°. The answer is hsv(32, 100%, 100%), a fully bright, fully saturated orange.

Common colours in HSV

Hue in degrees, saturation and value in percent, rounded to whole numbers.
ColourRGBHSV
Redrgb(255, 0, 0)hsv(0, 100%, 100%)
Orangergb(255, 165, 0)hsv(39, 100%, 100%)
Yellowrgb(255, 255, 0)hsv(60, 100%, 100%)
Limergb(0, 255, 0)hsv(120, 100%, 100%)
Greenrgb(0, 128, 0)hsv(120, 100%, 50%)
Cyanrgb(0, 255, 255)hsv(180, 100%, 100%)
Bluergb(0, 0, 255)hsv(240, 100%, 100%)
Navyrgb(0, 0, 128)hsv(240, 100%, 50%)
Purplergb(128, 0, 128)hsv(300, 100%, 50%)
Magentargb(255, 0, 255)hsv(300, 100%, 100%)
Pinkrgb(255, 192, 203)hsv(350, 25%, 100%)
Brownrgb(165, 42, 42)hsv(0, 75%, 65%)
Whitergb(255, 255, 255)hsv(0, 0%, 100%)
Silverrgb(192, 192, 192)hsv(0, 0%, 75%)
Greyrgb(128, 128, 128)hsv(0, 0%, 50%)
Blackrgb(0, 0, 0)hsv(0, 0%, 0%)

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.

Where HSV came from

Alvy Ray Smith described HSV in the August 1978 issue of Computer Graphics. He wanted a model that matched how a painter mixes, starting from a pure pigment and adding white to tint it or black to shade it.

In HSV, adding white lowers the saturation and adding black lowers the value. That is still how most colour pickers are laid out, with a hue strip beside a square of saturation and value.

Questions

Is HSV the same as HSB?

Yes. Brightness and value are two names for the same number.

Why is the hue 0 for white, grey and black?

They have no hue, because red, green and blue are equal. It is written as 0 by convention.

Does converting to HSV and back change the colour?

It can by one step in a channel, because HSV is rounded to whole degrees and percentages.

Sources

Added and reviewed . What's new