Layout
Utilities for layout
The utility classes you reach for most when laying out a page — display, flex, spacing and visibility.
For faster, mobile-friendly and responsive development, the theme includes dozens of utility classes for showing, hiding, aligning and spacing content. This page is a map; each heading links to the full reference.
Changing display
Use the display utilities for responsively toggling common values
of the display property. Mix it with the grid system, content or components to show or hide
them across specific viewports.
HTML
<div class="d-inline border bg-body-tertiary p-2">d-inline</div>
<div class="d-inline border bg-body-tertiary p-2">d-inline</div>
<div class="d-block border bg-body-tertiary p-2 mt-2">d-block</div>
<div class="d-none d-md-block border bg-body-tertiary p-2 mt-2">d-none d-md-block — hidden below md</div>The pattern is .d-{value} for all breakpoints and .d-{breakpoint}-{value} from a breakpoint upward.
Flexbox options
The theme is built with flexbox, but not every element's display has been changed to
display: flex — that would add many unnecessary overrides and unexpectedly change key browser
behaviours. Most components are built with flexbox enabled.
Should you need to add display: flex to an element, do so with .d-flex or one of
the responsive variants (e.g. .d-sm-flex, .d-md-flex). You need this class or
display value to allow the use of the extra
flexbox utilities for sizing, alignment, spacing and more.
HTML
<div class="d-flex justify-content-between align-items-center gap-3 border bg-body-tertiary p-3">
<span>Challenger</span>
<span class="text-marquee fs-4">vs</span>
<span>Champion</span>
</div>The stack helpers (.vstack, .hstack) wrap the most common flex recipes in one class.
Margin and padding
Use the margin and padding utilities to control how elements and
components are spaced and sized. The scale is the theme's own: nine steps, 0 through 8, on a
4px base — not Bootstrap's six. .m-4 is 1rem; .m-8 is 4rem.
| Step | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|---|
| rem | 0 | .25 | .5 | .75 | 1 | 1.5 | 2 | 3 | 4 |
| px | 0 | 4 | 8 | 12 | 16 | 24 | 32 | 48 | 64 |
Spacing utilities are responsive (.mt-md-6), include auto margins
(.mx-auto) and, in this theme, negative margins are enabled:
.mt-n1 through .mt-n8 pull an element back by the same scale.
Content below, pushed down with .mt-4.
HTML
<div class="border bg-body-tertiary p-4">
<div class="border bg-body-secondary p-2 mt-n4 mx-n4">.mt-n4 .mx-n4 — hugs the parent's edges despite its padding</div>
<p class="mt-4 mb-0">Content below, pushed down with <code>.mt-4</code>.</p>
</div>
Gaps between flex and grid children use the same scale through .gap-{0–8},
.row-gap-* and .column-gap-*.
Toggle visibility
When toggling display is not needed, you can toggle the visibility of an element
with the visibility utilities. Invisible elements still take up
space, but are hidden from view and from assistive technology.
HTML
<div class="d-flex gap-2">
<div class="border bg-body-tertiary p-3">Visible</div>
<div class="invisible border bg-body-tertiary p-3">Invisible, but still here</div>
<div class="border bg-body-tertiary p-3">Visible</div>
</div>For content that should be read by screen readers but not seen, use the visually hidden helper instead.
Related pages
- Position —
.position-*,.top-0,.translate-middle; sticky and fixed helpers. - Sizing —
.w-25….w-100,.vh-100,.mw-100. - Overflow — keep wide gutters from spilling out of a container.
- Float and the clearfix.
- Z-index — the stacking scale and
.z-*. - Utility API — add your own, or extend the spacing map.