🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Expert Masterclasses.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEcss

css Documentation

LOADING ENGINE...

CSS Flex Wrap

Control the flow of flex items. Learn how to prevent squishing and create responsive layouts using the wrap property.

style.css
.container {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
1
2
3
4
5
flex-wrap.html
1 / 8
📦

Tutor:By default, flex containers are set to 'nowrap'. This means items will stay on a single line, shrinking if necessary to fit the container.


CSS Layout Mastery

Unlock nodes by learning Flexbox wrapping mechanics.

Concept 1: Flex Default

When you declare display: flex, the default flex-wrap value is nowrap. This forces all children to stay on a single line, shrinking them if necessary.

System Check

What happens by default if flex items are too wide for the container?


Community Flex-Net

Share Layouts

Built a cool grid using flex-wrap? Share your CSS patterns.

Enjoying this guide?

Codesyllabus is 100% free and open-source. Support our mission, pay for server infrastructure, and fuel new tutorials by buying us a coffee!

CSS Flex Wrap

Author

Pascual Vila

Frontend Instructor.

The flex-wrap property specifies whether the flex items should wrap or not. By default, flex items will try to fit onto one line. You can change that and allow the items to wrap as needed with this property.

Understanding Default Behavior

By default, flex-wrap is set to nowrap. This means that if you have a container that is 500px wide, and you put ten 100px wide items inside it, they will not wrap. Instead, they will shrink (if flex-shrink is allowed) or overflow the container.

The wrap Value

Setting flex-wrap: wrap; allows items to break onto multiple lines from top to bottom. This is essential for building responsive grids where the number of items per row changes based on the screen width.

The wrap-reverse Value

This value behaves like wrap, but the cross-start and cross-end directions are swapped. In a horizontal row, this means items wrap onto new lines above the previous line.

Best Practices

Use flex-wrap: wrap whenever you have a dynamic number of items or when items need to maintain a specific width regardless of container size. Combined with gap, it creates robust layout grids without media queries.

Flex Wrap Glossary

nowrap
The default value. All flex items will be on one line.
wrap
Flex items will wrap onto multiple lines, from top to bottom.
wrap-reverse
Flex items will wrap onto multiple lines, from bottom to top.
Cross Axis
The axis perpendicular to the main axis. When wrapping occurs, new lines are added along the cross axis.