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 - Gift wrapping and a handwritten note are free on every order.<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 - Gift wrapping and a handwritten note are free on every order.</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">Pixel Nest</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.
- Sustainable materialsOur packaging is plastic-free and every delivery is carbon-neutral.
- Carbon-neutral deliveryMembers get early access to new drops and prices only they can see.
<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">Sustainable materials</div><div class="small text-muted">Our packaging is plastic-free and every delivery is carbon-neutral.</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">Carbon-neutral delivery</div><div class="small text-muted">Members get early access to new drops and prices only they can see.</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 piece is made in small batches from materials we test ourselves. Each product is checked by hand before it goes into the box. We keep things simple, so you can focus on what matters to you.
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 we choose sustainable materials
</div>
<p class="small grow">Clear prices, honest advice and no surprises along the way.</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 to pack for a rainy weekend outdoors
</div>
<p class="small grow">Every piece is made in small batches from materials we test ourselves. Each product is checked by hand before it goes into the box. We keep things simple, so you can focus on what matters to you.</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">$16.92</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">tutorial</span> <span class="small">A beginner's guide to getting started</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">
Gifts they will actually keep
</div>
<div class="small text-muted">
We measure success by how many shoppers come back and tell their friends.
</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 216</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.
The new collection has landed
Thousands of shoppers already trust us, and we work hard to keep it that way. Order before 2 pm and most items leave our warehouse the same day.
<div class="flex flex-col lg:flex-row-reverse gap-4 lg:items-center">
<img src="https://images.unsplash.com/photo-1567958451986-2de427a4a0be?auto=format&fit=crop&w=1200&h=800&q=70" alt="Thoughtful goods for a simpler home" class="rounded-xl w-full" style="max-width:20rem">
<div>
<h3 class="h5 font-semibold">The new collection has landed</h3>
<p class="small text-muted mb-0">Thousands of shoppers already trust us, and we work hard to keep it that way. Order before 2 pm and most items leave our warehouse the same day.</p>
</div>
</div>