margin-top

Sets the outer spacing on the top side of an element. Use the prefix mt followed by a value with unit. Commonly used for vertical spacing between sections and gaps between headings and body text.

Class Patterns

Prefix mt + value + unit. Use px for values under 20px, and rem (1rem = 10px) for 20px and above.

ClassCSS OutputDescription
mt4pxmargin-top: 4pxminimum spacing
mt8pxmargin-top: 8pxnarrow spacing
mt12pxmargin-top: 12pxdefault spacing
mt16pxmargin-top: 16pxgenerous spacing
mt2remmargin-top: 2rem (20px)rem unit starting point
mt2-4remmargin-top: 2.4rem (24px)decimals expressed with hyphens
mt3-2remmargin-top: 3.2rem (32px)wide spacing
mt4remmargin-top: 4rem (40px)spacing between sections
mtamargin-top: autoauto margin (for flexbox/grid alignment)

Unit Comparison

Comparison of the same size expressed in px and rem. Based on: html { font-size: 10px }

Sizepx Classrem Class
8pxmt8pxmt0-8rem
12pxmt12pxmt1-2rem
16pxmt16pxmt1-6rem
20pxmt20pxmt2rem
24pxmt24pxmt2-4rem
32pxmt32pxmt3-2rem
40pxmt40pxmt4rem

Common Values

ClassActual SizeUsage
mt4px4pxFine-tune inline elements
mt8px8pxNarrow gap between paragraphs
mt16px16pxBetween heading and body
mt2-4rem24pxGap between subsections
mt4rem40pxGap between major sections
mt4-8rem48pxPage major section separator

Code Examples

<!-- Section Title Gap -->
<h2 class="mt4rem mb16px">Section Title</h2>
<p>Section body content</p>

<!-- List item gap -->
<ul>
  <li>First Item</li>
  <li class="mt8px">Second Item</li>
  <li class="mt8px">Third Item</li>
</ul>

<!-- Responsive Gap -->
<section class="mt4-8rem sm-mt2-4rem">
  Desktop 48px, mobile 24px top gap
</section>

Auto Value

mta applies margin-top: auto. Used to push elements downward in flex containers.

<!-- Push footer down in flex container -->
<div class="df fdc h100vh">
  <header class="p2rem">Header</header>
  <main class="p2rem">Content</main>
  <footer class="mta p2rem">Always at bottom</footer>
</div>

Negative Margin (neg- prefix)

neg-mt applies negative margin-top. Used to pull elements upward or create overlap effects.

ClassCSSDescription
neg-mt8pxmargin-top: -8pxpull up 8px
neg-mt10pxmargin-top: -10pxpull up 10px
neg-mt2remmargin-top: -2rempull up 20px
<!-- Pull element up to overlap -->
<div class="bg6366F1 p4rem cFFFFFF">Top area</div>
<div class="neg-mt2rem mxa maxw40rem bg18181B p2rem br8px">
  Pulled up 20px, overlaps with top area
</div>

Tips & Notes

Margin Collapse

A block element's mt collapses with the previous element's mb. Only the larger value applies. Collapse does not occur inside flex/grid containers, so using gap is recommended.

Caution with neg-mt

Negative margin-top can cause elements to overlap into the area above. Without oh (overflow: hidden) on the parent, elements may overflow outside their bounds.