VOOZH about

URL: https://www.geeksforgeeks.org/bootstrap/bootstrap-5-flex/

⇱ Bootstrap 5 Flex - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bootstrap 5 Flex

Last Updated : 23 Jul, 2025

Bootstrap 5 Flex offers utility classes for creating flexible layouts using Flexbox, ensuring responsiveness across screen sizes. To start, wrap desired elements in a flex container with classes like .container or .row. Then, use flex utility classes to control item layout.

AspectDescription
Flex DirectionControls flex item arrangement direction. The default is a row for horizontal alignment.
Justify ContentAlign flex items along the main axis: flex-start, center, flex-end, space-around, or space-between.
Align ItemsChanges flex item alignment on the cross-axis (vertical/horizontal depending on flex-direction).
Align SelfAdjusts single flex item alignment on the cross-axis, independently from others in the container.
FillForces flex items into equal widths while utilizing all available horizontal space.
Grow and ShrinkDetermines flex item growth and shrinkage relative to others in container based on available space.
Auto MarginsUtility classes for adding auto margins to flex items, aiding in various layout alignments.
WrapAlters how flex items wrap in container: no wrap, wrap, or wrap in reverse direction.
OrderChanges visual order of specific flex items using integer values, altering item sequencing.
Align ContentControls flex item alignment on cross-axis in multiline flex containers.
Media ObjectCombines .media and .media-body classes for consistent alignment of media objects with content.
SassSoftware as a service (SaaS) for building responsive web apps using Bootstrap 5.

Syntax:

<div class="d-flex p-2 ">
 ....
</div>

Using Justify content:

justify-content in Bootstrap 5 Flex is a property that aligns flex items along the main axis. It controls how the space is distributed between and around flex items, allowing for various alignments like center, start, end, space-between, and more.

Syntax:

<div class="d-flex justify-content-center">
 ...
</div>

Example: In this example, we have a container with a flex container inside it. The flex container has three flex items, each with a different background color. We're using the "justify-content-center" and "align-items-center" classes to center the flex items both horizontally and vertically within the flex container.

Output:

👁 Bootstrap 5 Flex

Using Direction:

In Bootstrap 5 Flex, flex-direction is a property that determines the direction in which flex items are laid out. It allows for both horizontal (row) and vertical (column) orientations.

Syntax:

<div class="d-flex flex-column">
 ...
</div>
<div class="d-flex flex-column-reverse">
 ...
</div>

Example: In this example, we are using flex-column to set our items (1,2, and 3) in the vertical direction and we use flex-column-reverse to set the item(4,5 and 6) vertically from the opposite side.

Output:

👁 Bootstrap 5 Flex

Comment
Article Tags:

Explore