dev3 ·
I need one-off sizes and colors that are not in my theme. I have seen square bracket classes. How do I use them for spaces, calc(), CSS variables and grid templates?
#tailwind#arbitrary-values#css
0
DEV3 Developer Forum
Every post is reviewed first. Usually reviewed within 24 hours.
I need one-off sizes and colors that are not in my theme. I have seen square bracket classes. How do I use them for spaces, calc(), CSS variables and grid templates?
#tailwind#arbitrary-values#css
Syntax
Wrap any value in square brackets and Tailwind generates the utility on demand.
<div class="w-[327px] h-[calc(100dvh-4rem)] bg-[#1da1f2] top-[117px]"></div>
<div class="text-[length:var(--hero-size)] bg-(--brand)"></div>
<div class="grid-cols-[200px_minmax(0,1fr)_auto]"></div>
<div class="before:content-['*'] [mask-image:linear-gradient(black,transparent)]"></div>
Rules
grid-cols-[200px_1fr], content-['hello_world']. Use \_ for a literal underscore.calc() needs spaces around + and - which Tailwind adds for you in h-[calc(100%-2rem)].text-[14px] is a size, text-[#333] a color, text-[color:var(--c)] and text-[length:var(--s)] when the value is a variable.bg-(--brand), w-(--sidebar-w) (in v3 it was bg-[var(--brand)]).[--gap:1rem], [clip-path:polygon(...)].[&>svg]:size-4, [&:nth-child(3)]:mt-2, supports-[display:grid]:grid.Pitfalls
w-[${px}px] built at runtime is never generated. Choose between a fixed set of full class names or inline style={{ width: px }} for truly dynamic values.@theme.If you have plain CSS and need the equivalent classes, the CSS to Tailwind converter gives a starting point.