Spacing
Tailwind CSS includes a wide range of shorthand responsive margin, padding, and gap utility classes to modify an element’s appearance.
Spacing on TailwindMargin and padding
Assign responsive-friendly margin or padding values to an element or a subset of its sides with shorthand classes. Includes support for individual properties, all properties, and vertical and horizontal properties.
Using the CSS Grid layout module? Consider using the gap utility
Notations
Spacing utilities that apply to all breakpoints, from xs to 2xl, have no breakpoint abbreviation in them. This is because those classes are applied from min-width: 0 and up, and thus are not bound by a media query. The remaining breakpoints, however, do include a breakpoint abbreviation.
The classes are named using the format {property}{sides}-{size} for xs and {breakpoint}:{property}{sides}-{size} for sm,md,lg,xl and 2xl.
Where property is one of:
m- for classes that setmarginp- for classes that setpadding
Wheresides is one of:
t- for classes that setmargin-toporpadding-topb- for classes that setmargin-bottomorpadding-bottoms- for classes that setmargin-inline-startorpadding-inline-starte- for classes that setmargin-inline-endorpadding-inline-endx- for classes that setmargin-inlineorpadding-inliney- for classes that setmargin-blockorpadding-blockl- for classes that setmargin-leftorpadding-leftr- for classes that setmargin-rightorpadding-right- blank - for classes that set a
marginorpaddingon all 4 sides of the element
Horizontal centering
Additionally, Tailwind also includes an .mx-auto class for horizontally centering fixed-width block level content—that is, content that has display: block and a width set—by setting the horizontal margins to auto.
<div class="mx-auto bg-body-highlight w-50">Centered element</div>
Negative margins
For negative margins, use - prefix before the size.
.-mt-5 {
margin-top: calc(var(--spacing) * -5);
}
Gap
When using display: grid, you can make use of gap utilities on the parent grid container. This can save on having to add margin utilities to individual grid items (children of a display: grid container). Gap utilities are responsive by default, and are generated via our utilities API.
<div class="grid gap-4">
<div class="p-2 bg-body-highlight border border-translucent">Grid item 1</div>
<div class="p-2 bg-body-highlight border border-translucent">Grid item 2</div>
<div class="p-2 bg-body-highlight border border-translucent">Grid item 3</div>
</div>

