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.
Example
Code Example
<div class="d-flex p-2 bg-light">I'm a flexbox container!</div> <div class="d-inline-flex p-2 bg-light">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.
Code Example
<div class="d-flex flex-row bg-lighter mb-3"> <div class="p-2 bg-light">Flex item 1</div> <div class="p-2 bg-light">Flex item 2</div> <div class="p-2 bg-light">Flex item 3</div> </div> <div class="d-flex flex-row-reverse bg-lighter"> <div class="p-2 bg-light">Flex item 1</div> <div class="p-2 bg-light">Flex item 2</div> <div class="p-2 bg-light">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.
Code Example
<div class="d-flex flex-column bg-lighter mb-3"> <div class="p-2 bg-light">Flex item 1</div> <div class="p-2 bg-light">Flex item 2</div> <div class="p-2 bg-light">Flex item 3</div> </div> <div class="d-flex flex-column-reverse bg-lighter"> <div class="p-2 bg-light">Flex item 1</div> <div class="p-2 bg-light">Flex item 2</div> <div class="p-2 bg-light">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
.
Code Example
<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 variations also exist for justify-content
.
.justify-content-start
.justify-content-end
.justify-content-center
.justify-content-between
.justify-content-around
.justify-content-evenly
.justify-content-sm-start
.justify-content-sm-end
.justify-content-sm-center
.justify-content-sm-between
.justify-content-sm-around
.justify-content-sm-evenly
.justify-content-md-start
.justify-content-md-end
.justify-content-md-center
.justify-content-md-between
.justify-content-md-around
.justify-content-md-evenly
.justify-content-lg-start
.justify-content-lg-end
.justify-content-lg-center
.justify-content-lg-between
.justify-content-lg-around
.justify-content-lg-evenly
.justify-content-xl-start
.justify-content-xl-end
.justify-content-xl-center
.justify-content-xl-between
.justify-content-xl-around
.justify-content-xl-evenly
.justify-content-xxl-start
.justify-content-xxl-end
.justify-content-xxl-center
.justify-content-xxl-between
.justify-content-xxl-around
.justify-content-xxl-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).
Code Example
<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-around">...</div> <div class="d-flex align-items-stretch">...</div>
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, stretch
(browser default).
Code Example
<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>
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.
Code Example
<div class="d-flex bg-lighter"> <div class="p-2 flex-fill bg-light border">Flex item with a lot of content</div> <div class="p-2 flex-fill bg-light border">Flex item</div> <div class="p-2 flex-fill bg-light border">Flex item</div> </div>
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.
Code Example
<div class="d-flex bg-lighter"> <div class="p-2 flex-grow-1 bg-light">Flex item</div> <div class="p-2 bg-light">Flex item</div> <div class="p-2 bg-light">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
.
Code Example
<div class="d-flex bg-lighter"> <div class="p-2 w-100 bg-light">Flex item</div> <div class="p-2 flex-shrink-1 bg-light">Flex item</div> </div>
Auto margins
For margin left right auto just use .ms-auto
, .me-auto
class on flex items
Code Example
<div class="d-flex bg-lighter mb-3"> <div class="p-2 bg-light">Flex item</div> <div class="p-2 bg-light">Flex item</div> <div class="p-2 bg-light">Flex item</div> </div> <div class="d-flex bg-lighter mb-3"> <div class="me-auto p-2 bg-light">Flex item</div> <div class="p-2 bg-light">Flex item</div> <div class="p-2 bg-light">Flex item</div> </div> <div class="d-flex bg-lighter mb-3"> <div class="p-2 bg-light">Flex item</div> <div class="p-2 bg-light">Flex item</div> <div class="ms-auto p-2 bg-light">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
.
Code Example
<div class="d-flex align-items-start flex-column bg-lighter mb-3" style="height: 200px;"> <div class="mb-auto p-2 bg-light">Flex item</div> <div class="p-2 bg-light">Flex item</div> <div class="p-2 bg-light">Flex item</div> </div> <div class="d-flex align-items-end flex-column bg-lighter mb-3" style="height: 200px;"> <div class="p-2 bg-light">Flex item</div> <div class="p-2 bg-light">Flex item</div> <div class="mt-auto p-2 bg-light">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
.
flex-nowrap
flex-wrap
flex-wrap-reverse
Code Example
<-- flex-nowrap --> <div class="d-flex flex-nowrap bg-lighter"> ... </div> <-- flex-wrap --> <div class="d-flex flex-wrap bg-lighter"> ... </div> <-- flex-wrap-reverse --> <div class="d-flex flex-wrap-reverse bg-lighter"> ... </div>
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.
Code Example
<div class="d-flex flex-nowrap bg-lighter"> <div class="order-3 p-2 bg-light">First flex item</div> <div class="order-2 p-2 bg-light">Second flex item</div> <div class="order-1 p-2 bg-light">Third flex item</div> </div>
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.
.align-content-start
.align-content-end
.align-content-center
.align-content-between
.align-content-around
.align-content-stretch
Code Example
<-- align-content-start --> <div class="d-flex align-content-start flex-wrap"> ... </div> <-- align-content-end --> <div class="d-flex align-content-end flex-wrap"> ... </div> <-- align-content-center --> <div class="d-flex align-content-center flex-wrap"> ... </div> <-- align-content-between --> <div class="d-flex align-content-between flex-wrap"> ... </div> <-- align-content-around --> <div class="d-flex align-content-around flex-wrap"> ... </div> <-- align-content-stretch --> <div class="d-flex align-content-stretch flex-wrap"> ... </div>
Media object
Create it with a few flex utilities
Vertically center
Code Example
<div class="d-flex"> <div class="flex-shrink-0"> <img src="#" alt="..."> </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. This is some content from a media component. You can replace this with any content and adjust it as needed. This is some content from a media component. You can replace this with any content and adjust it as needed. </div> </div> <-- Vertically center --> <div class="d-flex"> <div class="flex-shrink-0"> <img src="#" alt="..."> </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. This is some content from a media component. You can replace this with any content and adjust it as needed. This is some content from a media component. You can replace this with any content and adjust it as needed. </div> </div>