Sub topic 3
The color wheel and hue angles
This chapter treats hue as a position on a circle. You will read hue angles, measure the gap between two hues, and see why two wheels that look similar can disagree about which colors are opposites. It assumes you know that hue names a color family such as red or blue, that screens mix red, green, and blue light, and that you can read short CSS and Python snippets.
From a list of colors to a circle
Hue describes which family a color belongs to. Red, orange, yellow, green, blue, and purple are the familiar families. If you place them in order of their light wavelengths, they form a line from red to violet. Purple and magenta do not fit that line. They come from mixing the two ends, red-ish light and blue-ish light. Closing the line into a ring puts red and violet next to each other, and magenta sits between them.
That ring is the color wheel. Because it is a ring, every hue can be given an angle, measured in degrees from 0 to 360. Software and CSS use this convention. Red sits at 0°, and the angle increases through the rainbow order.
The hue angles of the screen wheel
The wheel used in screen color models (HSL, HSV, and CSS) is built on the RGB primaries, which are red, green, and blue light. They sit 120° apart. The colors you get by mixing two primaries sit halfway between them.
| Angle | Hue | How it forms |
|---|---|---|
| 0° | Red | Primary |
| 60° | Yellow | Red + green |
| 120° | Green | Primary |
| 180° | Cyan | Green + blue |
| 240° | Blue | Primary |
| 300° | Magenta | Blue + red |
| 360° | Red again | Same as 0° |
Everything else is in between. Orange is near 30°, because it is red with some green added. A sky blue is around 200°, and a violet is around 270°.
Hue is circular, so the arithmetic is too
Hue is a position on a ring, not a position on a ruler. Two consequences follow.
First, 0° and 360° are the same color. Any angle can be shifted by a full turn without changing the color. CSS follows this rule. hsl(370 80% 50%) is the same as hsl(10 80% 50%), and hsl(-20 80% 50%) is the same as hsl(340 80% 50%).
Second, the distance between two hues is the shorter way around the ring. Hues 350° and 10° are only 20° apart, even though the numbers differ by 340. If you compute "closeness" with a plain subtraction, you will treat a red and a slightly different red as opposites.
The function below handles both rules. It gives the angle of a color, and the shortest distance between two hues.
import colorsys
def hue_degrees(r, g, b):
"""Hue of an RGB color (components 0 to 1), in whole degrees 0-359."""
h, s, v = colorsys.rgb_to_hsv(r, g, b)
return round(h * 360) % 360
def hue_distance(a, b):
"""Shortest angular distance between two hues, from 0 to 180."""
diff = abs(a - b) % 360
return min(diff, 360 - diff)
print(hue_degrees(1, 0, 0)) # 0 (red)
print(hue_degrees(1, 1, 0)) # 60 (yellow)
print(hue_degrees(0, 0, 1)) # 240 (blue)
print(hue_degrees(1, 0.5, 0)) # 30 (orange)
print(hue_distance(350, 10)) # 20
print(hue_distance(0, 180)) # 180The largest possible distance is 180°. Anything farther around one way is shorter the other way.
The final % 360 in hue_degrees matters. A color that rounds up to 360° is reported as 0°, so it matches red.
Where the angle comes from
Hue is computed from the RGB values by comparing the largest and smallest channels. Let max and min be the largest and smallest of R, G, and B, and let delta = max - min. Then:
- If red is largest:
hue = 60 × (((G − B) / delta) mod 6) - If green is largest:
hue = 60 × ((B − R) / delta + 2) - If blue is largest:
hue = 60 × ((R − G) / delta + 4)
Take the medium blue from the Python example, RGB (0.2, 0.4, 0.8). Blue is largest and delta = 0.6, so hue = 60 × ((0.2 − 0.4) / 0.6 + 4) = 60 × 3.667 = 220°. This matches what colorsys reports.
Each channel contributes a base angle: 0° for red, 120° for green, and 240° for blue. The other two channels then pull the hue toward their own side by up to 60°. This is why a color with a lot of red and a little green lands between red (0°) and yellow (60°).
Hue is undefined for grays
If delta is 0, then R, G, and B are equal and the color is a gray. The formula would divide by zero, and there is no direction to point in. Libraries return 0 by convention.
import colorsys
print(colorsys.rgb_to_hsv(0.5, 0.5, 0.5)) # (0.0, 0.0, 0.5)The 0 here does not mean "red". It means "no hue", and saturation is 0. The same applies to near-grays: a color with very low saturation has a hue number that is real but visually almost meaningless, and small rounding changes can shift it a lot. When you analyze colors in code, ignore the hue of anything with saturation near zero.
Two wheels, two answers
The wheel in the table above is the screen wheel. It is based on light, where red, green, and blue are primaries. Art classes often teach a different wheel, the traditional RYB wheel, where red, yellow, and blue are primaries and green sits opposite red.
The two wheels place colors in the same general order, but they differ in spacing and in what counts as opposite.
| Question | Screen wheel (RGB) | Traditional wheel (RYB) |
|---|---|---|
| Primaries | Red, green, blue | Red, yellow, blue |
| Opposite of red | Cyan | Green |
| Opposite of blue | Yellow | Orange |
| Used by | CSS, HSL, HSV, most design tools | Painting and print-minded teaching |
Design tools use the screen wheel when you type or drag a hue number. A color picker may still show a different layout. Check the angle readout to see which one you are working with.
Rotating hue in practice
Because hue is an angle, many color relationships become plain addition. To get a related color, add or subtract degrees from a base hue and keep saturation and lightness the same.
:root {
--base-hue: 210;
--base: hsl(var(--base-hue) 70% 50%);
--shift-30: hsl(calc(var(--base-hue) + 30) 70% 50%);
--shift-minus-30: hsl(calc(var(--base-hue) - 30) 70% 50%);
--opposite: hsl(calc(var(--base-hue) + 180) 70% 50%);
}With a base hue of 210°, these resolve to 240° (a more violet blue), 180° (a greener cyan), and 390°, which wraps to 30° (orange). You do not need to wrap the number yourself in CSS. In Python, wrap with % 360, or % 1.0 when working in colorsys units.
Small offsets such as ±30° give neighbors that feel like variations of one color. Offsets near 180° give strong opposition. The next chapters on tints and harmonies build on this, so here it is enough to know that the offset is the whole mechanism.
Common errors
- Forgetting the wrap. Adding 180 to a hue of 270 gives 450. In CSS this is fine. In code that expects 0 to 359, it fails or produces an invalid value.
- Comparing hues by plain subtraction. Use the shortest-way-around distance, as in
hue_distance. - Mixing units.
colorsysuses 0 to 1 for hue, while CSS uses degrees. A hue of 0.5 is 180°. Passing 180 tocolorsysgives a wrapped, wrong result without any error. - Trusting the hue of a gray. The 0 returned for gray is a placeholder.
- Assuming equal angles look equally different. The spacing is mathematical, not perceptual. Between 90° and 150° the greens look similar, while between 0° and 60° the change from red to yellow is obvious. The reason belongs to a later chapter on perceived lightness.
Exercise
A brand color has a hue of 300°. (a) What hue do you get after adding 90°? (b) What is the shortest distance between that new hue and a hue of 20°? (c) In the screen wheel, which named hue sits opposite 300°?
Show answer
(a) 300 + 90 = 390, which wraps to 30° (an orange). (b) The difference is |30 − 20| = 10, and the other way around is 350, so the shortest distance is 10°. (c) Adding 180 gives 480, which wraps to 120°, so the opposite of magenta (300°) is green.
Exercise
Why does hue_distance(0, 270) return 90 and not 270?
Show answer
Hue is a circle, so the distance is the shorter way around. The plain difference is 270, and the other direction is 360 − 270 = 90. The function returns the smaller of the two, which is 90.