Flex
A full suite of responsive flexbox utilities for controlling layout direction, alignment, sizing, wrapping, and ordering of flex items.
Enable flex behaviors
.d-flex and .d-inline-flex turn an element into a flexbox container, making direct children flex items. Additional flex properties can then be applied to the container or individual items.
<div class="d-flex p-xs">I'm a flexbox container!</div><div class="d-inline-flex p-xs">I'm an inline flexbox container!</div>Responsive variants are available for .d-flex and .d-inline-flex.
.d-flex.d-inline-flex.sm:d-flex.sm:d-inline-flex.md:d-flex.md:d-inline-flex.lg:d-flex.lg:d-inline-flex.xl:d-flex.xl:d-inline-flex.2xl:d-flex.2xl:d-inline-flex
Direction
Direction utilities set the flex-direction property. The default browser value is row, so .flex-row is typically unnecessary unless overriding a breakpoint-specific value.
.flex-row produces a left-to-right horizontal layout. .flex-row-reverse starts items from the right.
<div class="d-flex flex-row mb-md">
<div class="p-xs">Flex item 1</div>
<div class="p-xs">Flex item 2</div>
<div class="p-xs">Flex item 3</div>
</div>
<div class="d-flex flex-row-reverse">
<div class="p-xs">Flex item 1</div>
<div class="p-xs">Flex item 2</div>
<div class="p-xs">Flex item 3</div>
</div>.flex-column sets a top-to-bottom vertical direction. .flex-column-reverse starts items from the bottom.
<div class="d-flex flex-column mb-md">
<div class="p-xs">Flex item 1</div>
<div class="p-xs">Flex item 2</div>
<div class="p-xs">Flex item 3</div>
</div>
<div class="d-flex flex-column-reverse">
<div class="p-xs">Flex item 1</div>
<div class="p-xs">Flex item 2</div>
<div class="p-xs">Flex item 3</div>
</div>Responsive variants are available for flex-direction.
.flex-row.flex-row-reverse.flex-column.flex-column-reverse.sm:flex-row.sm:flex-row-reverse.sm:flex-column.sm:flex-column-reverse.md:flex-row.md:flex-row-reverse.md:flex-column.md:flex-column-reverse.lg:flex-row.lg:flex-row-reverse.lg:flex-column.lg:flex-column-reverse.xl:flex-row.xl:flex-row-reverse.xl:flex-column.xl:flex-column-reverse.2xl:flex-row.2xl:flex-row-reverse.2xl:flex-column.2xl:flex-column-reverse
Justify content
justify-content utilities control flex item alignment along the main axis — the x-axis by default, or the y-axis when flex-direction: column is applied. Available values: start (browser default), end, center, between, around, and evenly.
<div class="d-flex justify-content-start">...</div>
<div class="d-flex justify-content-end">...</div>
<div class="d-flex justify-content-center">...</div>
<div class="d-flex justify-content-between">...</div>
<div class="d-flex justify-content-around">...</div>
<div class="d-flex justify-content-evenly">...</div>Responsive variants are available for justify-content.
.justify-content-start.justify-content-end.justify-content-center.justify-content-between.justify-content-around.justify-content-evenly.sm:justify-content-start.sm:justify-content-end.sm:justify-content-center.sm:justify-content-between.sm:justify-content-around.sm:justify-content-evenly.md:justify-content-start.md:justify-content-end.md:justify-content-center.md:justify-content-between.md:justify-content-around.md:justify-content-evenly.lg:justify-content-start.lg:justify-content-end.lg:justify-content-center.lg:justify-content-between.lg:justify-content-around.lg:justify-content-evenly.xl:justify-content-start.xl:justify-content-end.xl:justify-content-center.xl:justify-content-between.xl:justify-content-around.xl:justify-content-evenly.2xl:justify-content-start.2xl:justify-content-end.2xl:justify-content-center.2xl:justify-content-between.2xl:justify-content-around.2xl:justify-content-evenly
Align items
align-items utilities control flex item alignment along the cross axis — the y-axis by default, or the x-axis when flex-direction: column is applied. Available values: start, end, center, baseline, and stretch (browser default).
<div class="d-flex align-items-start">...</div>
<div class="d-flex align-items-end">...</div>
<div class="d-flex align-items-center">...</div>
<div class="d-flex align-items-baseline">...</div>
<div class="d-flex align-items-stretch">...</div>Responsive variants are available for align-items.
.align-items-start.align-items-end.align-items-center.align-items-baseline.align-items-stretch.sm:align-items-start.sm:align-items-end.sm:align-items-center.sm:align-items-baseline.sm:align-items-stretch.md:align-items-start.md:align-items-end.md:align-items-center.md:align-items-baseline.md:align-items-stretch.lg:align-items-start.lg:align-items-end.lg:align-items-center.lg:align-items-baseline.lg:align-items-stretch.xl:align-items-start.xl:align-items-end.xl:align-items-center.xl:align-items-baseline.xl:align-items-stretch.2xl:align-items-start.2xl:align-items-end.2xl:align-items-center.2xl:align-items-baseline.2xl:align-items-stretch
Align self
align-self utilities override the container's align-items value for individual flex items. The same values are available as for align-items: start, end, center, baseline, and stretch (browser default).
<div class="align-self-start">Aligned flex item</div>
<div class="align-self-end">Aligned flex item</div>
<div class="align-self-center">Aligned flex item</div>
<div class="align-self-baseline">Aligned flex item</div>
<div class="align-self-stretch">Aligned flex item</div>Responsive variants are available for align-self.
.align-self-start.align-self-end.align-self-center.align-self-baseline.align-self-stretch.sm:align-self-start.sm:align-self-end.sm:align-self-center.sm:align-self-baseline.sm:align-self-stretch.md:align-self-start.md:align-self-end.md:align-self-center.md:align-self-baseline.md:align-self-stretch.lg:align-self-start.lg:align-self-end.lg:align-self-center.lg:align-self-baseline.lg:align-self-stretch.xl:align-self-start.xl:align-self-end.xl:align-self-center.xl:align-self-baseline.xl:align-self-stretch.2xl:align-self-start.2xl:align-self-end.2xl:align-self-center.2xl:align-self-baseline.2xl:align-self-stretch
Grow and shrink
.flex-grow-1 allows a flex item to expand and fill remaining space; .flex-grow-0 prevents growth. In the example below, the .flex-grow-1 element consumes all available space while the remaining items retain their natural size.
<div class="d-flex">
<div class="p-xs flex-grow-1">Flex item</div>
<div class="p-xs">Flex item</div>
<div class="p-xs">Flex item</div>
</div>.flex-shrink-0 prevents a flex item from shrinking below its natural size even when space is constrained. In the example below, the second item with .flex-shrink-0 holds its size even as the first item with .w-100 competes for space.
<div class="d-flex">
<div class="p-xs w-100">Flex item</div>
<div class="p-xs flex-shrink-0">Flex item with a lot of content</div>
</div>Responsive variants are available for flex-grow and flex-shrink.
.flex-{grow|shrink}-0.flex-{grow|shrink}-1.sm:flex-{grow|shrink}-0.sm:flex-{grow|shrink}-1.md:flex-{grow|shrink}-0.md:flex-{grow|shrink}-1.lg:flex-{grow|shrink}-0.lg:flex-{grow|shrink}-1.xl:flex-{grow|shrink}-0.xl:flex-{grow|shrink}-1.2xl:flex-{grow|shrink}-0.2xl:flex-{grow|shrink}-1
Fill and grow
.flex-fill forces sibling flex items to equal widths, consuming all available horizontal space regardless of their content.
<div class="d-flex mb-md">
<div class="p-xs flex-fill">Flex item with a lot of content</div>
<div class="p-xs flex-fill">Flex item</div>
<div class="p-xs flex-fill">Flex item</div>
</div>
<div class="d-flex">
<div class="p-xs flex-grow-1">Flex item with a lot of content</div>
<div class="p-xs flex-grow-1">Flex item</div>
<div class="p-xs flex-grow-1">Flex item</div>
</div>Responsive variants are available for flex-fill.
.flex-fill.sm:flex-fill.md:flex-fill.lg:flex-fill.xl:flex-fill.2xl:flex-fill
Auto margins
Auto margins push flex items away from each other. The examples below show three configurations: no auto margin, .me-auto pushing subsequent items right, and .ms-auto pulling an item to the right.
<div class="d-flex mb-md">
<div class="p-xs">Flex item</div>
<div class="p-xs">Flex item</div>
<div class="p-xs">Flex item</div>
</div>
<div class="d-flex mb-md">
<div class="me-auto p-xs">Flex item</div>
<div class="p-xs">Flex item</div>
<div class="p-xs">Flex item</div>
</div>
<div class="d-flex mb-md">
<div class="p-xs">Flex item</div>
<div class="p-xs">Flex item</div>
<div class="ms-auto p-xs">Flex item</div>
</div>With align-items
Combining flex-direction: column with mb-auto or mt-auto positions a single item at the top or bottom of the container.
<div class="d-flex align-items-start flex-column mb-md" style="height: 200px;">
<div class="mb-auto p-xs">Flex item</div>
<div class="p-xs">Flex item</div>
<div class="p-xs">Flex item</div>
</div>
<div class="d-flex align-items-end flex-column mb-md" style="height: 200px;">
<div class="p-xs">Flex item</div>
<div class="p-xs">Flex item</div>
<div class="mt-auto p-xs">Flex item</div>
</div>Wrap
Wrap utilities set the flex-wrap property. .flex-nowrap is the browser default; .flex-wrap allows items to flow onto multiple lines; .flex-wrap-reverse wraps in reverse order.
<div class="d-flex flex-nowrap">
...
</div><div class="d-flex flex-wrap">
...
</div><div class="d-flex flex-wrap-reverse">
...
</div>Responsive variants are available for flex-wrap.
.flex-nowrap.flex-wrap.flex-wrap-reverse.sm:flex-nowrap.sm:flex-wrap.sm:flex-wrap-reverse.md:flex-nowrap.md:flex-wrap.md:flex-wrap-reverse.lg:flex-nowrap.lg:flex-wrap.lg:flex-wrap-reverse.xl:flex-nowrap.xl:flex-wrap.xl:flex-wrap-reverse.2xl:flex-nowrap.2xl:flex-wrap.2xl:flex-wrap-reverse
Order
Order utilities set the visual sequence of flex items. Values 0–5 are available; custom CSS can extend this range.
<div class="d-flex flex-nowrap">
<div class="order-3 p-xs">First flex item</div>
<div class="order-2 p-xs">Second flex item</div>
<div class="order-1 p-xs">Third flex item</div>
</div>Responsive variants are available for order.
.order-0.order-1.order-2.order-3.order-4.order-5.sm:order-0.sm:order-1.sm:order-2.sm:order-3.sm:order-4.sm:order-5.md:order-0.md:order-1.md:order-2.md:order-3.md:order-4.md:order-5.lg:order-0.lg:order-1.lg:order-2.lg:order-3.lg:order-4.lg:order-5.xl:order-0.xl:order-1.xl:order-2.xl:order-3.xl:order-4.xl:order-5.2xl:order-0.2xl:order-1.2xl:order-2.2xl:order-3.2xl:order-4.2xl:order-5
.order-first applies order: -1; .order-last applies order: 6. Responsive variants are available for both.
.order-first.order-last.sm:order-first.sm:order-last.md:order-first.md:order-last.lg:order-first.lg:order-last.xl:order-first.xl:order-last.2xl:order-first.2xl:order-last
Align content
align-content utilities control how multiple lines of flex items are distributed along the cross axis. Available values: start (browser default), end, center, between, around, and stretch. The examples below use flex-wrap: wrap with an increased number of flex items to demonstrate the effect.
This property has no effect on single-line containers.
<div class="d-flex align-content-start flex-wrap">
...
</div><div class="d-flex align-content-end flex-wrap">...</div><div class="d-flex align-content-center flex-wrap">...</div><div class="d-flex align-content-between flex-wrap">...</div><div class="d-flex align-content-around flex-wrap">...</div><div class="d-flex align-content-stretch flex-wrap">...</div>Responsive variants are available for align-content.
.align-content-start.align-content-end.align-content-center.align-content-between.align-content-around.align-content-stretch.sm:align-content-start.sm:align-content-end.sm:align-content-center.sm:align-content-between.sm:align-content-around.sm:align-content-stretch.md:align-content-start.md:align-content-end.md:align-content-center.md:align-content-between.md:align-content-around.md:align-content-stretch.lg:align-content-start.lg:align-content-end.lg:align-content-center.lg:align-content-between.lg:align-content-around.lg:align-content-stretch.xl:align-content-start.xl:align-content-end.xl:align-content-center.xl:align-content-between.xl:align-content-around.xl:align-content-stretch.2xl:align-content-start.2xl:align-content-end.2xl:align-content-center.2xl:align-content-between.2xl:align-content-around.2xl:align-content-stretch
Place items
Use place-items utilities on CSS Grid containers as a shorthand to set both align-items and justify-items at once. This property controls how grid items are positioned within their grid areas on both axes.
Basic usage
Use place-items utilities to control the alignment of grid items. Choose from start, end, center, or stretch (browser default).
<div class="d-grid place-items-start">...</div>
<div class="d-grid place-items-end">...</div>
<div class="d-grid place-items-center">...</div>
<div class="d-grid place-items-stretch">...</div>Responsive
Responsive variations also exist for place-items.
.place-items-start.place-items-end.place-items-center.place-items-stretch.sm:place-items-start.sm:place-items-end.sm:place-items-center.sm:place-items-stretch.md:place-items-start.md:place-items-end.md:place-items-center.md:place-items-stretch.lg:place-items-start.lg:place-items-end.lg:place-items-center.lg:place-items-stretch.xl:place-items-start.xl:place-items-end.xl:place-items-center.xl:place-items-stretch.2xl:place-items-start.2xl:place-items-end.2xl:place-items-center.2xl:place-items-stretch
CSS
Flexbox utilities are generated via the utilities API.
Reference
The table lists all flexbox utilities and their CSS properties.
| Class | Properties |
|---|---|
.flex-fill | flex: 1; |
.flex-row | flex-direction: row; |
.flex-column | flex-direction: column; |
.flex-row-reverse | flex-direction: row-reverse; |
.flex-column-reverse | flex-direction: column-reverse; |
.flex-grow-0 | flex-grow: 0; |
.flex-grow-1 | flex-grow: 1; |
.flex-shrink-0 | flex-shrink: 0; |
.flex-shrink-1 | flex-shrink: 1; |
.flex-wrap | flex-wrap: wrap; |
.flex-nowrap | flex-wrap: nowrap; |
.flex-wrap-reverse | flex-wrap: wrap-reverse; |
.justify-content-start | justify-content: flex-start; |
.justify-content-end | justify-content: flex-end; |
.justify-content-center | justify-content: center; |
.justify-content-between | justify-content: space-between; |
.justify-content-around | justify-content: space-around; |
.justify-content-evenly | justify-content: space-evenly; |
.align-items-start | align-items: flex-start; |
.align-items-end | align-items: flex-end; |
.align-items-center | align-items: center; |
.align-items-baseline | align-items: baseline; |
.align-items-stretch | align-items: stretch; |
.align-content-start | align-content: flex-start; |
.align-content-end | align-content: flex-end; |
.align-content-center | align-content: center; |
.align-content-between | align-content: space-between; |
.align-content-around | align-content: space-around; |
.align-content-stretch | align-content: stretch; |
.align-self-auto | align-self: auto; |
.align-self-start | align-self: flex-start; |
.align-self-end | align-self: flex-end; |
.align-self-center | align-self: center; |
.align-self-baseline | align-self: baseline; |
.align-self-stretch | align-self: stretch; |
.order-first | order: -1; |
.order-0 | order: 0; |
.order-1 | order: 1; |
.order-2 | order: 2; |
.order-3 | order: 3; |
.order-4 | order: 4; |
.order-5 | order: 5; |
.order-last | order: 6; |
.place-items-start | place-items: start; |
.place-items-end | place-items: end; |
.place-items-center | place-items: center; |
.place-items-stretch | place-items: stretch; |
Utilities API
Flexbox utilities are declared in scss/utilities/_flex.scss using the utilities API.
"flex-fill": (
responsive: true,
property: flex,
values: (fill: 1)
),
"flex-direction": (
responsive: true,
property: flex-direction,
class: flex,
values: row column row-reverse column-reverse
),
"flex-grow": (
responsive: true,
property: flex-grow,
class: flex,
values: (
grow-0: 0,
grow-1: 1,
)
),
"flex-shrink": (
responsive: true,
property: flex-shrink,
class: flex,
values: (
shrink-0: 0,
shrink-1: 1,
)
),
"flex-wrap": (
responsive: true,
property: flex-wrap,
class: flex,
values: wrap nowrap wrap-reverse
),
"justify-content": (
responsive: true,
property: justify-content,
values: (
start: flex-start,
end: flex-end,
center: center,
between: space-between,
around: space-around,
evenly: space-evenly,
)
),
"align-items": (
responsive: true,
property: align-items,
values: (
start: flex-start,
end: flex-end,
center: center,
baseline: baseline,
stretch: stretch,
)
),
"align-content": (
responsive: true,
property: align-content,
values: (
start: flex-start,
end: flex-end,
center: center,
between: space-between,
around: space-around,
stretch: stretch,
)
),
"align-self": (
responsive: true,
property: align-self,
values: (
auto: auto,
start: flex-start,
end: flex-end,
center: center,
baseline: baseline,
stretch: stretch,
)
),
"order": (
responsive: true,
property: order,
values: (
first: -1,
0: 0,
1: 1,
2: 2,
3: 3,
4: 4,
5: 5,
last: 6,
),
),
"place-items": (
property: place-items,
values: (
start: start,
end: end,
center: center,
stretch: stretch,
)
),