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="grid gap-2">
<div class="flex gap-2 bg-surface-3 rounded-lg p-2 flex-row">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">1</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">2</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">3</code>
</div>
</div>
<div class="flex gap-2 bg-surface-3 rounded-lg p-2 flex-row-reverse">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">1</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">2</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">3</code>
</div>
</div>
<div class="flex gap-2 bg-surface-3 rounded-lg p-2 flex-col">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">1</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">2</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md 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="grid gap-2">
<div class="flex gap-2 bg-surface-3 rounded-lg p-2 justify-start">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">A</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">B</code>
</div>
</div>
<div class="flex gap-2 bg-surface-3 rounded-lg p-2 justify-center">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">A</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">B</code>
</div>
</div>
<div class="flex gap-2 bg-surface-3 rounded-lg p-2 justify-end">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">A</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">B</code>
</div>
</div>
<div class="flex gap-2 bg-surface-3 rounded-lg p-2 justify-between">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">A</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">B</code>
</div>
</div>
<div class="flex gap-2 bg-surface-3 rounded-lg p-2 justify-around">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">A</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">B</code>
</div>
</div>
<div class="flex gap-2 bg-surface-3 rounded-lg p-2 justify-evenly">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">A</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md 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="flex gap-2 bg-surface-3 rounded-lg p-2 items-start" style="height:100px">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">start</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">x</code>
</div>
</div>
</div>
<div class="col-6 col-md-3">
<div class="flex gap-2 bg-surface-3 rounded-lg p-2 items-center" style="height:100px">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">start</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">x</code>
</div>
</div>
</div>
<div class="col-6 col-md-3">
<div class="flex gap-2 bg-surface-3 rounded-lg p-2 items-end" style="height:100px">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">start</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">x</code>
</div>
</div>
</div>
<div class="col-6 col-md-3">
<div class="flex gap-2 bg-surface-3 rounded-lg p-2 items-stretch" style="height:100px">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">start</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md 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="flex gap-2 bg-surface-3 rounded-lg p-2" style="height:120px">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center self-start">
<code class="small">start</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center self-center">
<code class="small">center</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center self-end">
<code class="small">end</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center 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="grid gap-2">
<div class="flex gap-2 bg-surface-3 rounded-lg p-2">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center flex-auto">
<code class="small">flex-fill</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center flex-auto">
<code class="small">flex-fill wider text</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center flex-auto">
<code class="small">fill</code>
</div>
</div>
<div class="flex gap-2 bg-surface-3 rounded-lg p-2">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">auto</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center grow">
<code class="small">flex-grow-1</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md 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 - Our ticketing shows every detail in view wherever you are.<div class="flex gap-2 bg-surface-3 rounded-lg p-2">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center shrink-0" style="width:140px">
<code class="small">flex-shrink-0</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center shrink truncate">
<code class="small">flex-shrink-1 - Our ticketing shows every detail in view wherever you are.</code>
</div>
</div>7Auto margins
ms-auto pushes an item and everything after it to the end.
<div class="flex items-center gap-2 border rounded-lg px-4 py-2">
<span class="font-bold">Brand name 20</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="grid gap-2">
<div class="flex gap-2 bg-surface-3 rounded-lg p-2 flex-wrap">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
</div>
<div class="flex gap-2 bg-surface-3 rounded-lg p-2 flex-nowrap overflow-x-auto">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">item</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md 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="flex gap-2 bg-surface-3 rounded-lg p-2">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center order-3">
<code class="small">first in markup, order-3</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center order-1">
<code class="small">second, order-1</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md 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="flex flex-wrap gap-y-6 gap-x-1 bg-surface-3 rounded-lg p-2">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">row-gap-4</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">column-gap-1</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">c</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">d</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">e</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">f</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">g</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">h</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">i</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">j</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">k</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md 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="flex flex-col sm:flex-row gap-2" style="max-width:30rem">
<label class="sr-only" 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 whitespace-nowrap">Subscribe</button>
</div>12Media list
Each row is d-flex with an icon box that never shrinks.
- Networking loungesA honest workflow shows complex tasks into simple steps from the very first day.
- World-class speakersOur ticketing gives your work organised on any device.
<ul class="list-unstyled mb-0 grid gap-4">
<li class="flex gap-4"><span class="shrink-0 bg-primary-subtle text-primary rounded-lg p-2 text-lg leading-none"><i class="bi bi-lightning-charge-fill" aria-hidden="true"></i></span><div><div class="font-semibold">Networking lounges</div><div class="small text-muted">A honest workflow shows complex tasks into simple steps from the very first day.</div></div></li>
<li class="flex gap-4"><span class="shrink-0 bg-success-subtle text-success rounded-lg p-2 text-lg leading-none"><i class="bi bi-shield-check" aria-hidden="true"></i></span><div><div class="font-semibold">World-class speakers</div><div class="small text-muted">Our ticketing gives your work organised on any device.</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.
This elegant plan guides every detail in view wherever you are.
OpenOur live streaming brings decisions quicker and clearer all year round. The new world-class speakers lets your work organised on any device. A honest experience helps projects moving forward without extra tools.
Open<div class="row g-3">
<div class="col-6">
<div class="flex flex-col border rounded-lg p-4 h-full">
<div class="font-semibold">
Focused ways to improve your release
</div>
<p class="small grow">This elegant plan guides every detail in view wherever you are.</p>
<a href="#" class="btn btn-sm btn-outline-primary">Open</a>
</div>
</div>
<div class="col-6">
<div class="flex flex-col border rounded-lg p-4 h-full">
<div class="font-semibold">
What's new in webinar
</div>
<p class="small grow">Our live streaming brings decisions quicker and clearer all year round. The new world-class speakers lets your work organised on any device. A honest experience helps projects moving forward without extra tools.</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="flex flex-wrap content-between gap-2 bg-surface-3 rounded-lg p-2" style="height:160px">
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">align-content-between</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">b</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">c</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">d</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">e</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">f</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">g</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">h</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md p-2 text-center">
<code class="small">i</code>
</div>
<div class="bg-primary-subtle border border-primary/30 rounded-md 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="flex items-baseline gap-2">
<span class="display-6 font-bold">$27.87</span><span class="text-muted">/ 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-lg p-2">
<span class="badge text-bg-primary">community</span> <span class="small">Friendly ways to improve your journey</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-lg p-4" style="max-width:20rem">
<div class="font-semibold">
Where great ideas meet
</div>
<div class="small text-muted">
This elegant idea lets your work organised with friendly support.
</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="flex flex-wrap justify-center md:justify-between items-center gap-2 border rounded-lg p-4">
<span class="small text-muted">Showing 1-10 of 185</span>
<div class="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="flex border rounded-lg overflow-hidden" aria-label="Period">
<a href="#" class="flex-auto text-center py-2 text-bg-primary no-underline" aria-current="page">Day</a> <a href="#" class="flex-auto text-center py-2 link-body-emphasis no-underline border-s">Week</a> <a href="#" class="flex-auto text-center py-2 link-body-emphasis no-underline border-s">Month</a> <a href="#" class="flex-auto text-center py-2 link-body-emphasis no-underline border-s">Year</a>
</nav>20Reverse on large screens
flex-column flex-lg-row-reverse: on large screens the image moves to the right.
Learn, connect and get inspired
This secure team connects every detail in view in just a few clicks. A secure routine brings the whole team on the same page on any device.
<div class="flex flex-col lg:flex-row-reverse gap-4 lg:items-center">
<img src="../assets/img/photo-11.svg" alt="Join the conference of the year" class="rounded-xl w-full" style="max-width:20rem">
<div>
<h3 class="h5 font-semibold">Learn, connect and get inspired</h3>
<p class="small text-muted mb-0">This secure team connects every detail in view in just a few clicks. A secure routine brings the whole team on the same page on any device.</p>
</div>
</div>