How do I find hard-coded colours in a React codebase?

Short answer

Search the source for colour literals (hex, rgb(), hsl(), oklch()), including inside Tailwind classes like bg-[#8458d8] and inline style props, then compare each one with your declared tokens in every theme. A literal that equals a token exactly is a mistake with a known fix: swap it for the token. A literal close to a token is probably a copy that drifted. One that matches nothing is either a new colour nobody declared or a one-off that should not exist.

A first pass with grep

A plain search gets you a list in seconds. It cannot tell you which token each value should be, and it will also find colours that belong where they are, such as a chart palette or an SVG.

grep -rnoE '#[0-9a-fA-F]{3,8}\b' src --include='*.tsx' --include='*.ts' --include='*.css' | sort | uniq -c | sort -rn | head
grep -rnoE '(rgb|hsl|oklch)a?\([^)]*\)' src | head

Why the list alone is not enough

  • Tokens resolve differently per theme. #5227a5 may be your brand colour in light mode and nothing in dark mode.
  • Tokens are often defined indirectly, through var() chains, Tailwind configs or @theme blocks, so the value you need to compare against is not written anywhere as a literal.
  • Case and format differ: #FFF, #ffffff and rgb(255 255 255) are the same colour to a reader and three strings to grep.

So the useful question is not where the literals are but which token each one restates, and in which themes.

Doing it with Saer

Saer resolves your tokens in every theme and context, then reports each raw value that equals one (exact drift, with the token to use) apart from values that are only close (near-matches, with the distance). The colour scan is free, needs no account and works offline.

curl -fsSL https://saer.app/install | sh
saer scan

Open .saer/report.html for every finding with its file and line. See reading the report.

What Saer does about this

Today
  • Colour in the beta: Tailwind v3 configs, Tailwind v4 @theme blocks and CSS custom properties, across dark mode and other theme contexts, with exact drift, near-matches, dead and conflicting declarations.
  • The free colour scan needs no account. A free account adds full local scans of every area: type, spacing and the other foundations, components and accessibility.
Not yet
  • Windows and Linux builds of the full scan: the beta runs on macOS on Apple Silicon.

Every capability and its state: what Saer checks.

See it on your own codebase.

Start free trial