Measuring text contrast: from a 1.02:1 button to a build gate
It started with button text drawn at 1.02:1 on white. Three parts follow it to a checker that silently skipped 40% of the text, then to a site build that computes 143 contrast pairs and fails below 4.5:1.
What this series found
- The buttons in a delete dialog of our spelling app had a contrast of 1.02:1 on white (September 16, 2026). No layout XML set white text: the app bar colour, colorPrimary, leaked into button text in three places. (Part 1: where the theme colour leaks)
- While a contrast check passed with zero failures in light, dark and sunset themes, 3,762 of 9,318 text fragments (40%) had been dropped with no contrast value. Measuring them again turned up a SnackBar at 3.28:1. (Part 2: the checker that skipped 40%)
- In the dark theme, the hover state of outline buttons fell below 4.5:1 for 7 of 11 apps. The build now computes 143 contrast pairs from 13 app accents and fails if any pair falls short. (Part 3: contrast in the build)
- The gate still has a gap. On November 3, putting the old 4.17:1 hover pair back into a copy of the CSS still passed the build, because the gate computes contrast from a fixed list of token pairs and never reads which pairs the CSS uses. (Part 3)
This series is for developers who want contrast checked automatically in an app or on a website. Each part changes what the check actually measures, so they read best in order: Part 1 moves from reading XML to measuring the view on screen, Part 2 makes the checker print how much it measured and fail on a shortfall, and Part 3 turns a one-line rule in a document into a build failure. In a hurry? Follow the steps in Part 1 for Android, Part 2 for Flutter and Part 3 for a site with many accent colours.
Series contents
- Part 1No XML file said white, yet the dialog buttons vanished: three places a theme colour leaked
The app bar colour, colorPrimary, became dialog and sheet button text at 1.02:1 on white.
- Part 2Our contrast checker passed while skipping 40% of the text: make it print how much it measured
A contrast check that passed in three themes had silently dropped 3,762 of 9,318 text fragments (40%).
- Part 34.5:1 contrast in the site build: the dark hover pair that failed for 7 of 11 apps
Our site build computes 143 contrast pairs from 13 app accents and fails below 4.5:1.