Flex Utility
Quickly manage the layout, alignment, and sizing of grid columns, navigation, components, and more with a full suite of responsive flexbox utilities.
Code Example
<div class="d-flex p-2 bg-lighter">I'm a flexbox container!</div>
Code Example
<div class="d-inline-flex p-2 bg-lighter">I'm an inline flexbox container!</div>
Direction
Default horizontal direction of flex item is row
. If you want to change direction then use flex-row
for horizontal direction, flex-row-reverse
for opposite horizontal direction. Default Vertical direction is column
,for it use flex-column
or flex-column-reverse
for opposit vertical direction
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>
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>
Justify content
On flexbox container use justify-content
utilities for change the alignment of flex items. There are many classes. just add (start, end, center, between, around)
with justify-content
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>
Align Items
On flexbox container use align-items
utilities for change the alignment of flex items on the cross axis. There are many classes. just add (start, end, center, baseline, stretch)
with align-items
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-stretch">...</div>
Align Self
On flexbox items use align-self
utilities for change the alignment. There are many classes. just add (start, end, center, baseline, stretch)
with align-self
.
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 flex-fill
class on flex-items
Code Example
<div class="d-flex bg-light"> <div class="p-2 flex-fill bg-light">Flex item with a lot of content</div> <div class="p-2 flex-fill bg-light">Flex item</div> <div class="p-2 flex-fill bg-light">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-light"> <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>
Code Example
<div class="d-flex bg-light"> <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 .ml-auto
, mr-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="mr-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="ml-auto p-2 bg-light">Flex item</div> </div>
With align-items
For margin top bottom auto just use .mt-auto
, mb-auto
class on flex items
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.
Code Example
<div class="d-flex flex-nowrap bg-light" style="width: 8rem;"> <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 class="p-2 bg-light">Flex item</div> <div class="p-2 bg-light">Flex item</div> </div>
Code Example
<div class="d-flex flex-wrap bg-light"> <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 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 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 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 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>
Code Example
<div class="d-flex flex-wrap-reverse bg-light"> <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 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 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 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 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>
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-light"> <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.
Code Example
<div class="d-flex align-content-start flex-wrap"> ... </div> <div class="d-flex align-content-end flex-wrap">...</div>