Skip to main content

Helpers

Stacks

Vertical and horizontal flex shortcuts with the theme's 4px gap scale.

How it works

.vstack and .hstack are one-class flex layouts. They are a shortcut, not a component: add gap utilities for spacing and flex utilities for anything they do not cover.

Remember the gap scale is nine steps on a 4px base: gap-1 = .25rem up to gap-8 = 4rem.

Vertical

.vstack stacks children top to bottom and stretches them full width. It also sets flex: 1 1 auto on itself, so it grows inside a parent flex container.

First item
Second item
Third item
HTML
<div class="vstack gap-3">
  <div class="p-2 bg-body-secondary border rounded-1">First item</div>
  <div class="p-2 bg-body-secondary border rounded-1">Second item</div>
  <div class="p-2 bg-body-secondary border rounded-1">Third item</div>
</div>

Horizontal

.hstack lays children left to right and centres them vertically. Use .ms-auto or .me-auto to push items apart.

First item
Second item
Third item
HTML
<div class="hstack gap-3">
  <div class="p-2 bg-body-secondary border rounded-1">First item</div>
  <div class="p-2 bg-body-secondary border rounded-1">Second item</div>
  <div class="p-2 bg-body-secondary border rounded-1">Third item</div>
</div>
First item
Second item
Third item
HTML
<div class="hstack gap-3">
  <div class="p-2 bg-body-secondary border rounded-1">First item</div>
  <div class="p-2 ms-auto bg-body-secondary border rounded-1">Second item</div>
  <div class="p-2 bg-body-secondary border rounded-1">Third item</div>
</div>

A vertical rule stretches to the row height inside a stack.

First item
Second item
Third item
HTML
<div class="hstack gap-3">
  <div class="p-2 bg-body-secondary border rounded-1">First item</div>
  <div class="p-2 ms-auto bg-body-secondary border rounded-1">Second item</div>
  <div class="vr"></div>
  <div class="p-2 bg-body-secondary border rounded-1">Third item</div>
</div>

Examples

A button stack, as you would use in a card or a confirm step.

HTML
<div class="vstack gap-2 col-md-5 mx-auto">
  <button type="button" class="btn btn-primary">Sign the contract</button>
  <button type="button" class="btn btn-outline-secondary">Read the fine print</button>
</div>

An inline form — the control grows, the buttons stay their natural width.

HTML
<div class="hstack gap-3">
  <label class="visually-hidden" for="stacks-search">Search the roster</label>
  <input class="form-control me-auto" type="text" id="stacks-search" placeholder="Search the roster…">
  <button type="button" class="btn btn-secondary">Submit</button>
  <div class="vr"></div>
  <button type="button" class="btn btn-outline-danger">Reset</button>
</div>

CSS

.hstack {
  display: flex;
  flex-direction: row;
  align-items: center;
  align-self: stretch;
}
.vstack {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-self: stretch;
}

There is no Sass option or mixin for stacks; they are two plain rules in Bootstrap's helpers/_stacks.scss. Drop the helpers import from your own entry file if you do not want them.