Kinda Code
Home/HTML & CSS/Tailwind CSS: How to set font size with an arbitrary value

Tailwind CSS: How to set font size with an arbitrary value

Last updated: June 10, 2022

Tailwind CSS provides utility classes for setting the font size of text with fixed values: text-xs, text-sm, text-base, text-lg, text-2xl, text-3xl, text-4xl, text-5xl, text-6xl, text-7xl, text-8xl, and text-9xl. However, you can use an arbitrary font size by enclosing your custom value between a pair of square brackets: text-[your value here].

Example

Screenshot:

The code:

<body class="p-20 bg-green-700 space-y-5">
    <h1 class="text-[80px] text-white font-light italic">KindaCode.com (80px)</h1>
    <p class="text-[4em] text-yellow-500">Hello There (4em)</p>
    <p class="text-[3.5rem] text-sky-300">Banana (3.5rem)</p>
</body>

That’s it. Further reading:

You can also check out our CSS category page for the latest tutorials and examples.