Custom Typography Scales
What you'll learn: How to define your own font sizes, line heights, and letter spacing values in Tailwind's configuration to create a consistent, branded typography system.
Why Custom Typography Scales Matter
Out of the box, Tailwind provides sensible defaults like text-sm, text-base, text-lg, etc. But your design system might need specific sizes—perhaps your headings should be 42px instead of 48px, or you need precise line heights for better readability.
Think of a custom typography scale like a musical scale: instead of using random notes, you're defining a harmonious set of values that work together across your entire site.
Defining Custom Typography in tailwind.config.js
In your Tailwind configuration file, you can extend the fontSize theme property. Unlike simple spacing values, typography utilities can accept both size and line-height as a pair:
module.exports = {
theme: {
extend: {
fontSize: {
'display': ['4rem', '1.1'], // 64px, 110% line-height
'h1': ['2.5rem', '1.2'], // 40px, 120% line-height
'body': ['1rem', '1.6'], // 16px, 160% line-height
'caption': ['0.875rem', '1.4'], // 14px, 140% line-height
},
},
},
}
Now you can use classes like text-display or text-h1 throughout your HTML, ensuring every heading uses exactly the size and line-height your designer specified.
Adding Letter Spacing
You can also customize letterSpacing separately:
letterSpacing: {
'tighter': '-0.02em',
'relaxed': '0.05em',
}
Then combine: text-display tracking-tighter for a tight, modern headline.
Key Takeaway: Custom typography scales let you encode your design system's exact font sizes, line heights, and letter spacing into Tailwind's configuration, replacing generic utilities with branded, purpose-specific classes that ensure typographic consistency.