Custom Spacing and Sizing Scales
What you'll learn: How to add project-specific spacing values and sizing scales to complement Tailwind's default spacing system.
The Core Idea
Tailwind comes with a well-thought-out default spacing scale (0, 1, 2, 3, 4, etc., where each unit equals 0.25rem). But your project might have unique design requirements—perhaps your design system uses 18px gaps or 72px sections. Instead of using arbitrary values repeatedly with square brackets, you can extend Tailwind's configuration to include your custom values, making them reusable and consistent across your codebase.
How It Works
In your tailwind.config.js file, you extend the spacing key under theme to add custom values alongside the defaults. These values become available across all spacing utilities: margin (m-*), padding (p-*), gap (gap-*), and more.
For sizing specifically (width and height), you can extend width or height separately if you need unique sizing values that differ from your spacing scale.
Example configuration:
module.exports = {
theme: {
extend: {
spacing: {
'18': '4.5rem', // 72px
'128': '32rem', // 512px
'gutter': '1.875rem' // 30px, named value
},
width: {
'sidebar': '280px'
}
}
}
}
Now you can use mt-18, p-gutter, or w-sidebar throughout your HTML just like built-in utilities.
Why This Matters
Think of this like adding custom paint colors to a standard palette. You're not replacing the basics—you're augmenting them with values that match your specific design language, ensuring consistency without sacrificing Tailwind's utility-first philosophy.
Key Takeaway: Custom spacing and sizing scales let you encode your design system's unique measurements directly into Tailwind's configuration, creating reusable utilities that maintain consistency across your entire project.