The "View work" button in my home page hero disappeared in light mode: white text on an almost-white background, and the only way to know it was there was to hover over it. Dark mode looked perfectly fine.
The class looked right, the CSS was broken
The button's classes referenced theme variables defined in globals.css:
<a className="bg-[--accent] text-[--bg]">View work</a>
This was a very common shorthand in the Tailwind v3 days: put a bare variable name inside square brackets and Tailwind wraps it in var(--accent) for you. tsc, ESLint and next build all passed without a single warning.
Opening DevTools on the button gave the answer straight away:
.bg-\[--accent\] {
background-color: --accent;
}
Not var(--accent). The literal text --accent. That is not a valid color, so the browser drops the declaration, and the button ends up with no background color at all.
Why only light mode broke
Tailwind v4 deprecated the "square brackets plus a bare variable name" shorthand and replaced it with parentheses:
// the v4 way
<a className="bg-(--accent) text-(--bg)">View work</a>
In v4, square brackets only mean "copy this value as is", so [--accent] is written into the CSS untouched.
Both themes were actually broken. In dark mode the page background happened to be dark enough that a transparent button with light text still looked normal. A bug where one theme gets away with it is exactly the kind you never catch if you only look at one theme.
A search across the whole site found 116 places written this way. All of them now use parentheses.
Fixed, and the broken rule was still in the CSS
After the change I rebuilt, opened the compiled CSS, and background-color:--accent was still there. I deleted .next entirely and rebuilt. Still there.
The source turned out to be the project's own documentation. I had written this bug up in CLAUDE.md, including a "don't use square brackets" counter-example. With no config file, Tailwind v4 automatically scans the whole repository for class names, .md files included. It saw the counter-example in the docs and compiled it as a real class.
The fix is to exclude Markdown in the CSS:
@source not "../../**/*.md";
This post is an .mdx file that also shows the wrong syntax as a counter-example, so .mdx is excluded too.
What I learned
- In v4, always reference CSS variables with parentheses:
bg-(--accent). Square brackets are only for real literal values such asw-[1px]ortracking-[0.2em] - "The build passed" does not mean the CSS is right. Color mistakes are invisible to tsc, lint and the build. Either open DevTools and look at the computed value, or rely on an automated contrast check (I later added an axe scan to my browser tests, run once in light mode and once in dark)
- Look at both themes
- Tailwind scans your docs. If you show wrong syntax in Markdown, exclude those files
If you would rather not hunt these down one by one, I built a small tool for it (the page itself is in Chinese): paste your code, it highlights every square-bracket variable and converts them all to parentheses in one click.