Spacing

Tailwind CSS includes a wide range of shorthand responsive margin, padding, and gap utility classes to modify an element’s appearance.

Spacing on Tailwind

Margin 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 set margin
  • p - for classes that set padding

Wheresides is one of:

  • t - for classes that set margin-top or padding-top
  • b - for classes that set margin-bottom or padding-bottom
  • s - for classes that set margin-inline-start or padding-inline-start
  • e - for classes that set margin-inline-end or padding-inline-end
  • x - for classes that set margin-inline or padding-inline
  • y - for classes that set margin-block or padding-block
  • l - for classes that set margin-left or padding-left
  • r - for classes that set margin-right or padding-right
  • blank - for classes that set a margin or padding on 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>
Centered element

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>
Grid item 1
Grid item 2
Grid item 3

Thank you for creating with Phoenix Tailwind2026 ©ThemeWagon

v1.0.0-beta

Theme Customizer

Explore different styles according to your preferences

Color Scheme
RTL

Change text direction

Support Chat

Toggle support chat

Navigation Type
Vertical Navbar Appearance
Horizontal Navbar Shape
Horizontal Navbar Appearance
Purchase template
customize