Utilities
Flex
Manage the layout, alignment and sizing of grid columns, navigation, components and more with responsive flexbox utilities.
How it works
Flex utilities are the quickest way to lay out a row of things without reaching for the
grid. Every class below has responsive variants, and the spacing between
items comes from the theme's gap utilities on the 4 px scale
(.gap-4 = 1 rem). Nothing in this theme changes the flex classes themselves.
Enable flex behaviors
Apply display utilities to create a flexbox container and transform direct children into flex
items. Flex containers and items can be modified further with the additional flex properties.
HTML
<div class="d-flex p-2 bg-body-tertiary border">I'm a flexbox container!</div>HTML
<div class="d-inline-flex p-2 bg-body-tertiary border">I'm an inline flexbox container!</div>Responsive variations also exist for .d-flex and .d-inline-flex.
.d-flex,.d-inline-flex.d-sm-flex,.d-sm-inline-flex.d-md-flex,.d-md-inline-flex.d-lg-flex,.d-lg-inline-flex.d-xl-flex,.d-xl-inline-flex.d-xxl-flex,.d-xxl-inline-flex
Direction
Set the direction of flex items in a flex container with direction utilities. In most cases you can omit the
horizontal class here as the browser default is row. However, you may encounter situations
where you needed to explicitly set this value (like responsive layouts).
Use .flex-row to set a horizontal direction (the browser default), or .flex-row-reverse to start the horizontal direction from the opposite side.
HTML
<div class="d-flex flex-row mb-3 gap-2">
<div class="p-2 bg-body-tertiary border">Flex item 1</div>
<div class="p-2 bg-body-tertiary border">Flex item 2</div>
<div class="p-2 bg-body-tertiary border">Flex item 3</div>
</div>
<div class="d-flex flex-row-reverse gap-2">
<div class="p-2 bg-body-tertiary border">Flex item 1</div>
<div class="p-2 bg-body-tertiary border">Flex item 2</div>
<div class="p-2 bg-body-tertiary border">Flex item 3</div>
</div>Use .flex-column to set a vertical direction, or .flex-column-reverse to start the vertical direction from the opposite side.
HTML
<div class="d-flex flex-column mb-3 gap-2">
<div class="p-2 bg-body-tertiary border">Flex item 1</div>
<div class="p-2 bg-body-tertiary border">Flex item 2</div>
<div class="p-2 bg-body-tertiary border">Flex item 3</div>
</div>
<div class="d-flex flex-column-reverse gap-2">
<div class="p-2 bg-body-tertiary border">Flex item 1</div>
<div class="p-2 bg-body-tertiary border">Flex item 2</div>
<div class="p-2 bg-body-tertiary border">Flex item 3</div>
</div>Responsive variations also exist for flex-direction.
.flex-row,.flex-row-reverse,.flex-column,.flex-column-reverse.flex-sm-row,.flex-sm-row-reverse,.flex-sm-column,.flex-sm-column-reverse.flex-md-row,.flex-md-row-reverse,.flex-md-column,.flex-md-column-reverse.flex-lg-row,.flex-lg-row-reverse,.flex-lg-column,.flex-lg-column-reverse.flex-xl-row,.flex-xl-row-reverse,.flex-xl-column,.flex-xl-column-reverse.flex-xxl-row,.flex-xxl-row-reverse,.flex-xxl-column,.flex-xxl-column-reverse
Justify content
Use justify-content utilities on flexbox containers to change the alignment of flex items on the
main axis (the x-axis to start, y-axis if flex-direction: column). Choose from
start (browser default), end, center, between,
around, or evenly.
HTML
<div class="d-flex justify-content-start mb-3 bg-body-tertiary border">
<div class="p-2 border">Start</div><div class="p-2 border">Start</div><div class="p-2 border">Start</div>
</div>
<div class="d-flex justify-content-end mb-3 bg-body-tertiary border">
<div class="p-2 border">End</div><div class="p-2 border">End</div><div class="p-2 border">End</div>
</div>
<div class="d-flex justify-content-center mb-3 bg-body-tertiary border">
<div class="p-2 border">Center</div><div class="p-2 border">Center</div><div class="p-2 border">Center</div>
</div>
<div class="d-flex justify-content-between mb-3 bg-body-tertiary border">
<div class="p-2 border">Between</div><div class="p-2 border">Between</div><div class="p-2 border">Between</div>
</div>
<div class="d-flex justify-content-around mb-3 bg-body-tertiary border">
<div class="p-2 border">Around</div><div class="p-2 border">Around</div><div class="p-2 border">Around</div>
</div>
<div class="d-flex justify-content-evenly bg-body-tertiary border">
<div class="p-2 border">Evenly</div><div class="p-2 border">Evenly</div><div class="p-2 border">Evenly</div>
</div>Responsive variations also exist for justify-content.
.justify-content-start,-end,-center,-between,-around,-evenly.justify-content-sm-start,-end,-center,-between,-around,-evenly.justify-content-md-start,-end,-center,-between,-around,-evenly.justify-content-lg-start,-end,-center,-between,-around,-evenly.justify-content-xl-start,-end,-center,-between,-around,-evenly.justify-content-xxl-start,-end,-center,-between,-around,-evenly
Align items
Use align-items utilities on flexbox containers to change the alignment of flex items on the
cross axis (the y-axis to start, x-axis if flex-direction: column). Choose from
start, end, center, baseline, or stretch
(browser default).
HTML
<div class="d-flex align-items-start mb-3 bg-body-tertiary border" style="height: 100px">
<div class="p-2 border">Start</div><div class="p-2 border">Start</div><div class="p-2 border">Start</div>
</div>
<div class="d-flex align-items-end mb-3 bg-body-tertiary border" style="height: 100px">
<div class="p-2 border">End</div><div class="p-2 border">End</div><div class="p-2 border">End</div>
</div>
<div class="d-flex align-items-center mb-3 bg-body-tertiary border" style="height: 100px">
<div class="p-2 border">Center</div><div class="p-2 border">Center</div><div class="p-2 border">Center</div>
</div>
<div class="d-flex align-items-baseline mb-3 bg-body-tertiary border" style="height: 100px">
<div class="p-2 border">Baseline</div><div class="p-2 border fs-3">Baseline</div><div class="p-2 border">Baseline</div>
</div>
<div class="d-flex align-items-stretch bg-body-tertiary border" style="height: 100px">
<div class="p-2 border">Stretch</div><div class="p-2 border">Stretch</div><div class="p-2 border">Stretch</div>
</div>Responsive variations also exist for align-items.
.align-items-start,-end,-center,-baseline,-stretch.align-items-sm-start,-end,-center,-baseline,-stretch.align-items-md-start,-end,-center,-baseline,-stretch.align-items-lg-start,-end,-center,-baseline,-stretch.align-items-xl-start,-end,-center,-baseline,-stretch.align-items-xxl-start,-end,-center,-baseline,-stretch
Align self
Use align-self utilities on flexbox items to individually change their alignment on the cross
axis. Choose from the same options as align-items: start, end,
center, baseline, or stretch (browser default).
HTML
<div class="d-flex mb-3 bg-body-tertiary border" style="height: 100px">
<div class="p-2 border">Flex item</div>
<div class="align-self-start p-2 border">Aligned flex item</div>
<div class="p-2 border">Flex item</div>
</div>
<div class="d-flex mb-3 bg-body-tertiary border" style="height: 100px">
<div class="p-2 border">Flex item</div>
<div class="align-self-end p-2 border">Aligned flex item</div>
<div class="p-2 border">Flex item</div>
</div>
<div class="d-flex mb-3 bg-body-tertiary border" style="height: 100px">
<div class="p-2 border">Flex item</div>
<div class="align-self-center p-2 border">Aligned flex item</div>
<div class="p-2 border">Flex item</div>
</div>
<div class="d-flex mb-3 bg-body-tertiary border" style="height: 100px">
<div class="p-2 border">Flex item</div>
<div class="align-self-baseline p-2 border">Aligned flex item</div>
<div class="p-2 border">Flex item</div>
</div>
<div class="d-flex bg-body-tertiary border" style="height: 100px">
<div class="p-2 border">Flex item</div>
<div class="align-self-stretch p-2 border">Aligned flex item</div>
<div class="p-2 border">Flex item</div>
</div>Responsive variations also exist for align-self.
.align-self-start,-end,-center,-baseline,-stretch,-auto.align-self-sm-start,-end,-center,-baseline,-stretch,-auto.align-self-md-start,-end,-center,-baseline,-stretch,-auto.align-self-lg-start,-end,-center,-baseline,-stretch,-auto.align-self-xl-start,-end,-center,-baseline,-stretch,-auto.align-self-xxl-start,-end,-center,-baseline,-stretch,-auto
Fill
Use the .flex-fill class on a series of sibling elements to force them into widths equal to
their content (or equal widths if their content does not surpass their border-boxes) while taking up all
available horizontal space.
HTML
<div class="d-flex bg-body-tertiary border">
<div class="p-2 flex-fill border">Flex item with a lot of content</div>
<div class="p-2 flex-fill border">Flex item</div>
<div class="p-2 flex-fill border">Flex item</div>
</div>Responsive variations also exist for flex-fill.
.flex-fill.flex-sm-fill.flex-md-fill.flex-lg-fill.flex-xl-fill.flex-xxl-fill
Grow and shrink
Use .flex-grow-* utilities to toggle a flex item's ability to grow to fill available space. In
the example below, the .flex-grow-1 elements use all available space it can, while allowing the
remaining two flex items their necessary space.
HTML
<div class="d-flex bg-body-tertiary border">
<div class="p-2 flex-grow-1 border">Flex item</div>
<div class="p-2 border">Flex item</div>
<div class="p-2 border">Third flex item</div>
</div>
Use .flex-shrink-* utilities to toggle a flex item's ability to shrink if necessary. In the
example below, the second flex item with .flex-shrink-1 is forced to wrap its contents to a new
line, "shrinking" to allow more space for the previous flex item with .w-100.
HTML
<div class="d-flex bg-body-tertiary border">
<div class="p-2 w-100 border">Flex item</div>
<div class="p-2 flex-shrink-1 border">Flex item</div>
</div>Responsive variations also exist for flex-grow and flex-shrink.
.flex-{grow|shrink}-0,.flex-{grow|shrink}-1.flex-sm-{grow|shrink}-0,.flex-sm-{grow|shrink}-1.flex-md-{grow|shrink}-0,.flex-md-{grow|shrink}-1.flex-lg-{grow|shrink}-0,.flex-lg-{grow|shrink}-1.flex-xl-{grow|shrink}-0,.flex-xl-{grow|shrink}-1.flex-xxl-{grow|shrink}-0,.flex-xxl-{grow|shrink}-1
Auto margins
Flexbox can do some pretty awesome things when you mix flex alignments with auto margins. Shown below are
three examples of controlling flex items via auto margins: default (no auto margin), pushing two items to
the right (.me-auto), and pushing two items to the left (.ms-auto).
HTML
<div class="d-flex mb-3 bg-body-tertiary border">
<div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div>
</div>
<div class="d-flex mb-3 bg-body-tertiary border">
<div class="me-auto p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div>
</div>
<div class="d-flex bg-body-tertiary border">
<div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div>
<div class="ms-auto p-2 border">Flex item</div>
</div>With align-items
Vertically move one flex item to the top or bottom of a container by mixing align-items,
flex-direction: column, and margin-top: auto or margin-bottom: auto.
HTML
<div class="d-flex align-items-start flex-column mb-3 bg-body-tertiary border" style="height: 200px">
<div class="mb-auto p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div>
</div>
<div class="d-flex align-items-end flex-column bg-body-tertiary border" style="height: 200px">
<div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div>
<div class="mt-auto p-2 border">Flex item</div>
</div>Wrap
Change how flex items wrap in a flex container. Choose from no wrapping at all (the browser default) with
.flex-nowrap, wrapping with .flex-wrap, or reverse wrapping with
.flex-wrap-reverse.
HTML
<div class="d-flex flex-nowrap bg-body-tertiary border" style="width: 8rem">
<div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div>
</div>HTML
<div class="d-flex flex-wrap bg-body-tertiary border">
<div class="p-2 border">Flex item 1</div>
<div class="p-2 border">Flex item 2</div>
<div class="p-2 border">Flex item 3</div>
<div class="p-2 border">Flex item 4</div>
<div class="p-2 border">Flex item 5</div>
<div class="p-2 border">Flex item 6</div>
<div class="p-2 border">Flex item 7</div>
<div class="p-2 border">Flex item 8</div>
<div class="p-2 border">Flex item 9</div>
<div class="p-2 border">Flex item 10</div>
<div class="p-2 border">Flex item 11</div>
<div class="p-2 border">Flex item 12</div>
<div class="p-2 border">Flex item 13</div>
<div class="p-2 border">Flex item 14</div>
</div>HTML
<div class="d-flex flex-wrap-reverse bg-body-tertiary border">
<div class="p-2 border">Flex item 1</div>
<div class="p-2 border">Flex item 2</div>
<div class="p-2 border">Flex item 3</div>
<div class="p-2 border">Flex item 4</div>
<div class="p-2 border">Flex item 5</div>
<div class="p-2 border">Flex item 6</div>
<div class="p-2 border">Flex item 7</div>
<div class="p-2 border">Flex item 8</div>
<div class="p-2 border">Flex item 9</div>
<div class="p-2 border">Flex item 10</div>
<div class="p-2 border">Flex item 11</div>
<div class="p-2 border">Flex item 12</div>
<div class="p-2 border">Flex item 13</div>
<div class="p-2 border">Flex item 14</div>
</div>Responsive variations also exist for flex-wrap.
.flex-nowrap,.flex-wrap,.flex-wrap-reverse.flex-sm-nowrap,.flex-sm-wrap,.flex-sm-wrap-reverse.flex-md-nowrap,.flex-md-wrap,.flex-md-wrap-reverse.flex-lg-nowrap,.flex-lg-wrap,.flex-lg-wrap-reverse.flex-xl-nowrap,.flex-xl-wrap,.flex-xl-wrap-reverse.flex-xxl-nowrap,.flex-xxl-wrap,.flex-xxl-wrap-reverse
Order
Change the visual order of specific flex items with a handful of order utilities.
We only provide options for making an item first or last, as well as a reset to use the DOM order. As
order takes any integer value from 0 to 5, add custom CSS for any additional values needed.
HTML
<div class="d-flex flex-nowrap bg-body-tertiary border">
<div class="order-3 p-2 border">First flex item</div>
<div class="order-2 p-2 border">Second flex item</div>
<div class="order-1 p-2 border">Third flex item</div>
</div>Responsive variations also exist for order.
.order-0….order-5.order-sm-0….order-sm-5.order-md-0….order-md-5.order-lg-0….order-lg-5.order-xl-0….order-xl-5.order-xxl-0….order-xxl-5
Additionally there are also responsive .order-first and .order-last classes that
change the order of an element by applying order: -1 and order: 6,
respectively. These classes can also be intermixed with the numbered .order-* classes as
needed.
.order-first,.order-last.order-sm-first,.order-sm-last.order-md-first,.order-md-last.order-lg-first,.order-lg-last.order-xl-first,.order-xl-last.order-xxl-first,.order-xxl-last
order for presentation only. See
Accessibility.Align content
Use align-content utilities on flexbox containers to align flex items together on the
cross axis. Choose from start (browser default), end, center,
between, around, or stretch. To demonstrate these utilities, we've
enforced flex-wrap: wrap and increased the number of flex items.
Heads up! This property has no effect on single rows of flex items.
HTML
<div class="d-flex align-content-start flex-wrap bg-body-tertiary border" style="height: 200px">
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
</div>HTML
<div class="d-flex align-content-end flex-wrap bg-body-tertiary border" style="height: 200px">
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
</div>HTML
<div class="d-flex align-content-center flex-wrap bg-body-tertiary border" style="height: 200px">
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
</div>HTML
<div class="d-flex align-content-between flex-wrap bg-body-tertiary border" style="height: 200px">
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
</div>HTML
<div class="d-flex align-content-around flex-wrap bg-body-tertiary border" style="height: 200px">
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
</div>HTML
<div class="d-flex align-content-stretch flex-wrap bg-body-tertiary border" style="height: 200px">
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
<div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div><div class="p-2 border">Flex item</div>
</div>Responsive variations also exist for align-content.
.align-content-start,-end,-center,-between,-around,-stretch.align-content-sm-start,-end,-center,-between,-around,-stretch.align-content-md-start,-end,-center,-between,-around,-stretch.align-content-lg-start,-end,-center,-between,-around,-stretch.align-content-xl-start,-end,-center,-between,-around,-stretch.align-content-xxl-start,-end,-center,-between,-around,-stretch
Media object
Looking to replicate the media object component from Bootstrap 4? Recreate it in no time with a few flex utilities that allow even more flexibility and customization than before. The avatar below is an inline SVG so the page carries no images.
Main event
This is some content from a media component. You can replace this with any content and adjust it as needed — a wrestler bio, a results line, a card of matches.HTML
<div class="d-flex">
<div class="flex-shrink-0">
<svg class="rounded border" width="64" height="64" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: 64x64"><rect width="100%" height="100%" fill="var(--bs-navy-500)"/><text x="50%" y="50%" fill="var(--bs-cream-50)" dy=".3em" text-anchor="middle" font-size="14">64×64</text></svg>
</div>
<div class="flex-grow-1 ms-3">
<h4 class="mt-0">Main event</h4>
This is some content from a media component. You can replace this with any content and adjust it as
needed — a wrestler bio, a results line, a card of matches.
</div>
</div>And say you want to vertically center the content next to the image.
HTML
<div class="d-flex align-items-center">
<div class="flex-shrink-0">
<svg class="rounded border" width="64" height="64" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: 64x64"><rect width="100%" height="100%" fill="var(--bs-gold-700)"/><text x="50%" y="50%" fill="var(--bs-navy-900)" dy=".3em" text-anchor="middle" font-size="14">64×64</text></svg>
</div>
<div class="flex-grow-1 ms-3">
This is some content from a media component. You can replace this with any content and adjust it as
needed.
</div>
</div>CSS
Flex utilities are declared in the utilities map and generated by the Utility API.
The relevant entries are "flex", "flex-direction", "flex-grow",
"flex-shrink", "flex-wrap", "justify-content",
"align-items", "align-content", "align-self" and
"order", all with responsive: true.