GamutDesk Logo
GamutDesk

W3C CSS4 HWB to HEX Converter

Convert HWB (Hue, Whiteness, Blackness) values to a HEX color code. Follows the CSS Color Level 4 algorithm, including gray normalization when W plus B is 100%.

Client-Side ArchitecturePrivate Client-Side Processing

Input

Result

HEX#3B82F5
RGBrgb(59, 130, 245)
CSS hwb()hwb(217 23% 4%)

Technical Specification & Mathematical Principles

How the HWB to HEX Converter Works

The CSS Color 4 algorithm first normalizes whiteness and blackness: if W + B >= 1, the result is the gray W / (W + B) on all channels. Otherwise it computes the fully saturated RGB of the hue (HSL with S = 100% and L = 50%).

Each channel of that pure hue is then scaled: channel = pure x (1 - W - B) + W. The result is multiplied by 255 and rounded to produce the 8-bit HEX channels. At W = 0 and B = 0 the output is the pure hue; at W = 100% it is white; at B = 100% it is black.

Frequently Asked Questions

What happens when whiteness plus blackness exceeds 100%?
Per the specification the two values are scaled proportionally so they sum to 100%, which always yields a neutral gray. For example hwb(120 60% 60%) becomes #808080.
Can hue be negative or above 360?
Yes. Hue wraps around the color wheel, so -60 degrees equals 300 degrees and 420 degrees equals 60 degrees.
Why is the result sometimes one digit off from another tool?
Implementations round at different stages. This tool computes in floating point and rounds only once at the end, matching browsers.

Related Design & Color Instruments