Typographic defaults in Tailwind CSS v4: font, size, color and prose
Published Updated 7 min read
On this page
How do you handle typographic styles with a utility-first CSS framework like Tailwind CSS? In this article I show you how to set your defaults for font family, size, line height and color, how to style headings and links, and how to style content you don’t control, such as text from a CMS or a markdown file.
The best way to set typographic defaults in Tailwind CSS
Updated for Tailwind CSS v4. I wrote this post in 2021 for Tailwind CSS 2. Tailwind v4 moved the configuration from tailwind.config.js into your CSS file, so the font and typography plugin setup below is rewritten. The examples also had a mistake: they used classes like font-base and font-3xl, which never existed. Font sizes in Tailwind are text-base, text-3xl and so on.
Define the basics#
Start with the global typographic defaults for the page, so you can fine-tune specific elements later. To follow along, a basic understanding of how Tailwind CSS works helps.
Font family
The first thing to decide is the font family. Tailwind CSS comes with three font stacks out of the box: font-sans, font-serif and font-mono. A font stack is a list of fonts, where each one is the fallback for the one before it.
In Tailwind v4 the page already uses the sans stack by default: Preflight sets the font of the html element from --font-sans. To use a different stack on the whole page, put its class on the body:
<body class="font-serif">...</body>You likely want your own brand font. In v4 you do that in your CSS with a theme variable, not in tailwind.config.js. To make Roboto the sans font, with the system fonts as fallback:
@import "tailwindcss";
@theme {
--font-sans: "Roboto", ui-sans-serif, system-ui, sans-serif;
}Because the page default reads --font-sans, this changes the font everywhere without a class on the body. You can also add a font next to the defaults: --font-display: "Oswald", sans-serif; gives you a font-display class.
Don’t forget to load the font itself, for example from Google Fonts in the head of your document, or self-hosted with @font-face:
<head>
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
</head>Font size and font weight
Next, the base font size and weight. Tailwind has font size classes from text-xs to text-9xl and font weight classes from font-thin to font-black. These defaults work well in most cases:
<body class="text-base font-normal">...</body>And if you want a little more impact:
<body class="text-lg font-medium">...</body>The Tailwind font size, weight and family reference lists every class with its pixel value and line height, and the font size generator builds a scale of your own as a v4 @theme block.
Line height
Every text-* class sets a line height to match: text-base is 16px with a line height of 1.5. To change it, Tailwind has two kinds of line height classes. The named ones are relative to the font size: leading-tight (1.25), leading-normal (1.5) and leading-relaxed (1.625). Numbered ones like leading-7 are a fixed height from the spacing scale (1.75rem). I like a little more space between lines and pick leading-relaxed:
<body class="text-base leading-relaxed font-normal">...</body>In v4 you can also set both at once with a slash: text-base/7 is 16px text on a 1.75rem line.
Text color
The last default is the text color. You likely want one from the gray scales in the Tailwind color palette: a dark gray like text-gray-800 for a light theme, a light gray like text-gray-200 for a dark one. With the dark: variant you can set both:
<body class="text-base leading-relaxed text-gray-800 dark:bg-gray-950 dark:text-gray-200">...</body>With the defaults in place, it’s time to fine-tune specific elements like headings and buttons.
Styling page headings and other elements#
Different font sizes show the hierarchy of a page and let people scan its outline. So headings should be larger than the body text, which shows where a new section starts.
Headings
For a heading we want a larger font size, a heavier weight, a tighter line height and a darker gray. Four classes do that:
<h1 class="text-3xl leading-tight font-bold text-gray-900">...</h1>Apply the same principle to the other headings. They don’t all have to look the same:
<h1 class="text-4xl leading-tight font-medium text-blue-600">...</h1>
<h2 class="text-2xl leading-tight font-bold text-gray-900">...</h2>
<h3 class="text-xl leading-tight font-bold text-gray-900">...</h3>Hyperlinks & buttons
Links and buttons should also look different from the text around them. Style them the same way:
<a href="/pricing/" class="text-green-700 underline-offset-4 hover:underline">...</a>A button needs a few more classes:
<button type="button" class="inline-block rounded-lg bg-green-600 px-3 py-2 font-medium text-white hover:bg-green-700">...</button>bg-green-600 sets the background color, text-white the text color, py-2 the padding at the top and bottom, px-3 the padding left and right, and rounded-lg the border radius. If you know CSS, you can usually guess the matching Tailwind class.
Set defaults for content from a CMS#
Utility classes are great for developers but cumbersome for writers. You don’t want anybody to add classes to every heading or paragraph they write. For content you don’t control, such as text from a CMS or a markdown file, the makers of Tailwind CSS have a plugin.
Tailwind CSS typography plugin
Install the plugin with npm:
npm install -D @tailwindcss/typographyIn Tailwind v4 you register it in your CSS file, right after the import of Tailwind:
@import "tailwindcss";
@plugin "@tailwindcss/typography";That gives you the prose class. Put it on the element that holds the content and everything inside is styled, without a class on each tag:
<article class="prose">
<h2>This h2 is styled by the prose class</h2>
<p>So is this paragraph</p>
<ul>
<li>And this list item</li>
</ul>
</article>Change the default styling
To bring the prose styles closer to your brand, you no longer need a config file. The plugin has three ways to change them, from small to large.
A gray scale. Prose uses prose-gray by default. Add prose-slate, prose-zinc, prose-neutral or prose-stone to match the gray of the rest of your site, and dark:prose-invert for dark mode:
<article class="prose prose-zinc dark:prose-invert">...</article>Element modifiers. To change one element, use a prose-* modifier with any utility. This sets the heading and link colors from the 2021 version of this post:
<article class="prose prose-headings:text-gray-800 prose-a:text-green-700 prose-a:hover:text-green-800 prose-strong:text-gray-800">...</article>Raw CSS. For bigger changes the plugin README still uses the JavaScript theme API: a typography key in a tailwind.config.js, as in the old version of this post. Tailwind v4 doesn’t read that file by itself, so load it from your CSS with @config "./tailwind.config.js";. See the plugin’s README for all options.
When to use prose and when not
You might wonder when to use prose and when to style elements yourself with classes like text-xl and text-gray-800. I use prose only for content from a blog, a long article or a product description. For everything else I prefer the other utility classes, because they give finer control.
Different typographic defaults for mobile#
Every utility class in Tailwind can be applied at a breakpoint, so different defaults for mobile are easy.
Say you want smaller text and headings on mobile, so more content fits on the screen. Start with the body.
Responsive body classes
<body class="text-sm leading-normal text-gray-800 md:text-base md:leading-relaxed">...</body>Breakpoints in Tailwind CSS are mobile first: classes without a prefix apply to every screen, and prefixed classes take over from that width up. Here text-sm and leading-normal are for small screens, and from the md breakpoint (768px) md:text-base and md:leading-relaxed bring back the defaults from before.
Responsive headings and CMS content
The same goes for headings:
<h1 class="text-xl leading-tight font-bold text-gray-900 md:text-2xl lg:text-3xl">...</h1>Three classes control the font size here: text-xl, md:text-2xl and lg:text-3xl, an extra step up at the lg breakpoint. For the CMS content, the typography plugin has size classes that work at breakpoints too:
<article class="prose md:prose-lg">...</article>Be careful not to micro-manage font sizes. Get the basics in place first, then fill the site with real content. With the content in place, scan the page for anything that looks off and fine-tune that.
Conclusion#
Getting typography right is a difficult and time-consuming job. With a few theme variables, utility classes on the body and the official typography plugin for content, Tailwind CSS covers the common cases and leaves you time to fine-tune. If you’d rather start from components that are already styled, the free themes.dev UI library has components and page sections for React, Astro and plain HTML, built with Tailwind CSS v4.