Loading lessons...
Utilities
Utilities
Utilities are small classes for common styles like spacing, borders, shadows, and sizing. They let you style elements without writing custom CSS.
Spacing
Spacing utilities control margin (m-) and padding (p-) on all sides or a single side.
| Class | Meaning |
|---|---|
m-3 | margin on all sides |
mt-3 | margin top |
mb-3 | margin bottom |
ms-3 | margin start (left) |
me-3 | margin end (right) |
p-3 | padding on all sides |
py-3 | padding top and bottom |
px-3 | padding left and right |
The number at the end goes from 0 to 5. For example, p-5 is large padding, m-0 is no margin.
<div class="mt-4 p-5 bg-primary text-white">Spaced box</div>
Borders
.borderadds a border..border-top,.border-bottom,.border-start,.border-endadd one side..border-0removes borders..roundedrounds corners;.rounded-circlemakes a circle.
<div class="border border-primary p-3">Bordered box</div>
Shadows
.shadowa normal shadow..shadow-sma small shadow..shadow-lga large shadow..shadow-noneno shadow.
<div class="shadow-lg p-3 mb-5 bg-white rounded">Large shadow</div>
Sizing
.w-25,.w-50,.w-75,.w-100set width..h-25,.h-50,.h-75,.h-100set height..mw-100sets max-width to 100%.
<div class="w-50 bg-success text-white">50% wide</div>
Display
.d-blockdisplay block..d-inlinedisplay inline..d-flexdisplay flex..d-nonehides the element..d-md-blockdisplay changes at the md breakpoint.
TL;DR
m-/p-control margin and padding..borderand.roundedhandle borders and corners..shadow*adds shadows..w-and.h-set sizing..d-*controls display.