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.
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_sth
and .d-inline-flex_sth
.
.d-flex_sth
.d-inline-flex_sth
.d-sm-flex_sth
.d-sm-inline-flex_sth
.d-md-flex_sth
.d-md-inline-flex_sth
.d-lg-flex_sth
.d-lg-inline-flex_sth
.d-xl-flex_sth
.d-xl-inline-flex_sth
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_sth
to set a horizontal direction (the browser default), or .flex-row-reverse_sth
to start the horizontal direction from the opposite side.
<div class="d-flex_sth flex-row_sth">
<div class="p-2_sth">Flex item 1</div>
<div class="p-2_sth">Flex item 2</div>
<div class="p-2_sth">Flex item 3</div>
</div>
<div class="d-flex_sth flex-row-reverse_sth">
<div class="p-2_sth">Flex item 1</div>
<div class="p-2_sth">Flex item 2</div>
<div class="p-2_sth">Flex item 3</div>
</div>
Use .flex-column_sth
to set a vertical direction, or .flex-column-reverse_sth
to start the vertical direction from the opposite side.
<div class="d-flex_sth flex-column_sth">
<div class="p-2_sth">Flex item 1</div>
<div class="p-2_sth">Flex item 2</div>
<div class="p-2_sth">Flex item 3</div>
</div>
<div class="d-flex_sth flex-column-reverse_sth">
<div class="p-2_sth">Flex item 1</div>
<div class="p-2_sth">Flex item 2</div>
<div class="p-2_sth">Flex item 3</div>
</div>
Responsive variations also exist for flex-direction
.
.flex-row_sth
.flex-row-reverse_sth
.flex-column_sth
.flex-column-reverse_sth
.flex-sm-row_sth
.flex-sm-row-reverse_sth
.flex-sm-column_sth
.flex-sm-column-reverse_sth
.flex-md-row_sth
.flex-md-row-reverse_sth
.flex-md-column_sth
.flex-md-column-reverse_sth
.flex-lg-row_sth
.flex-lg-row-reverse_sth
.flex-lg-column_sth
.flex-lg-column-reverse_sth
.flex-xl-row_sth
.flex-xl-row-reverse_sth
.flex-xl-column_sth
.flex-xl-column-reverse_sth
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
, or around
.
<div class="d-flex_sth justify-content-start_sth">...</div>
<div class="d-flex_sth justify-content-end_sth">...</div>
<div class="d-flex_sth justify-content-center_sth">...</div>
<div class="d-flex_sth justify-content-between_sth">...</div>
<div class="d-flex_sth justify-content-around_sth">...</div>
Responsive variations also exist for justify-content
.
.justify-content-start_sth
.justify-content-end_sth
.justify-content-center_sth
.justify-content-between_sth
.justify-content-around_sth
.justify-content-sm-start_sth
.justify-content-sm-end_sth
.justify-content-sm-center_sth
.justify-content-sm-between_sth
.justify-content-sm-around_sth
.justify-content-md-start_sth
.justify-content-md-end_sth
.justify-content-md-center_sth
.justify-content-md-between_sth
.justify-content-md-around_sth
.justify-content-lg-start_sth
.justify-content-lg-end_sth
.justify-content-lg-center_sth
.justify-content-lg-between_sth
.justify-content-lg-around_sth
.justify-content-xl-start_sth
.justify-content-xl-end_sth
.justify-content-xl-center_sth
.justify-content-xl-between_sth
.justify-content-xl-around_sth
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).
<div class="d-flex_sth align-items-start_sth">...</div>
<div class="d-flex_sth align-items-end_sth">...</div>
<div class="d-flex_sth align-items-center_sth">...</div>
<div class="d-flex_sth align-items-baseline_sth">...</div>
<div class="d-flex_sth align-items-stretch_sth">...</div>
Responsive variations also exist for align-items
.
.align-items-start_sth
.align-items-end_sth
.align-items-center_sth
.align-items-baseline_sth
.align-items-stretch_sth
.align-items-sm-start_sth
.align-items-sm-end_sth
.align-items-sm-center_sth
.align-items-sm-baseline_sth
.align-items-sm-stretch_sth
.align-items-md-start_sth
.align-items-md-end_sth
.align-items-md-center_sth
.align-items-md-baseline_sth
.align-items-md-stretch_sth
.align-items-lg-start_sth
.align-items-lg-end_sth
.align-items-lg-center_sth
.align-items-lg-baseline_sth
.align-items-lg-stretch_sth
.align-items-xl-start_sth
.align-items-xl-end_sth
.align-items-xl-center_sth
.align-items-xl-baseline_sth
.align-items-xl-stretch_sth
Align self
Use align-self
utilities on flexbox items to individually change their alignment on the cross axis (the y-axis to start, x-axis if flex-direction: column
). Choose from the same options as align-items
: start
, end
, center
, baseline
, or stretch
(browser default).
<div class="align-self-start_sth">Aligned flex item</div>
<div class="align-self-end_sth">Aligned flex item</div>
<div class="align-self-center_sth">Aligned flex item</div>
<div class="align-self-baseline_sth">Aligned flex item</div>
<div class="align-self-stretch_sth">Aligned flex item</div>
Responsive variations also exist for align-self
.
.align-self-start_sth
.align-self-end_sth
.align-self-center_sth
.align-self-baseline_sth
.align-self-stretch_sth
.align-self-sm-start_sth
.align-self-sm-end_sth
.align-self-sm-center_sth
.align-self-sm-baseline_sth
.align-self-sm-stretch_sth
.align-self-md-start_sth
.align-self-md-end_sth
.align-self-md-center_sth
.align-self-md-baseline_sth
.align-self-md-stretch_sth
.align-self-lg-start_sth
.align-self-lg-end_sth
.align-self-lg-center_sth
.align-self-lg-baseline_sth
.align-self-lg-stretch_sth
.align-self-xl-start_sth
.align-self-xl-end_sth
.align-self-xl-center_sth
.align-self-xl-baseline_sth
.align-self-xl-stretch_sth
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 (.mr-auto
), and pushing two items to the left (.ml-auto
).
Unfortunately, IE10 and IE11 do not properly support auto margins on flex items whose parent has a non-default justify-content
value. See this StackOverflow answer for more details.
<div class="d-flex_sth">
<div class="p-2_sth">Flex item</div>
<div class="p-2_sth">Flex item</div>
<div class="p-2_sth">Flex item</div>
</div>
<div class="d-flex_sth">
<div class="mr-auto_sth p-2_sth">Flex item</div>
<div class="p-2_sth">Flex item</div>
<div class="p-2_sth">Flex item</div>
</div>
<div class="d-flex_sth">
<div class="p-2_sth">Flex item</div>
<div class="p-2_sth">Flex item</div>
<div class="ml-auto_sth p-2_sth">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
.
<div class="d-flex_sth align-items-start_sth flex-column_sth" style="height: 200px;">
<div class="mb-auto_sth p-2_sth">Flex item</div>
<div class="p-2_sth">Flex item</div>
<div class="p-2_sth">Flex item</div>
</div>
<div class="d-flex_sth align-items-end_sth flex-column_sth" style="height: 200px;">
<div class="p-2_sth">Flex item</div>
<div class="p-2_sth">Flex item</div>
<div class="mt-auto_sth p-2_sth">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
.
<div class="d-flex_sth flex-nowrap_sth">
...
</div>
<div class="d-flex_sth flex-wrap_sth">
...
</div>
<div class="d-flex_sth flex-wrap-reverse_sth">
...
</div>
Responsive variations also exist for flex-wrap
.
.flex-nowrap_sth
.flex-wrap_sth
.flex-wrap-reverse_sth
.flex-sm-nowrap_sth
.flex-sm-wrap_sth
.flex-sm-wrap-reverse_sth
.flex-md-nowrap_sth
.flex-md-wrap_sth
.flex-md-wrap-reverse_sth
.flex-lg-nowrap_sth
.flex-lg-wrap_sth
.flex-lg-wrap-reverse_sth
.flex-xl-nowrap_sth
.flex-xl-wrap_sth
.flex-xl-wrap-reverse_sth
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 (e.g., 5
), add custom CSS for any additional values needed.
<div class="d-flex_sth flex-nowrap_sth">
<div class="order-3_sth p-2_sth">First flex item</div>
<div class="order-2_sth p-2_sth">Second flex item</div>
<div class="order-1_sth p-2_sth">Third flex item</div>
</div>
Responsive variations also exist for order
.
.order-1_sth
.order-2_sth
.order-3_sth
.order-4_sth
.order-5_sth
.order-6_sth
.order-7_sth
.order-8_sth
.order-9_sth
.order-10_sth
.order-11_sth
.order-12_sth
.order-sm-1_sth
.order-sm-2_sth
.order-sm-3_sth
.order-sm-4_sth
.order-sm-5_sth
.order-sm-6_sth
.order-sm-7_sth
.order-sm-8_sth
.order-sm-9_sth
.order-sm-10_sth
.order-sm-11_sth
.order-sm-12_sth
.order-md-1_sth
.order-md-2_sth
.order-md-3_sth
.order-md-4_sth
.order-md-5_sth
.order-md-6_sth
.order-md-7_sth
.order-md-8_sth
.order-md-9_sth
.order-md-10_sth
.order-md-11_sth
.order-md-12_sth
.order-lg-1_sth
.order-lg-2_sth
.order-lg-3_sth
.order-lg-4_sth
.order-lg-5_sth
.order-lg-6_sth
.order-lg-7_sth
.order-lg-8_sth
.order-lg-9_sth
.order-lg-10_sth
.order-lg-11_sth
.order-lg-12_sth
.order-xl-1_sth
.order-xl-2_sth
.order-xl-3_sth
.order-xl-4_sth
.order-xl-5_sth
.order-xl-6_sth
.order-xl-7_sth
.order-xl-8_sth
.order-xl-9_sth
.order-xl-10_sth
.order-xl-11_sth
.order-xl-12_sth
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.
<div class="d-flex_sth align-content-start_sth flex-wrap_sth">
...
</div>
<div class="d-flex_sth align-content-end_sth flex-wrap_sth">...</div>
<div class="d-flex_sth align-content-center_sth flex-wrap_sth">...</div>
<div class="d-flex_sth align-content-between_sth flex-wrap_sth">...</div>
<div class="d-flex_sth align-content-around_sth flex-wrap_sth">...</div>
<div class="d-flex_sth align-content-stretch_sth flex-wrap_sth">...</div>
Responsive variations also exist for align-content
.
.align-content-start_sth
.align-content-end_sth
.align-content-center_sth
.align-content-around_sth
.align-content-stretch_sth
.align-content-sm-start_sth
.align-content-sm-end_sth
.align-content-sm-center_sth
.align-content-sm-around_sth
.align-content-sm-stretch_sth
.align-content-md-start_sth
.align-content-md-end_sth
.align-content-md-center_sth
.align-content-md-around_sth
.align-content-md-stretch_sth
.align-content-lg-start_sth
.align-content-lg-end_sth
.align-content-lg-center_sth
.align-content-lg-around_sth
.align-content-lg-stretch_sth
.align-content-xl-start_sth
.align-content-xl-end_sth
.align-content-xl-center_sth
.align-content-xl-around_sth
.align-content-xl-stretch_sth