Quick reference

Class
Properties
m-0margin: 0px;
mx-0margin-left: 0px; margin-right: 0px;
my-0margin-top: 0px; margin-bottom: 0px;
mt-0margin-top: 0px;
mr-0margin-right: 0px;
mb-0margin-bottom: 0px;
ml-0margin-left: 0px;
m-pxmargin: 1px;
mx-pxmargin-left: 1px; margin-right: 1px;
my-pxmargin-top: 1px; margin-bottom: 1px;
mt-pxmargin-top: 1px;
mr-pxmargin-right: 1px;
mb-pxmargin-bottom: 1px;
ml-pxmargin-left: 1px;
m-0.5margin: 0.125rem; /* 2px */
mx-0.5margin-left: 0.125rem; /* 2px */ margin-right: 0.125rem; /* 2px */
my-0.5margin-top: 0.125rem; /* 2px */ margin-bottom: 0.125rem; /* 2px */
mt-0.5margin-top: 0.125rem; /* 2px */
mr-0.5margin-right: 0.125rem; /* 2px */
mb-0.5margin-bottom: 0.125rem; /* 2px */
ml-0.5margin-left: 0.125rem; /* 2px */
m-1margin: 0.25rem; /* 4px */
mx-1margin-left: 0.25rem; /* 4px */ margin-right: 0.25rem; /* 4px */
my-1margin-top: 0.25rem; /* 4px */ margin-bottom: 0.25rem; /* 4px */
mt-1margin-top: 0.25rem; /* 4px */
mr-1margin-right: 0.25rem; /* 4px */
mb-1margin-bottom: 0.25rem; /* 4px */
ml-1margin-left: 0.25rem; /* 4px */
m-1.5margin: 0.375rem; /* 6px */
mx-1.5margin-left: 0.375rem; /* 6px */ margin-right: 0.375rem; /* 6px */
my-1.5margin-top: 0.375rem; /* 6px */ margin-bottom: 0.375rem; /* 6px */
mt-1.5margin-top: 0.375rem; /* 6px */
mr-1.5margin-right: 0.375rem; /* 6px */
mb-1.5margin-bottom: 0.375rem; /* 6px */
ml-1.5margin-left: 0.375rem; /* 6px */
m-2margin: 0.5rem; /* 8px */
mx-2margin-left: 0.5rem; /* 8px */ margin-right: 0.5rem; /* 8px */
my-2margin-top: 0.5rem; /* 8px */ margin-bottom: 0.5rem; /* 8px */
mt-2margin-top: 0.5rem; /* 8px */
mr-2margin-right: 0.5rem; /* 8px */
mb-2margin-bottom: 0.5rem; /* 8px */
ml-2margin-left: 0.5rem; /* 8px */
m-2.5margin: 0.625rem; /* 10px */
mx-2.5margin-left: 0.625rem; /* 10px */ margin-right: 0.625rem; /* 10px */
my-2.5margin-top: 0.625rem; /* 10px */ margin-bottom: 0.625rem; /* 10px */
mt-2.5margin-top: 0.625rem; /* 10px */
mr-2.5margin-right: 0.625rem; /* 10px */
mb-2.5margin-bottom: 0.625rem; /* 10px */
ml-2.5margin-left: 0.625rem; /* 10px */
m-3margin: 0.75rem; /* 12px */
mx-3margin-left: 0.75rem; /* 12px */ margin-right: 0.75rem; /* 12px */
my-3margin-top: 0.75rem; /* 12px */ margin-bottom: 0.75rem; /* 12px */
mt-3margin-top: 0.75rem; /* 12px */
mr-3margin-right: 0.75rem; /* 12px */
mb-3margin-bottom: 0.75rem; /* 12px */
ml-3margin-left: 0.75rem; /* 12px */
m-3.5margin: 0.875rem; /* 14px */
mx-3.5margin-left: 0.875rem; /* 14px */ margin-right: 0.875rem; /* 14px */
my-3.5margin-top: 0.875rem; /* 14px */ margin-bottom: 0.875rem; /* 14px */
mt-3.5margin-top: 0.875rem; /* 14px */
mr-3.5margin-right: 0.875rem; /* 14px */
mb-3.5margin-bottom: 0.875rem; /* 14px */
ml-3.5margin-left: 0.875rem; /* 14px */
m-4margin: 1rem; /* 16px */
mx-4margin-left: 1rem; /* 16px */ margin-right: 1rem; /* 16px */
my-4margin-top: 1rem; /* 16px */ margin-bottom: 1rem; /* 16px */
mt-4margin-top: 1rem; /* 16px */
mr-4margin-right: 1rem; /* 16px */
mb-4margin-bottom: 1rem; /* 16px */
ml-4margin-left: 1rem; /* 16px */
m-5margin: 1.25rem; /* 20px */
mx-5margin-left: 1.25rem; /* 20px */ margin-right: 1.25rem; /* 20px */
my-5margin-top: 1.25rem; /* 20px */ margin-bottom: 1.25rem; /* 20px */
mt-5margin-top: 1.25rem; /* 20px */
mr-5margin-right: 1.25rem; /* 20px */
mb-5margin-bottom: 1.25rem; /* 20px */
ml-5margin-left: 1.25rem; /* 20px */
m-6margin: 1.5rem; /* 24px */
mx-6margin-left: 1.5rem; /* 24px */ margin-right: 1.5rem; /* 24px */
my-6margin-top: 1.5rem; /* 24px */ margin-bottom: 1.5rem; /* 24px */
mt-6margin-top: 1.5rem; /* 24px */
mr-6margin-right: 1.5rem; /* 24px */
mb-6margin-bottom: 1.5rem; /* 24px */
ml-6margin-left: 1.5rem; /* 24px */
m-7margin: 1.75rem; /* 28px */
mx-7margin-left: 1.75rem; /* 28px */ margin-right: 1.75rem; /* 28px */
my-7margin-top: 1.75rem; /* 28px */ margin-bottom: 1.75rem; /* 28px */
mt-7margin-top: 1.75rem; /* 28px */
mr-7margin-right: 1.75rem; /* 28px */
mb-7margin-bottom: 1.75rem; /* 28px */
ml-7margin-left: 1.75rem; /* 28px */
m-8margin: 2rem; /* 32px */
mx-8margin-left: 2rem; /* 32px */ margin-right: 2rem; /* 32px */
my-8margin-top: 2rem; /* 32px */ margin-bottom: 2rem; /* 32px */
mt-8margin-top: 2rem; /* 32px */
mr-8margin-right: 2rem; /* 32px */
mb-8margin-bottom: 2rem; /* 32px */
ml-8margin-left: 2rem; /* 32px */
m-9margin: 2.25rem; /* 36px */
mx-9margin-left: 2.25rem; /* 36px */ margin-right: 2.25rem; /* 36px */
my-9margin-top: 2.25rem; /* 36px */ margin-bottom: 2.25rem; /* 36px */
mt-9margin-top: 2.25rem; /* 36px */
mr-9margin-right: 2.25rem; /* 36px */
mb-9margin-bottom: 2.25rem; /* 36px */
ml-9margin-left: 2.25rem; /* 36px */
m-10margin: 2.5rem; /* 40px */
mx-10margin-left: 2.5rem; /* 40px */ margin-right: 2.5rem; /* 40px */
my-10margin-top: 2.5rem; /* 40px */ margin-bottom: 2.5rem; /* 40px */
mt-10margin-top: 2.5rem; /* 40px */
mr-10margin-right: 2.5rem; /* 40px */
mb-10margin-bottom: 2.5rem; /* 40px */
ml-10margin-left: 2.5rem; /* 40px */
m-11margin: 2.75rem; /* 44px */
mx-11margin-left: 2.75rem; /* 44px */ margin-right: 2.75rem; /* 44px */
my-11margin-top: 2.75rem; /* 44px */ margin-bottom: 2.75rem; /* 44px */
mt-11margin-top: 2.75rem; /* 44px */
mr-11margin-right: 2.75rem; /* 44px */
mb-11margin-bottom: 2.75rem; /* 44px */
ml-11margin-left: 2.75rem; /* 44px */
m-12margin: 3rem; /* 48px */
mx-12margin-left: 3rem; /* 48px */ margin-right: 3rem; /* 48px */
my-12margin-top: 3rem; /* 48px */ margin-bottom: 3rem; /* 48px */
mt-12margin-top: 3rem; /* 48px */
mr-12margin-right: 3rem; /* 48px */
mb-12margin-bottom: 3rem; /* 48px */
ml-12margin-left: 3rem; /* 48px */
m-14margin: 3.5rem; /* 56px */
mx-14margin-left: 3.5rem; /* 56px */ margin-right: 3.5rem; /* 56px */
my-14margin-top: 3.5rem; /* 56px */ margin-bottom: 3.5rem; /* 56px */
mt-14margin-top: 3.5rem; /* 56px */
mr-14margin-right: 3.5rem; /* 56px */
mb-14margin-bottom: 3.5rem; /* 56px */
ml-14margin-left: 3.5rem; /* 56px */
m-16margin: 4rem; /* 64px */
mx-16margin-left: 4rem; /* 64px */ margin-right: 4rem; /* 64px */
my-16margin-top: 4rem; /* 64px */ margin-bottom: 4rem; /* 64px */
mt-16margin-top: 4rem; /* 64px */
mr-16margin-right: 4rem; /* 64px */
mb-16margin-bottom: 4rem; /* 64px */
ml-16margin-left: 4rem; /* 64px */
m-20margin: 5rem; /* 80px */
mx-20margin-left: 5rem; /* 80px */ margin-right: 5rem; /* 80px */
my-20margin-top: 5rem; /* 80px */ margin-bottom: 5rem; /* 80px */
mt-20margin-top: 5rem; /* 80px */
mr-20margin-right: 5rem; /* 80px */
mb-20margin-bottom: 5rem; /* 80px */
ml-20margin-left: 5rem; /* 80px */
m-24margin: 6rem; /* 96px */
mx-24margin-left: 6rem; /* 96px */ margin-right: 6rem; /* 96px */
my-24margin-top: 6rem; /* 96px */ margin-bottom: 6rem; /* 96px */
mt-24margin-top: 6rem; /* 96px */
mr-24margin-right: 6rem; /* 96px */
mb-24margin-bottom: 6rem; /* 96px */
ml-24margin-left: 6rem; /* 96px */
m-28margin: 7rem; /* 112px */
mx-28margin-left: 7rem; /* 112px */ margin-right: 7rem; /* 112px */
my-28margin-top: 7rem; /* 112px */ margin-bottom: 7rem; /* 112px */
mt-28margin-top: 7rem; /* 112px */
mr-28margin-right: 7rem; /* 112px */
mb-28margin-bottom: 7rem; /* 112px */
ml-28margin-left: 7rem; /* 112px */
m-32margin: 8rem; /* 128px */
mx-32margin-left: 8rem; /* 128px */ margin-right: 8rem; /* 128px */
my-32margin-top: 8rem; /* 128px */ margin-bottom: 8rem; /* 128px */
mt-32margin-top: 8rem; /* 128px */
mr-32margin-right: 8rem; /* 128px */
mb-32margin-bottom: 8rem; /* 128px */
ml-32margin-left: 8rem; /* 128px */
m-36margin: 9rem; /* 144px */
mx-36margin-left: 9rem; /* 144px */ margin-right: 9rem; /* 144px */
my-36margin-top: 9rem; /* 144px */ margin-bottom: 9rem; /* 144px */
mt-36margin-top: 9rem; /* 144px */
mr-36margin-right: 9rem; /* 144px */
mb-36margin-bottom: 9rem; /* 144px */
ml-36margin-left: 9rem; /* 144px */
m-40margin: 10rem; /* 160px */
mx-40margin-left: 10rem; /* 160px */ margin-right: 10rem; /* 160px */
my-40margin-top: 10rem; /* 160px */ margin-bottom: 10rem; /* 160px */
mt-40margin-top: 10rem; /* 160px */
mr-40margin-right: 10rem; /* 160px */
mb-40margin-bottom: 10rem; /* 160px */
ml-40margin-left: 10rem; /* 160px */
m-44margin: 11rem; /* 176px */
mx-44margin-left: 11rem; /* 176px */ margin-right: 11rem; /* 176px */
my-44margin-top: 11rem; /* 176px */ margin-bottom: 11rem; /* 176px */
mt-44margin-top: 11rem; /* 176px */
mr-44margin-right: 11rem; /* 176px */
mb-44margin-bottom: 11rem; /* 176px */
ml-44margin-left: 11rem; /* 176px */
m-48margin: 12rem; /* 192px */
mx-48margin-left: 12rem; /* 192px */ margin-right: 12rem; /* 192px */
my-48margin-top: 12rem; /* 192px */ margin-bottom: 12rem; /* 192px */
mt-48margin-top: 12rem; /* 192px */
mr-48margin-right: 12rem; /* 192px */
mb-48margin-bottom: 12rem; /* 192px */
ml-48margin-left: 12rem; /* 192px */
m-52margin: 13rem; /* 208px */
mx-52margin-left: 13rem; /* 208px */ margin-right: 13rem; /* 208px */
my-52margin-top: 13rem; /* 208px */ margin-bottom: 13rem; /* 208px */
mt-52margin-top: 13rem; /* 208px */
mr-52margin-right: 13rem; /* 208px */
mb-52margin-bottom: 13rem; /* 208px */
ml-52margin-left: 13rem; /* 208px */
m-56margin: 14rem; /* 224px */
mx-56margin-left: 14rem; /* 224px */ margin-right: 14rem; /* 224px */
my-56margin-top: 14rem; /* 224px */ margin-bottom: 14rem; /* 224px */
mt-56margin-top: 14rem; /* 224px */
mr-56margin-right: 14rem; /* 224px */
mb-56margin-bottom: 14rem; /* 224px */
ml-56margin-left: 14rem; /* 224px */
m-60margin: 15rem; /* 240px */
mx-60margin-left: 15rem; /* 240px */ margin-right: 15rem; /* 240px */
my-60margin-top: 15rem; /* 240px */ margin-bottom: 15rem; /* 240px */
mt-60margin-top: 15rem; /* 240px */
mr-60margin-right: 15rem; /* 240px */
mb-60margin-bottom: 15rem; /* 240px */
ml-60margin-left: 15rem; /* 240px */
m-64margin: 16rem; /* 256px */
mx-64margin-left: 16rem; /* 256px */ margin-right: 16rem; /* 256px */
my-64margin-top: 16rem; /* 256px */ margin-bottom: 16rem; /* 256px */
mt-64margin-top: 16rem; /* 256px */
mr-64margin-right: 16rem; /* 256px */
mb-64margin-bottom: 16rem; /* 256px */
ml-64margin-left: 16rem; /* 256px */
m-72margin: 18rem; /* 288px */
mx-72margin-left: 18rem; /* 288px */ margin-right: 18rem; /* 288px */
my-72margin-top: 18rem; /* 288px */ margin-bottom: 18rem; /* 288px */
mt-72margin-top: 18rem; /* 288px */
mr-72margin-right: 18rem; /* 288px */
mb-72margin-bottom: 18rem; /* 288px */
ml-72margin-left: 18rem; /* 288px */
m-80margin: 20rem; /* 320px */
mx-80margin-left: 20rem; /* 320px */ margin-right: 20rem; /* 320px */
my-80margin-top: 20rem; /* 320px */ margin-bottom: 20rem; /* 320px */
mt-80margin-top: 20rem; /* 320px */
mr-80margin-right: 20rem; /* 320px */
mb-80margin-bottom: 20rem; /* 320px */
ml-80margin-left: 20rem; /* 320px */
m-96margin: 24rem; /* 384px */
mx-96margin-left: 24rem; /* 384px */ margin-right: 24rem; /* 384px */
my-96margin-top: 24rem; /* 384px */ margin-bottom: 24rem; /* 384px */
mt-96margin-top: 24rem; /* 384px */
mr-96margin-right: 24rem; /* 384px */
mb-96margin-bottom: 24rem; /* 384px */
ml-96margin-left: 24rem; /* 384px */
m-automargin: auto;
mx-automargin-left: auto; margin-right: auto;
my-automargin-top: auto; margin-bottom: auto;
mt-automargin-top: auto;
mr-automargin-right: auto;
mb-automargin-bottom: auto;
ml-automargin-left: auto;

Basic usage

Add margin to a single side

Control the margin on one side of an element using the m{t|r|b|l}-{size} utilities.

For example, mt-6 would add 1.5rem of margin to the top of an element, mr-4 would add 1rem of margin to the right of an element, mb-8 would add 2rem of margin to the bottom of an element, and ml-2 would add 0.5rem of margin to the left of an element.

mt-6
mr-4
mb-8
ml-2
<div class="mt-6 ...">mt-6</div>
<div class="mr-4 ...">mr-4</div>
<div class="mb-8 ...">mb-8</div>
<div class="ml-2 ...">ml-2</div>

Add horizontal margin

Control the horizontal margin of an element using the mx-{size} utilities.

mx-8
<div class="mx-8 ...">mx-8</div>

Add vertical margin

Control the vertical margin of an element using the my-{size} utilities.

my-8
<div class="my-8 ...">my-8</div>

Add margin to all sides

Control the margin on all sides of an element using the m-{size} utilities.

m-8
<div class="m-8 ...">m-8</div>

Using negative values

To use a negative margin value, prefix the class name with a dash to convert it to a negative value.

-mt-8
<div class="w-36 h-16 bg-sky-400 opacity-20 ..."></div>
<div class="-mt-8 bg-sky-300 ...">-mt-8</div>

Applying conditionally

Hover, focus, and other states

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:mt-8 to only apply the mt-8 utility on hover.

<div class="mt-4 hover:mt-8">
  <!-- ... -->
</div>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:mt-8 to apply the mt-8 utility at only medium screen sizes and above.

<div class="mt-4 md:mt-8">
  <!-- ... -->
</div>

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.


Using custom values

Customizing your theme

By default, Tailwind’s margin scale uses the default spacing scale. You can customize your spacing scale by editing theme.spacing or theme.extend.spacing in your tailwind.config.js file.

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      spacing: {
        '5px': '5px',
      }
    }
  }
}

Alternatively, you can customize just the margin scale by editing theme.margin or theme.extend.margin in your tailwind.config.js file.

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      margin: {
        '5px': '5px',
      }
    }
  }
}

Learn more about customizing the default theme in the theme customization documentation.

Arbitrary values

If you need to use a one-off margin value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.

<div class="m-[5px]">
  <!-- ... -->
</div>

Learn more about arbitrary value support in the arbitrary values documentation.