HN
Today

Too Much Color

This technical deep dive meticulously quantifies how many decimal places are truly necessary for CSS color values, ultimately concluding that three decimal points for 0-1 ranges and one for larger scales provide an imperceptible yet robust precision. The author's journey to this simple rule, driven by minifier development, resonates with Hacker News's appreciation for rigorous analysis, performance optimization, and practical takeaways from complex problems. It sparks discussions on web bloat, human perception, and developer workflows.

60
Score
33
Comments
#11
Highest Rank
11h
on Front Page
First Seen
Mar 20, 9:00 AM
Last Seen
Mar 20, 8:00 PM
Rank Over Time
2426181511192127182320

The Lowdown

The author, while developing a CSS minifier for csskit, delves into the precise world of color representation and asks: 'Just how precise is precise enough?' His extensive research reveals that many decimal places found in color pickers are superfluous, leading to the core assertion that 3 decimal places (dp) are sufficient for most color notations.

  • The article introduces Delta-E (dE00 and dEOk) as metrics to quantify color differences, defining the 'Just Noticeable Difference' (JND) as the threshold below which humans cannot perceive a distinction (dE00 JND ~2.0, dEOk JND ~0.02).
  • Through interactive demos, the author illustrates how rounding to 0, 1, or 2 decimal places can lead to perceptible color shifts or accumulation of errors in chained operations (like color-mix() or relative color syntax).
  • The primary recommendation is 3dp for color channels with a 0-1 range (e.g., oklab L, a, b; oklch L, C; alpha) and 1dp for larger ranges (e.g., oklch h, lab/lch L, C, h; XYZ D50/D65). This provides a crucial safety margin against rounding errors that compound in complex color calculations.
  • For sRGB notations like rgb() or hsl(), where values are often integers or percentages, the 8-bit quantization of browsers means extra precision is typically discarded. Integers suffice for static colors, while 1dp is recommended for chained calculations.
  • Browsers store color values as 32-bit floats, meaning they don't perform internal rounding or optimization, making external minification efforts like the author's relevant.

Ultimately, the author's quest for a 'smart' rounding algorithm for his minifier led him to a surprisingly simple solution: a static lookup table of recommended decimal places per color space. This eliminates complex, error-prone calculations at minify time while ensuring perceptually identical results and robust color handling.

The Gossip

Minimizing Bloat & Bytes

Commenters acknowledged the article's deep dive into optimizing color precision, but several questioned the practical impact of saving a few bytes on color values given the overall 'enshitification of the web' with megabytes of JavaScript and other bloat. Some highlighted that while technically correct, the byte savings might be negligible in the grand scheme, contrasting with the detailed technical effort involved.

Perceptual Ponderings

A significant portion of the discussion revolved around the 'What's My JND?' game linked in the article. Users shared their scores, often beating the theoretical JND, and debated factors influencing perception like monitor quality, lighting, and even head-bobbing. The concept of tetrachromacy also came up, with some wondering if such individuals could discern the subtle differences the article deems imperceptible, though others countered that screen technology limits such distinctions.

Design Decisions & Dev Dilemmas

Comments touched on the practical implications for designers and developers. One user lamented 'NASA numbers' – excessive precision from design tools that bloats SVG files and complicates workflows, advocating for simpler, more manageable values. Another observed the irony of a color expert's website being monochrome, sparking discussion on whether it reflected a preference for minimalism or a deep understanding of color theory that led to a neutral canvas.