Why do dynamically constructed Tailwind class names fail to render?
Tailwind's JIT scans the files listed in content and generates only classes it finds as literal strings. Class names built dynamically are invisible to the scanner.
// broken: no utility generated
const cls = `bg-${color}-500`;
// works: full class names present in source
const cls = color === 'red' ? 'bg-red-500' : 'bg-blue-500';
This is the most common Tailwind bug. Fixes: write complete class names in a lookup map or object, add a safelist in the config for values you cannot enumerate, or use inline styles for truly dynamic values.
The content array must include every file type that contains classes, including .vue, .svelte, .php and template files, and broad globs like ./src/**/* are fine. In v4 content is auto-detected, but explicit sources still help with generated files. Keeping class strings static also matters for frameworks that purge unused styles in production.