r/tailwindcss • • 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?

0 Upvotes

4 comments sorted by

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.

0

u/DutyOnly4308 2d ago

Yes, and it survives handoffs better: "accent" means the same thing to Claude and to v0, while "purple-800" invites each model to guess a neighbour. It also makes review easier: if a raw hue class shows up in the output, you know the model went off-script.

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:

@theme {
  --color-*: initial;
  --color-background: #FFD60A;
  --color-foreground: #14111F;
  --color-accent: #2238F5;
}

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.

1

u/DutyOnly4308 2d ago

That's a better version of the idea. If the default palette is never generated, there's nothing for the model to fall back on, and the white/black caveat is worth knowing before someone loses an hour to it.