I'm trying to use custom spacing variables from my Tailwind theme inside a calc() expression, but it doesn’t seem to work.
In my input.css, I added custom spacing like this:
@theme {
--spacing-my-custom-height: 10rem;
--spacing-my-custom-height-2: 5rem;
}
Then in my HTML, I tried using them like this:
<div class="size-my-custom-height bg-green-800">
<!-- Works -->
<div class="size-my-custom-height-2 bg-green-600"></div>
</div>
<div class="size-my-custom-height bg-green-800">
<!-- Doesn't work -->
<div class="size-[calc(100%-(my-custom-height-2))] bg-green-600"></div>
</div>
How can I correctly use Tailwind's custom spacing variables inside a calc() expression in utility classes?
- TailwindCSS v4.1
- Installation mode: CLI
Note: There is no error in the terminal.
--prefix is not omitted. It's only meant to make writing shorter class names easier. If you just want to reference a variable withoutcalc(), you can usesize-(--my-custom-height)instead ofsize-[var(--my-custom-height)](but both are correct). See more: tailwindcss.com/docs/…