Flex
Flex utilities control flexbox layouts: direction, wrapping, alignment on both axes, growing, shrinking, order and gaps. Every utility has responsive variants such as flex-md-row or justify-content-lg-between, so one set of markup can stack on phones and spread out on larger screens.
1Direction
flex-row is the default, flex-row-reverse flips it, flex-column stacks items.
123123123<div class="d-grid gap-2">
<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2 flex-row">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">1</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">2</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">3</code>
</div>
</div>
<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2 flex-row-reverse">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">1</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">2</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">3</code>
</div>
</div>
<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2 flex-column">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">1</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">2</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">3</code>
</div>
</div>
</div>2Justify content
start, center, end, between, around and evenly distribute free space on the main axis.
ABABABABABAB<div class="d-grid gap-2">
<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2 justify-content-start">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">A</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">B</code>
</div>
</div>
<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2 justify-content-center">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">A</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">B</code>
</div>
</div>
<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2 justify-content-end">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">A</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">B</code>
</div>
</div>
<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2 justify-content-between">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">A</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">B</code>
</div>
</div>
<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2 justify-content-around">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">A</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">B</code>
</div>
</div>
<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2 justify-content-evenly">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">A</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">B</code>
</div>
</div>
</div>3Align items
align-items-start, -center, -end and -stretch align items on the cross axis.
startxstartxstartxstartx<div class="row g-2">
<div class="col-6 col-md-3">
<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2 align-items-start" style="height:100px">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">start</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">x</code>
</div>
</div>
</div>
<div class="col-6 col-md-3">
<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2 align-items-center" style="height:100px">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">start</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">x</code>
</div>
</div>
</div>
<div class="col-6 col-md-3">
<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2 align-items-end" style="height:100px">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">start</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">x</code>
</div>
</div>
</div>
<div class="col-6 col-md-3">
<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2 align-items-stretch" style="height:100px">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">start</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">x</code>
</div>
</div>
</div>
</div>4Align self
align-self-* moves a single item on the cross axis.
startcenterendstretch<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2" style="height:120px">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center align-self-start">
<code class="small">start</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center align-self-center">
<code class="small">center</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center align-self-end">
<code class="small">end</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center align-self-stretch">
<code class="small">stretch</code>
</div>
</div>5Fill and grow
flex-fill shares space equally, flex-grow-1 takes the remaining space.
flex-fillflex-fill wider textfillautoflex-grow-1auto<div class="d-grid gap-2">
<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center flex-fill">
<code class="small">flex-fill</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center flex-fill">
<code class="small">flex-fill wider text</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center flex-fill">
<code class="small">fill</code>
</div>
</div>
<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">auto</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center flex-grow-1">
<code class="small">flex-grow-1</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">auto</code>
</div>
</div>
</div>6Shrink
flex-shrink-0 keeps an item at its size while the other one shrinks.
flex-shrink-0flex-shrink-1 - Automations take care of the repetitive steps, so people can focus on real work.<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center flex-shrink-0" style="width:140px">
<code class="small">flex-shrink-0</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center flex-shrink-1 text-truncate">
<code class="small">flex-shrink-1 - Automations take care of the repetitive steps, so people can focus on real work.</code>
</div>
</div>7Auto margins
ms-auto pushes an item and everything after it to the end.
<div class="d-flex align-items-center gap-2 border rounded-3 px-3 py-2">
<span class="fw-bold">Vela</span> <a href="#" class="small link-body-emphasis">Docs</a> <a href="#" class="small link-body-emphasis">Blog</a>
<button type="button" class="btn btn-sm btn-primary ms-auto">Sign in</button>
</div>8Wrap
flex-wrap lets items move to a new line; flex-nowrap keeps one line.
itemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitem<div class="d-grid gap-2">
<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2 flex-wrap">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
</div>
<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2 flex-nowrap overflow-x-auto">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">item</code>
</div>
</div>
</div>9Order
order-* changes the visual order without changing the markup.
first in markup, order-3second, order-1third, order-2<div class="d-flex gap-2 bg-body-tertiary rounded-3 p-2">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center order-3">
<code class="small">first in markup, order-3</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center order-1">
<code class="small">second, order-1</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center order-2">
<code class="small">third, order-2</code>
</div>
</div>10Row gap and column gap
row-gap-* and column-gap-* set the two gaps separately.
row-gap-4column-gap-1cdefghijkl<div class="d-flex flex-wrap row-gap-4 column-gap-1 bg-body-tertiary rounded-3 p-2">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">row-gap-4</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">column-gap-1</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">c</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">d</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">e</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">f</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">g</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">h</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">i</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">j</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">k</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">l</code>
</div>
</div>11Responsive direction
flex-column flex-sm-row: a sign-up form stacks on phones and sits in one row from sm.
<div class="d-flex flex-column flex-sm-row gap-2" style="max-width:30rem">
<label class="visually-hidden" for="ut-mail-1250">Email</label>
<input id="ut-mail-1250" type="email" class="form-control" placeholder="you@example.com">
<button type="button" class="btn btn-primary text-nowrap">Subscribe</button>
</div>12Media list
Each row is d-flex with an icon box that never shrinks.
- Dark modeOnboarding guides and live chat help new colleagues get going on day one.
- 99.99% uptimeOur open API and ready-made integrations fit into the stack you already have.
<ul class="list-unstyled mb-0 d-grid gap-3">
<li class="d-flex gap-3"><span class="flex-shrink-0 bg-primary-subtle text-primary rounded-3 p-2 fs-5 lh-1"><i class="bi bi-lightning-charge-fill" aria-hidden="true"></i></span><div><div class="fw-semibold">Dark mode</div><div class="small text-body-secondary">Onboarding guides and live chat help new colleagues get going on day one.</div></div></li>
<li class="d-flex gap-3"><span class="flex-shrink-0 bg-success-subtle text-success rounded-3 p-2 fs-5 lh-1"><i class="bi bi-shield-check" aria-hidden="true"></i></span><div><div class="fw-semibold">99.99% uptime</div><div class="small text-body-secondary">Our open API and ready-made integrations fit into the stack you already have.</div></div></li>
</ul>13Sticky footer in a card
A flex-column card with flex-grow-1 body keeps the button at the bottom regardless of text length.
Every update lands in one place, so nothing gets lost in email threads.
OpenWe measure success by how many customers come back and tell their friends. We keep things simple, so you can focus on what matters to you. Our team has done this many times, so you never have to guess.
Open<div class="row g-3">
<div class="col-6">
<div class="d-flex flex-column border rounded-3 p-3 h-100">
<div class="fw-semibold">
Inside our product roadmap for next year
</div>
<p class="small flex-grow-1">Every update lands in one place, so nothing gets lost in email threads.</p>
<a href="#" class="btn btn-sm btn-outline-primary">Open</a>
</div>
</div>
<div class="col-6">
<div class="d-flex flex-column border rounded-3 p-3 h-100">
<div class="fw-semibold">
Writing status updates people actually read
</div>
<p class="small flex-grow-1">We measure success by how many customers come back and tell their friends. We keep things simple, so you can focus on what matters to you. Our team has done this many times, so you never have to guess.</p>
<a href="#" class="btn btn-sm btn-outline-primary">Open</a>
</div>
</div>
</div>14Align content
align-content-* distributes wrapped lines in a taller container.
align-content-betweenbcdefghij<div class="d-flex flex-wrap align-content-between gap-2 bg-body-tertiary rounded-3 p-2" style="height:160px">
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">align-content-between</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">b</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">c</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">d</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">e</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">f</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">g</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">h</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">i</code>
</div>
<div class="bg-primary-subtle border border-primary-subtle rounded-2 p-2 text-center">
<code class="small">j</code>
</div>
</div>15Baseline alignment
align-items-baseline lines up text of different sizes on its baseline.
<div class="d-flex align-items-baseline gap-2">
<span class="display-6 fw-bold">$16.49</span><span class="text-body-secondary">/ month</span><span class="small text-success">billed yearly</span>
</div>16Horizontal stack
hstack is a shortcut for a centred flex row with gap.
<div class="hstack gap-2 border rounded-3 p-2">
<span class="badge text-bg-primary">news</span> <span class="small">What we learned shipping 200 releases</span>
<div class="vr ms-auto">
</div>
<button type="button" class="btn btn-sm btn-light">Edit</button>
</div>17Vertical stack
vstack is a flex column with gap: quick form or card layouts.
<div class="vstack gap-2 border rounded-3 p-3" style="max-width:20rem">
<div class="fw-semibold">
Ship faster with less busywork
</div>
<div class="small text-body-secondary">
Your data is encrypted, backed up daily and hosted in the region you choose.
</div>
<button type="button" class="btn btn-primary btn-sm">Join waitlist</button>
</div>18Responsive justify
justify-content-center justify-content-md-between centres on phones and spreads from md.
<div class="d-flex flex-wrap justify-content-center justify-content-md-between align-items-center gap-2 border rounded-3 p-3">
<span class="small text-body-secondary">Showing 1-10 of 118</span>
<div class="d-flex gap-1">
<button type="button" class="btn btn-sm btn-light border">Prev</button>
<button type="button" class="btn btn-sm btn-light border">Next</button>
</div>
</div>19Equal width columns with flex-fill
Navigation tabs share the row equally with flex-fill and text-center.
<nav class="d-flex border rounded-3 overflow-hidden" aria-label="Period">
<a href="#" class="flex-fill text-center py-2 text-bg-primary text-decoration-none" aria-current="page">Day</a> <a href="#" class="flex-fill text-center py-2 link-body-emphasis text-decoration-none border-start">Week</a> <a href="#" class="flex-fill text-center py-2 link-body-emphasis text-decoration-none border-start">Month</a> <a href="#" class="flex-fill text-center py-2 link-body-emphasis text-decoration-none border-start">Year</a>
</nav>20Reverse on large screens
flex-column flex-lg-row-reverse: on large screens the image moves to the right.
Work that moves itself forward
Plan projects, track progress and share updates without another status meeting. Start in minutes and get help from a real person whenever you need it.
<div class="d-flex flex-column flex-lg-row-reverse gap-3 align-items-lg-center">
<img src="https://images.unsplash.com/photo-1702301266409-ed1bfe210971?auto=format&fit=crop&w=1200&h=800&q=70" alt="The workspace your team will actually love" class="rounded-4 w-100" style="max-width:20rem">
<div>
<h3 class="h5 fw-semibold">Work that moves itself forward</h3>
<p class="small text-body-secondary mb-0">Plan projects, track progress and share updates without another status meeting. Start in minutes and get help from a real person whenever you need it.</p>
</div>
</div>