Spacing
Utilities for controlling an element's margin.
Class | Styles |
---|---|
m-<number> | margin: calc(var(--spacing) * <number>); |
mx-<number> | margin-inline: calc(var(--spacing) * <number>); |
my-<number> | margin-block: calc(var(--spacing) * <number>); |
ms-<number> | margin-inline-start: calc(var(--spacing) * <number>) |
me-<number> | margin-inline-end: calc(var(--spacing) * <number>) |
mt-<number> | margin-top: calc(var(--spacing) * <number>) |
mr-<number> | margin-right: calc(var(--spacing) * <number>) |
mb-<number> | margin-bottom: calc(var(--spacing) * <number>) |
ml-<number> | margin-left: calc(var(--spacing) * <number>) |
m-(<custom-property>) | margin: var(<custom-property>); |
m-[<value>] | margin: <value>; |
Use the mt-*
, mr-*
, mb-*
, and ml-*
utilities to control the margin on one side of an element.
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.
Use the mx-*
utilities to control the horizontal margin of an element:
Use the my-*
utilities to control the vertical margin of an element:
Use the m-*
utilities to control the margin on all sides of an element:
To use a negative margin value, prefix the class name with a dash to convert it to a negative value:
Use the ms-*
and me-*
utilities to set the margin-inline-start
and margin-inline-end
logical properties:
Use the margin-(<custom-property>)
syntax to set the margin based on a custom property:
<div class="margin-(--my-margin) ..."> <!-- ... --></div>
Use the margin-[<value>]
syntax to set the margin based on a completely custom value:
<div class="margin-[5px] ..."> <!-- ... --></div>
Prefix a margin
utility with a breakpoint variant like md:
to only apply the utility at medium screen sizes and above:
<div class="mt-4 md:mt-8"> <!-- ... --></div>
Learn more about using variants in the variants documentation.
Use the --margin-*
theme variables to customize the margin utilities in your project:
@theme { --margin-5px: 5px; }
Now the margin-5px
utility can be used in your markup:
<div class="margin-5px"> <!-- ... --></div>
Learn more about customizing your theme in the theme documentation.