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 evening party is the best place to turn talks into friendships.<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 evening party is the best place to turn talks into friendships.</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">Zeni Studio</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.
- World-class speakersWe keep things simple, so you can focus on what matters to you.
- CertificatesVirtual passes let you join the main stage live from anywhere.
<ul class="list-unstyled mb-0 grid gap-4">
<li class="flex gap-4"><span class="shrink-0 bg-primary-subtle text-primary-ink 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">World-class speakers</div><div class="small text-muted">We keep things simple, so you can focus on what matters to you.</div></div></li>
<li class="flex gap-4"><span class="shrink-0 bg-success-subtle text-success-emphasis rounded-lg p-2 text-lg leading-none"><i class="bi bi-shield-check" aria-hidden="true"></i></span><div><div class="font-semibold">Certificates</div><div class="small text-muted">Virtual passes let you join the main stage live from anywhere.</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.
Sponsors meet decision-makers in a relaxed, friendly setting.
OpenEvery attendee receives a certificate of participation. Three days of keynotes, hands-on workshops and evening meetups. Early bird tickets save you up to forty percent until the end of the month.
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">
How to pitch a talk that gets accepted
</div>
<p class="small grow">Sponsors meet decision-makers in a relaxed, friendly setting.</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 makes a panel worth watching
</div>
<p class="small grow">Every attendee receives a certificate of participation. Three days of keynotes, hands-on workshops and evening meetups. Early bird tickets save you up to forty percent until the end of the month.</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">$24.09</span><span class="text-muted">/ month</span><span class="small text-success-emphasis">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">update</span> <span class="small">A guide to the city for visiting attendees</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">
Friendly people answer your questions quickly, by phone, chat or email.
</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 51</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.
Be in the room where it happens
The venue is a short walk from the station and fully accessible. Group tickets include a private meeting room for your team.
<div class="flex flex-col lg:flex-row-reverse gap-4 lg:items-center">
<img src="https://images.unsplash.com/photo-1762968274962-20c12e6e8ecd?auto=format&fit=crop&w=1200&h=800&q=70" alt="Meet the people shaping the future" class="rounded-xl w-full" style="max-width:20rem">
<div>
<h3 class="h5 font-semibold">Be in the room where it happens</h3>
<p class="small text-muted mb-0">The venue is a short walk from the station and fully accessible. Group tickets include a private meeting room for your team.</p>
</div>
</div>