-
TLDR:On v3 I could just define custom spacing in tailwind.config.js like How can I do the same in v4 now that there’s no config file? Hi everyone, In Tailwind v3, it was extremely easy to define semantic spacing tokens directly in the t theme: {
extend: {
spacing: {
small: '0.5rem',
widget: '1.5rem',
},
},
}Then we instantly got access to all spacing-related utilities out of the box: With Tailwind v4, since there’s no I find a way with css variable but this is much less clean I also tried building a custom plugin that generates utilities like p-small, mt-small, inset-x-small, etc. from a JS map: const spacings = {
small: 'var(--spacing-small)',
widget: 'var(--spacing-widget)',
};It works, but it feels very heavy. I have to manually list every possible spacing prefix ( Is there any recommended or planned approach in Tailwind v4 to recreate semantic spacing aliases (like Or could Tailwind provide a way to automatically generate all spacing utilities from semantic tokens defined in |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Damn, I just had to ask the question to find the answer myself... Then just use |
Beta Was this translation helpful? Give feedback.
Damn, I just had to ask the question to find the answer myself...
Declaring CSS variables with the --spacing prefix inside
@themedoes the trick:Then just use
mt-small,pb-small, .....https://play.tailwindcss.com/MV8UbfAYBK?file=css