Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape

CSS Flex Wrap

CSS Flex Wrap

CSS CODES & EXAMPLES

CSS Flex Wrap

Learn how the CSS flex-wrap property controls whether flex items stay on one line or move onto multiple lines when there is not enough available space.

01

What is Flex Wrap?

Control whether flex items wrap onto new lines

By default, Flexbox tries to keep all flex items on a single line. The flex-wrap property allows items to move onto additional rows or columns when the available space is not sufficient.

nowrap

All items remain on one line.

wrap

Items move onto additional lines when necessary.

wrap-reverse

Items wrap in the reverse cross-axis direction.

02

flex-wrap: nowrap

The default value

The default value is nowrap. Flex items remain on a single line even when the container becomes smaller.

flex-nowrap.css
.container {
  display: flex;
  flex-wrap: nowrap;
}
ITEM 1
ITEM 2
ITEM 3
ITEM 4
ITEM 5
ITEM 6
Note: With nowrap, the items try to stay on one line.
03

flex-wrap: wrap

Allow items to move to new lines

The wrap value allows flex items to move onto multiple lines when there is not enough space.

flex-wrap.css
.container {
  display: flex;
  flex-wrap: wrap;
}
ITEM 1
ITEM 2
ITEM 3
ITEM 4
ITEM 5
ITEM 6
ITEM 7
ITEM 8
04

flex-wrap: wrap-reverse

Reverse the wrapping direction

The wrap-reverse value allows items to wrap, but the new lines are placed in the reverse cross-axis direction.

wrap-reverse.css
.container {
  display: flex;
  flex-wrap: wrap-reverse;
}
1
2
3
4
5
6
See also  HTML Images
05

Flex Wrap Values

Quick visual comparison
nowrap
1 2 3 4

One line

wrap
1 2 3 4

Multiple lines

wrap-reverse
1 2 3 4

Reverse wrapping

06

Flex Wrap with Gap

Create clean spacing between wrapped items

Combining flex-wrap with gap is a common technique for creating responsive layouts.

responsive-grid.css
.container {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}
HTML
CSS
JavaScript
PHP
Python
SQL
07

Flex Wrap with flex-basis

Control the starting size of flex items

flex-basis defines the initial size of a flex item before remaining space is distributed.

flex-basis.css
.item {
  flex: 1 1 220px;
}

.container {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}
220px BASE
220px BASE
220px BASE
220px BASE
08

Responsive Card Layout

A practical website example

Flex wrapping is especially useful for responsive cards. Cards can automatically move to another row when the screen becomes smaller.

09

Flex Direction + Flex Wrap

Use both properties together
direction-wrap.css
.container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 20px;
}
1
2
3
4
5
6
10

Flex Wrap Quick Reference

Important values at a glance
ValueMeaningResult
nowrap Keep items on one line Single line
wrap Allow items to wrap Multiple lines
wrap-reverse Reverse the wrapping direction Reverse cross-axis lines
12

CSS Flex Wrap Live Example

Run the practical example
LIVE PREVIEW
`;document.getElementById( "sncecFWPreview" ).srcdoc=html;}document.addEventListener( "DOMContentLoaded", function(){sncecFWRun();} );

HTML Video

  • 17/08/2026

HTML Basic

  • 16/08/2026

CSS Box Model

  • 18/08/2026

Leave a Reply

Your email address will not be published. Required fields are marked *