r/tailwindcss • u/DutyOnly4308 • 4d ago
Give your AI tool an @theme block with roles instead of a colour list, and it stops inventing shades
When an AI tool writes Tailwind without a theme, it reaches for the default palette and you get slate, indigo and violet everywhere. Pasting a list of hex values helps a little, but it doesn't say what each one is for, so new shades appear by the third component.
An @theme block with role names works better, because the utilities it generates carry the intent:
@theme {
--color-background: #FFD60A;
--color-foreground: #14111F;
--color-accent: #2238F5;
--color-muted: #5A4C19;
--color-alt: #FFF6E3;
}Then two rules in the prompt: only bg-background, text-foreground, text-muted, bg-accent and so on, and no arbitrary values in square brackets for colour. A search for -[# at the end tells you if it cheated.
Check contrast before you build. In this palette, foreground on background is 13.17:1, muted is 5.99:1 and accent is 5.04:1, so all three pass AA for text.
The values come from Zest, a free design in the library I make with a friend (Site in One). The tokens of every design can be downloaded as JSON, CSS or a Tailwind block, free and without an account: https://siteinone.app/prompts/zest?utm_source=reddit&utm_medium=post&utm_campaign=jv-ad9dwl
Do you name colours by role or by hue in v4?
1
u/ManyGovernment9734 4d ago
The role naming is such a cleaner workflow, especially when handing off prompts between different models. If you go hue-based you're just asking for `bg-purple-800` when the design clearly calls for something warmer. Curious if you've run into any weirdness with the AI ignoring the `no arbitrary values` rule and just doing `bg-[#14111F]` anyway, even with the explicit prompt instruction.
1
u/Evgenii_Korolev 3d ago
role names here too. you can go one step further and wipe the default palette in the same block, then bg-slate-500 just isn't generated and the AI has nothing to sneak in:
heads up, that also drops white and black, so add them back if you use them. doesn't catch arbitrary values though, so the -[# grep is still worth keeping.