Overview
Use margin utilities to control the space around elements. Margins create space outside an element’s border, pushing other elements away. These utilities work with a consistent 4px scale and include both static and fluid variants for responsive designs.Spacing Scale
All margin utilities follow a consistent 4px scale for predictable layouts.Spacing Scale
| 0 | 0px | No spacing |
| 1 | 4px | Fine adjustments |
| 2 | 8px | Small spacing |
| 3 | 12px | Medium spacing |
| 4 | 16px | Standard spacing |
| 6 | 24px | Large spacing |
| 8 | 32px | Extra large spacing |
| 12 | 48px | Section spacing |
All Sides Margin
Apply margin to all sides of an element at once.All Sides Margin
.m-0 | 0 | margin: 0; | No margin |
.m-1 | 4px | margin: 4px; | Small margin |
.m-2 | 8px | margin: 8px; | Small margin |
.m-3 | 12px | margin: 12px; | Medium margin |
.m-4 | 16px | margin: 16px; | Standard margin |
.m-6 | 24px | margin: 24px; | Large margin |
.m-8 | 32px | margin: 32px; | Extra large margin |
.m-12 | 48px | margin: 48px; | Section margin |
.m-auto | Auto | margin: auto; | Center element |
Examples
Vertical Margin
Control top and bottom margins independently.Top Margin
Top Margin
.mt-0 | 0 | margin-top: 0; | No top margin |
.mt-1 | 4px | margin-top: 4px; | Small top margin |
.mt-2 | 8px | margin-top: 8px; | Small top margin |
.mt-3 | 12px | margin-top: 12px; | Medium top margin |
.mt-4 | 16px | margin-top: 16px; | Standard top margin |
.mt-6 | 24px | margin-top: 24px; | Large top margin |
.mt-8 | 32px | margin-top: 32px; | Extra large top margin |
.mt-12 | 48px | margin-top: 48px; | Section top margin |
Bottom Margin
Bottom Margin
.mb-0 | 0 | margin-bottom: 0; | No bottom margin |
.mb-1 | 4px | margin-bottom: 4px; | Small bottom margin |
.mb-2 | 8px | margin-bottom: 8px; | Small bottom margin |
.mb-3 | 12px | margin-bottom: 12px; | Medium bottom margin |
.mb-4 | 16px | margin-bottom: 16px; | Standard bottom margin |
.mb-6 | 24px | margin-bottom: 24px; | Large bottom margin |
.mb-8 | 32px | margin-bottom: 32px; | Extra large bottom margin |
.mb-12 | 48px | margin-bottom: 48px; | Section bottom margin |
Examples
Horizontal Margin
Control left and right margins, including auto margins for centering.Horizontal Margin
.ml-auto | Left auto | margin-left: auto; | Push element right |
.mr-auto | Right auto | margin-right: auto; | Push element left |
Examples
Fluid Margin
Fluid margin utilities useclamp() to scale smoothly between mobile and desktop sizes. They’re perfect for hero sections, marketing pages, and responsive layouts that need to adapt automatically.
All Sides Fluid Margin
Fluid Margin Utilities
| Class | Clamp Expression | Mobile → Desktop |
|---|---|---|
.m-fluid-1 | clamp(0.25rem, calc(0.21rem + 0.09vw), 0.31rem) | 4px → 5px |
.m-fluid-2 | clamp(0.5rem, calc(0.43rem + 0.18vw), 0.63rem) | 8px → 10px |
.m-fluid-3 | clamp(0.75rem, calc(0.64rem + 0.27vw), 0.94rem) | 12px → 15px |
.m-fluid-4 | clamp(1rem, calc(0.85rem + 0.37vw), 1.25rem) | 16px → 20px |
.m-fluid-6 | clamp(1.5rem, calc(1.28rem + 0.56vw), 1.88rem) | 24px → 30px |
.m-fluid-8 | clamp(2rem, calc(1.71rem + 0.74vw), 2.5rem) | 32px → 40px |
.m-fluid-12 | clamp(3rem, calc(2.56rem + 1.1vw), 3.75rem) | 48px → 60px |
Fluid Margin Top/Bottom
Fluid Margin Top
| Class | Clamp Expression | Mobile → Desktop |
|---|---|---|
.mt-fluid-1 | clamp(0.25rem, calc(0.21rem + 0.09vw), 0.31rem) | 4px → 5px |
.mt-fluid-2 | clamp(0.5rem, calc(0.43rem + 0.18vw), 0.63rem) | 8px → 10px |
.mt-fluid-3 | clamp(0.75rem, calc(0.64rem + 0.27vw), 0.94rem) | 12px → 15px |
.mt-fluid-4 | clamp(1rem, calc(0.85rem + 0.37vw), 1.25rem) | 16px → 20px |
.mt-fluid-6 | clamp(1.5rem, calc(1.28rem + 0.56vw), 1.88rem) | 24px → 30px |
.mt-fluid-8 | clamp(2rem, calc(1.71rem + 0.74vw), 2.5rem) | 32px → 40px |
.mt-fluid-12 | clamp(3rem, calc(2.56rem + 1.1vw), 3.75rem) | 48px → 60px |
Fluid Margin Bottom
| Class | Clamp Expression | Mobile → Desktop |
|---|---|---|
.mb-fluid-1 | clamp(0.25rem, calc(0.21rem + 0.09vw), 0.31rem) | 4px → 5px |
.mb-fluid-2 | clamp(0.5rem, calc(0.43rem + 0.18vw), 0.63rem) | 8px → 10px |
.mb-fluid-3 | clamp(0.75rem, calc(0.64rem + 0.27vw), 0.94rem) | 12px → 15px |
.mb-fluid-4 | clamp(1rem, calc(0.85rem + 0.37vw), 1.25rem) | 16px → 20px |
.mb-fluid-6 | clamp(1.5rem, calc(1.28rem + 0.56vw), 1.88rem) | 24px → 30px |
.mb-fluid-8 | clamp(2rem, calc(1.71rem + 0.74vw), 2.5rem) | 32px → 40px |
.mb-fluid-12 | clamp(3rem, calc(2.56rem + 1.1vw), 3.75rem) | 48px → 60px |
Fluid Margin Examples
Common Margin Patterns
Section Spacing
Centered Content
Form Field Spacing
Best Practices
1
Use the 4px Scale
Always use the predefined spacing scale (1, 2, 3, 4, 6, 8, 12) for consistency.
2
Maintain Vertical Rhythm
Use consistent spacing between related elements for better visual flow.
3
Use Auto for Centering
Use
.ml-auto, .mr-auto, or both for horizontal centering instead of manual calculations.4
Consider Mobile
Use fluid margins for responsive designs that need to scale smoothly across breakpoints.
Common Mistakes
- Don’t use margin for spacing between flex items (use gap instead)
- Don’t mix different spacing scales inconsistently
- Don’t forget to consider mobile spacing needs
- Don’t overuse auto margins for centering (use flexbox utilities when appropriate)

