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 - Our rental team manages repairs, payments and tenants for landlords.<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 - Our rental team manages repairs, payments and tenants for landlords.</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">Kite HQ</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.
- Price alertsWe handle the paperwork, so you can focus on planning the move.
- Fast paperworkPrice alerts tell you the moment a home that fits your search comes on the market.
<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">Price alerts</div><div class="small text-body-secondary">We handle the paperwork, so you can focus on planning the move.</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">Fast paperwork</div><div class="small text-body-secondary">Price alerts tell you the moment a home that fits your search comes on the market.</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.
Most of our homes sell within six weeks, often above the asking price.
OpenMortgage advisors help you understand what you can afford before you start. Get a free, no-obligation valuation of your home within 48 hours. 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="d-flex flex-column border rounded-3 p-3 h-100">
<div class="fw-semibold">
The best neighbourhoods for families this year
</div>
<p class="small flex-grow-1">Most of our homes sell within six weeks, often above the asking price.</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">
Staging tips that help homes sell faster
</div>
<p class="small flex-grow-1">Mortgage advisors help you understand what you can afford before you start. Get a free, no-obligation valuation of your home within 48 hours. 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="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">$44.88</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">community</span> <span class="small">The small habits that make a big difference</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">
Buy, sell or rent with confidence
</div>
<div class="small text-body-secondary">
Thousands of buyers already trust us, and we work hard to keep it that way.
</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 99</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.
Home is closer than you think
Every listing is checked by our team, so the photos match what you see in person. Friendly people answer your questions quickly, by phone, chat or email.
<div class="d-flex flex-column flex-lg-row-reverse gap-3 align-items-lg-center">
<img src="https://images.unsplash.com/photo-1513584684374-8bab748fbf90?auto=format&fit=crop&w=1200&h=800&q=70" alt="Smart property search, real advice" class="rounded-4 w-100" style="max-width:20rem">
<div>
<h3 class="h5 fw-semibold">Home is closer than you think</h3>
<p class="small text-body-secondary mb-0">Every listing is checked by our team, so the photos match what you see in person. Friendly people answer your questions quickly, by phone, chat or email.</p>
</div>
</div>