Default Spacing Scale
Tailwind provides a comprehensive default spacing scale:Adding Custom Spacing
Extend the spacing scale with custom values:Using Spacing Values
Spacing values are used across many utility types:Padding
Margin
Gap
Width & Height
Inset
Spacing Utilities
Spacing values work with these utility groups:spacing
p-*, px-*, py-*, pt-*, pr-*, pb-*, pl-*, ps-*, pe-*spacing
m-*, mx-*, my-*, mt-*, mr-*, mb-*, ml-*, ms-*, me-*Supports negative values: -m-*, -mt-*, etc.spacing
gap-*, gap-x-*, gap-y-*spacing
space-x-*, space-y-*Supports negative values: -space-x-*, -space-y-*spacing
w-*, min-w-*, max-w-*spacing
h-*, min-h-*, max-h-*spacing
size-* (sets both width and height)spacing
inset-*, top-*, right-*, bottom-*, left-*, start-*, end-*Supports negative values for allspacing
scroll-m-*, scroll-mx-*, scroll-my-*, scroll-mt-*, etc.spacing
scroll-p-*, scroll-px-*, scroll-py-*, scroll-pt-*, etc.Arbitrary Values
Use arbitrary values for one-off spacing:Replacing the Spacing Scale
Completely replace the default scale:Semantic Spacing
Create semantic spacing names:Fractional Spacing
The default scale includes fractional values:Dynamic Spacing with Functions
Create spacing values from the theme:tailwind.config.ts
Responsive Spacing
Combine spacing with responsive variants:Negative Spacing
Most spacing utilities support negative values:Best Practices
- Use the default scale - It’s designed to work well for most projects
- Add semantic names - For common spacing patterns in your design
- Maintain consistency - Stick to the scale instead of arbitrary values
- Use responsive variants - For better mobile-to-desktop experiences
The spacing scale is based on a
0.25rem (4px) increment, which provides good granularity while maintaining visual harmony. This is a common design system pattern.