Flex
Quickly manage the layout, alignment, and sizing of grid columns, navigation, components, and more with a full suite of responsive flexbox utilities. For more complex implementations, custom CSS may be necessary.
| Class | Styles |
|---|---|
| .flex-fill | flex: 1 1 auto; |
| .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; |
Enable flex behaviors
Apply display utilities to create a flexbox container and transform direct children elements into flex items. Flex containers and items are able to be modified further with additional flex properties.
<div class="d-flex p-2">I'm a flexbox container!</div> <div class="d-inline-flex p-2">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-2xl-flex.d-2xl-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.
<div class="d-flex flex-row mb-3">
<div class="p-2">Flex item 1</div>
<div class="p-2">Flex item 2</div>
<div class="p-2">Flex item 3</div>
</div>
<div class="d-flex flex-row-reverse">
<div class="p-2">Flex item 1</div>
<div class="p-2">Flex item 2</div>
<div class="p-2">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.
<div class="d-flex flex-column mb-3">
<div class="p-2">Flex item 1</div>
<div class="p-2">Flex item 2</div>
<div class="p-2">Flex item 3</div>
</div>
<div class="d-flex flex-column-reverse">
<div class="p-2">Flex item 1</div>
<div class="p-2">Flex item 2</div>
<div class="p-2">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-2xl-row.flex-2xl-row-reverse.flex-2xl-column.flex-2xl-column-reverse
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.
<div class="d-flex">
<div class="p-2 flex-fill">Flex item with a lot of content</div>
<div class="p-2 flex-fill">Flex item</div>
<div class="p-2 flex-fill">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-2xl-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 uses all available space it can, while allowing the remaining two flex items their necessary space.
<div class="d-flex">
<div class="p-2 flex-grow-1">Flex item</div>
<div class="p-2">Flex item</div>
<div class="p-2">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.
<div class="d-flex">
<div class="p-2 w-100">Flex item</div>
<div class="p-2 flex-shrink-1">Flex item</div>
</div> Responsive variations also exist for flex-grow and flex-shrink.
.flex-grow-0.flex-grow-1.flex-shrink-0.flex-shrink-1.flex-sm-grow-0.flex-sm-grow-1.flex-sm-shrink-0.flex-sm-shrink-1.flex-md-grow-0.flex-md-grow-1.flex-md-shrink-0.flex-md-shrink-1.flex-lg-grow-0.flex-lg-grow-1.flex-lg-shrink-0.flex-lg-shrink-1.flex-xl-grow-0.flex-xl-grow-1.flex-xl-shrink-0.flex-xl-shrink-1.flex-2xl-grow-0.flex-2xl-grow-1.flex-2xl-shrink-0.flex-2xl-shrink-1
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.
<div class="d-flex flex-nowrap">
...
</div><div class="d-flex flex-wrap">
...
</div><div class="d-flex flex-wrap-reverse">
...
</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-2xl-nowrap.flex-2xl-wrap.flex-2xl-wrap-reverse
CSS
Sass utilities API
Flexbox utilities are declared in our utilities API in scss/_utilities.scss. Learn how to use the utilities API.
"flex": (
responsive: true,
property: flex,
values: (fill: 1 1 auto)
),
"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,
)
),
"justify-items": (
responsive: true,
property: justify-items,
values: (
start: start,
end: end,
center: center,
stretch: stretch,
)
),
"justify-self": (
responsive: true,
property: justify-self,
values: (
start: flex-start,
end: flex-end,
center: center,
)
),
"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,
)
),
"place-items": (
responsive: true,
property: place-items,
values: (
start: start,
end: end,
center: center,
stretch: stretch,
)
),
"grid-column-counts": (
responsive: true,
property: --columns,
class: grid-cols,
values: (
3,
4,
6
)
),
"grid-columns": (
responsive: true,
property: grid-column,
class: grid-cols,
values: (
fill: #{"1 / -1"},
)
),
"grid-auto-flow": (
responsive: true,
property: grid-auto-flow,
class: grid-auto-flow,
values: row column dense
),
"order": (
responsive: true,
property: order,
values: (
first: -1,
0: 0,
1: 1,
2: 2,
3: 3,
4: 4,
5: 5,
last: 6,
),
),