Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tailwind CSS: Use CSS variable as arbitrary value for font size?

Using Tailwind CSS, I know it is possible to use px and rem values as arbitrary values to set an element's font size:

text-[6.9rem]
text-[420px]

But is there a way to use CSS variables as arbitrary font size values? Using a variable in place of a px or rem value to set the font size does not seem to work, as the resulting class sets the element's color i.o. its font size:

text-[var(--custom-size-a)]
text-[var(--custom-size-b)]

enter image description here

like image 377
JoSch Avatar asked Sep 08 '26 10:09

JoSch


1 Answers

When using a CSS variable as an arbitrary value, wrapping your variable in var(...) isn’t needed — just providing the actual variable name is enough:

text-[--custom-size-a]
text-[--custom-size-b]

<!-- Will generate a font-size utility -->
<div class="text-[length:--my-var]">...</div>

<!-- Will generate a color utility -->
<div class="text-[color:--my-var]">...</div>

tailwind arbitrary values

like image 145
Jabir Avatar answered Sep 10 '26 22:09

Jabir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!