Course Content
Bootstrap 5 Alerts
0/1
Progress Bars
0/1
Spinners
0/1
Pagination
0/1
List Groups
0/1
Bootstrap 5 Scrollspy
0/1
Bootstrap
About Lesson

Flex Wrap (flex-wrap)

By default, items stay in one line, but you can wrap them to the next line using:

  • flex-wrap → Allows wrapping
  • flex-nowrap → No wrapping (default)
  • flex-wrap-reverse → Wrap items in reverse order

Example:

HTML
  <div class="d-flex flex-wrap border border-2 w-25">
    <div class="p-3 bg-primary text-white">Item 1</div>
    <div class="p-3 bg-success text-white">Item 2</div>
    <div class="p-3 bg-danger text-white">Item 3</div>
    <div class="p-3 bg-warning text-dark">Item 5</div>
    <div class="p-3 bg-primary text-white">Item 6</div>
    <div class="p-3 bg-success text-white">Item 7</div>
    <div class="p-3 bg-danger text-white">Item 8</div>
  </div>
<br>
  <div class="d-flex flex-nowrap border border-2 w-25">
    <div class="p-3 bg-primary text-white">Item 1</div>
    <div class="p-3 bg-success text-white">Item 2</div>
    <div class="p-3 bg-danger text-white">Item 3</div>
    <div class="p-3 bg-warning text-dark">Item 5</div>
    <div class="p-3 bg-primary text-white">Item 6</div>
    <div class="p-3 bg-success text-white">Item 7</div>
    <div class="p-3 bg-danger text-white">Item 8</div>
  </div>
<br>
  <div class="d-flex flex-wrap-reverse border border-2 w-25">
    <div class="p-3 bg-primary text-white">Item 1</div>
    <div class="p-3 bg-success text-white">Item 2</div>
    <div class="p-3 bg-danger text-white">Item 3</div>
    <div class="p-3 bg-warning text-dark">Item 5</div>
    <div class="p-3 bg-primary text-white">Item 6</div>
    <div class="p-3 bg-success text-white">Item 7</div>
    <div class="p-3 bg-danger text-white">Item 8</div>
  </div>

Output: