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

Updated: June 10, 2022 By: Pennywise Post a comment

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.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Related Articles