Margin

Utilities for controlling an element's margin.

On this page
ClassProperties
.m-0margin: 0;
.m-1margin: .25rem;
.m-2margin: .5rem;
.m-3margin: .75rem;
.m-4margin: 1rem;
.m-5margin: 1.5rem;
.m-6margin: 2rem;
.m-7margin: 3rem;
.m-8margin: 4rem;
.m-9margin: 6rem;
.-mt-1pxmargin-top: -1px;
.-mb-1pxmargin-bottom: -1px;

Usage

All sides

Use .m-{size} to apply margin on all sides of an element.

<div class="inline-block bg-gray-200">
  <div class="bg-gray-400 m-4"></div>
</div>
<div class="inline-block bg-gray-200">
  <div class="bg-gray-400 m-6"></div>
</div>
<div class="inline-block bg-gray-200">
  <div class="bg-gray-400 m-8"></div>
</div>

Specific sides

Use .m{t|r|b|l}-{size} to apply margin on a single side of an element.

<div class="inline-block bg-gray-200">
  <div class="bg-gray-400 ml-4"></div>
</div>
<div class="inline-block bg-gray-200">
  <div class="bg-gray-400 mr-4"></div>
</div>
<div class="inline-block bg-gray-200">
  <div class="bg-gray-400 mb-4"></div>
</div>

Use .mx-{size} to apply margin on the left and right (horizontal) sides of an element.

Use .my-{size} to apply margin on the top and bottom (vertical) sides of an element.

<div class="inline-block bg-gray-200">
  <div class="bg-gray-400 mx-4"></div>
</div>
<div class="inline-block bg-gray-200">
  <div class="bg-gray-400 my-4"></div>
</div>

Negative margin

Use .-m{side?}-{size} to apply negative margin.

<div class="p-4 bg-gray-200 w-8"></div>
<div class="p-4 bg-gray-400 w-6 -mt-4"></div>

Variants

By default, only responsive variants are generated for margin utilities.

Responsive

To control the margin for an element at a specific breakpoint, add a {screen}: prefix to any existing margin utility.

For example, use .md:m-4 to apply the m-4 utility at only medium screen sizes and above.

Hover-state

To include hover-state variants like .hover:m-4, add "margin" to the $hover-variants variable when recompiling your CSS:

$hover-variants: (
  // ...
  "margin",
);

Questions or feedback about this article? Let us know