Skip to main content

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.

d-inline
d-inline
d-block
d-none d-md-block — hidden below md
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.

Challenger vs Champion
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.

Step012345678
rem0.25.5.7511.5234
px048121624324864

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.

.mt-n4 .mx-n4 — hugs the parent's edges despite its padding

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.

Visible
Visible
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.