Color guides

Extract image clusters and check text contrast

·

Use a whole-image cluster analysis to extract a palette from several regions. Start with the small RGBA sample so the visible population and contrast are easy to check.

Dominant Color Extractor

Count the visible pixels in the RGBA example

Select Load example. Keep Maximum clusters at 8 and the backdrop white. Extract the 4 × 2 image. Seven samples enter the calculation and each of the seven resulting colors has one sample. The fully transparent pixel is excluded.

Choose a black backdrop and extract again. The partially transparent sample appears darker. Opaque colors keep their original values.

ToolMellow RGBA channel sample

Reduce the clusters and compare black or white text

Change Maximum clusters to 3 and extract again. K-means groups similar visible samples using distances between their RGB channels and reports each group’s rounded mean. Percentages use the total visible sample count.

Contrast uses the rounded swatch color as a solid background behind each text color. The thresholds in the table apply to normal text.

Reduce the clusters and compare black or white text
TestWCAG ratioWhat it describes
AA normal text4.5:1 or higherContrast Minimum
AAA normal text7:1 or higherContrast Enhanced
Black text on white21:1A reference pair with maximum sRGB contrast

Stuart Lloyd, Least Squares Quantization in PCMW3C WCAG 2.2, contrast and relative luminance

Export the rounded swatches and their evidence

Choose CSS variables and download dominant-colors.css. The file defines --palette-1 and subsequent variables in descending sample-count order. Sass and Tailwind v3 configuration export the same colors in their own formats.

Choose JSON evidence to save the sample dimensions, backdrop, population and contrast numbers. The cluster coordinates are derived from the current sample and can change if you adjust its backdrop or group count.

ToolMellow RGBA channel sample

Common questions

Why might a swatch color be absent from the original file?

Each swatch represents the rounded mean of its assigned sampled colors. That mean can fall between colors present in the source.

Do the contrast ratings certify the finished artwork?

They measure opaque black and white text on each solid swatch. Check the actual text and background wherever you place them in a design.

Sources

Put it into practice.

Related guides