Bootstrap 5 Flex Container

flex container enables a flexbox layout, which provides powerful and efficient ways to align and distribute space among items in the container, even when their sizes are dynamic or unknown.

Warning

Some HTML elements have no content (like the <br→ element). These elements are called empty elements. Empty elements do not have an end tag!

Flex Direction:

Control the direction of flex items:


Syntax:

flex-{size?}-{direction}
  • flex: Indicates flex.
  • size (optional): Responsive breakpoint (e.g., sm : ≥576pxmd : ≥ 768pxlg : ≥992pxxl : ≥1200pxxxl : ≥1400px).
  • direction : Defines the direction of the margin (e.g., rowrow-reversecolumncolumn-reverse).


Example:

  • .flex-row
  • .flex-sm-row
  • .flex-md-row
  • .flex-lg-row
  • .flex-xl-row
  • .flex-xxl-row

Class

Description

flex-row

Horizontal (default).

flex-row-reverse

Reverse horizontal.

flex-column

Vertical direction.

flex-column-reverse

Reverse vertical.

Example
<div class="d-flex flex-row">
<div>Row Item 1</div>
<div>Row Item 2</div>
</div>

Flex Wrap:

Control whether flex items wrap onto multiple lines.


Syntax:

flex-{size?}-{type}
  • flex: Indicates flex.
  • size (optional): Responsive breakpoint (e.g., sm : ≥576pxmd : ≥ 768pxlg : ≥992pxxl : ≥1200pxxxl : ≥1400px).
  • type : Defines the direction of the margin (e.g., wrapwrap-reversenowrap).


Example:

  • .flex-wrap
  • .flex-sm-wrap
  • .flex-md-wrap
  • .flex-lg-wrap
  • .flex-xl-wrap
  • .flex-xxl-wrap

Class

Description

flex-wrap

Wrap items onto a new line.

flex-wrap-reverse 

Wrap in reverse.

flex-nowrap

Prevent wrapping.

Example
<div class="d-flex flex-wrap">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</div>

Justify Content:

Align flex items horizontally along the main axis.


Syntax:

justify-content-{size?}-{type}
  • justify-content: Indicates justify-content.
  • size (optional): Responsive breakpoint (e.g., sm : ≥576pxmd : ≥ 768pxlg : ≥992pxxl : ≥1200pxxxl : ≥1400px).
  • type : Defines the direction of the margin (e.g., startendcenterbetween,around,evenly).


Example:

  • .justify-content-start
  • .justify-content-sm-start
  • .justify-content-md-start
  • .justify-content-lg-start
  • .justify-content-xl-start
  • .justify-content-xxl-start

Class

Description

justify-content-start

Align items to the start.

justify-content-end

Align items to the end.

justify-content-center

Align items to the center.

justify-content-between

Space between items.

justify-content-around

Space around items.

justify-content-evenly

Space evenly items.

Example
<div class="d-flex justify-content-center">
<div>Item 1</div>
<div>Item 2</div>
</div>

Align Items:

Align items vertically along the cross-axis.


Syntax:

align-items-{size?}-{type}
  • align-items: Indicates align-items.
  • size (optional): Responsive breakpoint (e.g., sm : ≥576pxmd : ≥ 768pxlg : ≥992pxxl : ≥1200pxxxl : ≥1400px).
  • type : Defines the direction of the margin (e.g., startendcenterbaseline,stretch).


Example:

  • .align-items-start
  • .align-items-sm-start
  • .align-items-md-start
  • .align-items-lg-start
  • .align-items-xl-start
  • .align-items-xxl-start

Class

Description

align-items-start

Align to the start.

align-items-end

Align to the end.

align-items-center

Align to the center.

align-items-baseline

Align to the baseline.

align-items-stretch

Stretch items (default).

Example
<div class="d-flex align-items-center">
<div>Item 1</div>
<div>Item 2</div>
</div>

Align Content:

Align items vertically along the cross-axis.


Syntax:

align-content-{size?}-{type}
  • align-content: Indicates align-content.
  • size (optional): Responsive breakpoint (e.g., sm : ≥576pxmd : ≥ 768pxlg : ≥992pxxl : ≥1200pxxxl : ≥1400px).
  • type : Defines the direction of the margin (e.g., startendcenteraround,stretch).


Example:

  • .align-content-start
  • .align-content-sm-start
  • .align-content-md-start
  • .align-content-lg-start
  • .align-content-xl-start
  • .align-content-xxl-start

Class

Description

align-content-start

Align rows at start.

align-content-end

Align rows at end.

align-content-center

Align rows at center.

align-content-between

Space between rows.

align-content-around

Space around rows.

align-content-stretch

Stretch rows.

Example
<div class="d-flex align-content-center">
<div>Item 1</div>
<div>Item 2</div>
</div>

Gap:

Add spacing between flex items using gap classes:


Syntax:

gap-{size}
  • gap: Indicates gap.
  • size (optional): Responsive breakpoint (e.g., 01234):

Class

Description

gap-0

0px

gap-1

4px

gap-2

8px

gap-3

16px

gap-4

24px

gap-5

32px

Example
<div class="d-flex gap-3">
<div>Item 1</div>
<div>Item 2</div>
</div>

Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.