HomeTutorsContact

How To Use Flex Wrap(flex-wrap) In CSS?

By Gulshan Saini
Published in CSS
May 16, 2020
1 min read

Flex container layout items horizontally or vertically using the flex-direction value of row or column respectively. By default, a flex container will try to fit its child elements on one line. Flexbox container might overflow if the size of items exceeds container size

Let’s look at below example to understand the problem

As we can see above the Column Seven does not fit within the container on the same row. Another, thing to notice is the text within the container automatically wraps - this happens because flex container tried to fit the items.

Intro to flex-wrap

To fix this problem and automatically move the problematic item(s) on next row we have a flex-wrap property that can be set to wrap as follows

Let’s add this property to previous example

See, how column five, column six, and column seven moved to the second row, and the text inside the columns is also displayed on a single line. Isn’t it awesome?

flex-wrap also accepts other values i.e. wrap-reverse and nowrap(default)

wrap-reverse behaves the same as a wrap but cross-start and cross-end are permuted.

Try out wrap-reverse in above playground.

Responsive Design

I think flex-wrap is great for responsive design as it will automatically wrap the content on the next row and you don’t have to worry about the responsive breakpoints.

Learn more about flex-direction

Like this article? Follow @devtutorialtips on Twitter


Tags

#css
Previous Article
How To Use flex-direction In CSS?

Gulshan Saini

Fullstack Developer

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Related Posts

How to use CSS custom variables and properties?

June 06, 2020
2 min
© 2020, All Rights Reserved.

Quick Links

Advertise with usContact Us

Social Media