CSS flex-wrap Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Flexbox

What You’ll Learn

The flex-wrap property controls whether flex items stay on one line or wrap onto multiple lines. It is essential for responsive layouts that adapt to different screen sizes and orientations.

01

nowrap

Single line.

02

wrap

Multi-line flow.

03

wrap-reverse

Reverse lines.

04

Container

On parent.

05

Responsive

Adapt layouts.

06

flex-flow

Shorthand pair.

Introduction

The flex-wrap property in CSS is used in flexbox layouts to control whether flex items are forced onto one line or can wrap onto multiple lines. This property is essential for creating responsive designs that adapt to different screen sizes and orientations.

Definition and Usage

Apply flex-wrap on a flex container with display: flex or display: inline-flex. Use wrap for card grids, tag lists, and toolbars where items should move to the next line when horizontal space runs out. Use nowrap when every item must stay on a single row or column.

💡
Beginner Tip

By default, flex items try to stay on one line (nowrap). If items overflow or get squashed, try flex-wrap: wrap so they flow onto new lines instead.

📝 Syntax

The syntax for the flex-wrap property is simple and can be applied to any flex container:

syntax.css
.container {
  flex-wrap: nowrap | wrap | wrap-reverse;
}

Basic Example

flex-wrap-basic.css
.card-grid {
  display: flex;
  flex-wrap: wrap;
}
flex-wrap: nowrap; flex-wrap: wrap; flex-wrap: wrap-reverse;

Default Value

The default value of the flex-wrap property is nowrap, meaning that all flex items will be kept on a single line, even if they overflow the container.

Syntax Rules

  • Apply on the flex container, not on individual flex items.
  • Requires display: flex or display: inline-flex on the same element.
  • Accepts exactly three keyword values: nowrap, wrap, and wrap-reverse.
  • The property is not inherited.
  • Wrapping behavior depends on the main axis set by flex-direction.

⚡ Quick Reference

QuestionAnswer
Initial valuenowrap
Applies toFlex containers
InheritedNo
Value typeKeyword (nowrap, wrap, wrap-reverse)
Common patterndisplay: flex; flex-wrap: wrap; for responsive grids

💎 Property Values

ValueDescription
nowrapAll flex items are kept on a single line. Overflow is not prevented — items may shrink or spill outside the container.
wrapFlex items wrap onto multiple lines from top to bottom (in a row flex container) when they run out of space along the main axis.
wrap-reverseFlex items wrap onto multiple lines in the reverse cross-axis direction — from bottom to top in a row flex container.

nowrap vs wrap

With nowrap, four 100px items inside a 200px container stay on one row and overflow or shrink. With wrap, the same items break into two rows of two, keeping readable sizes without horizontal scrolling.

👀 Live Preview

A 220px container with four 90px items using flex-wrap: wrap — items flow onto a second line when they no longer fit:

Item 1 Item 2 Item 3 Item 4

Examples Gallery

In this example, we’ll create a flex container with items that wrap onto multiple lines — plus nowrap comparison, wrap-reverse, and a responsive tag list.

🔀 Multi-Line Layouts

Start with the reference example — items that wrap when the container is too narrow.

Example 1 — Flex Container with Wrapping Items

Four 100px items inside a 200px container wrap onto two rows when flex-wrap: wrap is set.

flex-wrap-basic.html
<style>
  .container {
    display: flex;
    flex-wrap: wrap;
    width: 200px;
    border: 1px solid #000;
  }
  .item {
    width: 100px;
    height: 50px;
    background: lightblue;
    margin: 5px;
    text-align: center;
    line-height: 50px;
  }
</style>

<div class="container">
  <div class="item">Item 1</div>
  <div class="item">Item 2</div>
  <div class="item">Item 3</div>
  <div class="item">Item 4</div>
</div>
Try It Yourself

How It Works

Only two 100px items fit in the 200px row. Items 3 and 4 move to a second line because wrapping is enabled.

Example 2 — nowrap vs wrap

Compare the default single-line behavior with wrapping on the same item sizes.

flex-wrap-compare.css
.nowrap-row {
  display: flex;
  flex-wrap: nowrap; /* default */
}

.wrap-row {
  display: flex;
  flex-wrap: wrap;
}
Try It Yourself

How It Works

nowrap forces all items onto one line, which can cause overflow. wrap lets items move to the next line for a cleaner layout.

🔄 Wrap Variants

Control the direction new flex lines are added with wrap-reverse.

Example 3 — wrap-reverse

New lines stack in the opposite cross-axis direction compared to normal wrap.

flex-wrap-reverse.css
.reverse-wrap {
  display: flex;
  flex-wrap: wrap-reverse;
  width: 200px;
}
Try It Yourself

How It Works

Items still wrap when they run out of room, but additional lines appear above the first line instead of below it (in a row flex container).

Example 4 — Responsive Tag List

A common real-world use: tags or chips that wrap naturally on smaller screens.

flex-wrap-tags.css
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag {
  padding: 0.35rem 0.75rem;
  background: #dbeafe;
  border-radius: 999px;
}
Try It Yourself

How It Works

Tags keep their natural width and flow onto new lines as the container narrows — no fixed column count required.

♿ Accessibility

  • Keep logical DOM order — wrapping is visual; screen readers follow source order, not line breaks.
  • Ensure wrapped items remain reachable with keyboard navigation on every viewport size.
  • Do not rely on line position alone to communicate meaning or priority.
  • Maintain enough spacing between wrapped items so touch targets do not overlap.
  • Test with zoom and small screens to confirm wrapped content stays readable.

🧠 How flex-wrap Works

1

Items fill the main axis

Flex items are placed along the main axis until the current line runs out of space.

First line
2

Wrap decides the next step

With nowrap, items stay on one line. With wrap, overflow moves to a new line.

Keyword
3

New lines stack on the cross axis

wrap adds lines downward; wrap-reverse adds them in the opposite direction.

Cross axis
=

Responsive multi-line layout

Content adapts to container width without horizontal scrolling or crushed items.

🖥 Browser Compatibility

The flex-wrap property is widely supported in all modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. You can use it confidently in production projects.

Baseline · Universal support

flex-wrap everywhere

All three keyword values work consistently in every modern browser as part of standard Flexbox.

99% Universal support
Google Chrome 29+ · Desktop & Mobile
Full support
Mozilla Firefox 28+ · Desktop & Mobile
Full support
Apple Safari 9+ · macOS & iOS
Full support
Microsoft Edge 12+ · All versions
Full support
Opera 17+ · Modern versions
Full support
flex-wrap property 99% supported

Bottom line: flex-wrap is safe for all modern projects. Pair it with flex-direction or use the flex-flow shorthand.

🎉 Conclusion

The flex-wrap property is a valuable tool for web developers looking to create flexible and responsive layouts. By allowing flex items to wrap onto multiple lines, you can design layouts that adapt to various screen sizes and orientations, providing a better user experience.

Experiment with different values of flex-wrap to see how they can enhance the look and functionality of your web projects. For beginners, remember: default is nowrap, use wrap for responsive grids, and wrap-reverse when lines should stack in the opposite direction.

💡 Best Practices

✅ Do

  • Use flex-wrap: wrap for card grids, tags, and chip lists
  • Combine with gap for consistent spacing between wrapped items
  • Pair with align-content to control spacing between wrapped lines
  • Use flex-flow: row wrap as a concise shorthand when needed
  • Test layouts at multiple viewport widths

❌ Don’t

  • Apply flex-wrap on flex items instead of the container
  • Assume wrapping happens automatically — the default is nowrap
  • Use wrap-reverse without checking that visual order still makes sense
  • Forget that nowrap can cause overflow or heavy shrinking
  • Rely on wrapping alone when a CSS Grid layout may be clearer

Key Takeaways

Knowledge Unlocked

Five things to remember about flex-wrap

Use these points when building multi-line flex layouts.

5
Core concepts
nowrap 02

Default nowrap

Single line.

Default
wrap 03

Three values

nowrap, wrap, reverse.

Values
📂 04

Container only

On parent.

Target
📱 05

Responsive

Adapts to width.

Use case

❓ Frequently Asked Questions

The flex-wrap property controls whether flex items stay on one line or wrap onto multiple lines when they do not fit inside the flex container along the main axis.
The default value is nowrap, which keeps all flex items on a single line even if they overflow the container.
wrap moves overflowing items to new lines from top to bottom in a row container. wrap-reverse fills new lines in the opposite cross-axis direction, so lines appear from bottom to top.
flex-wrap applies to the flex container (the element with display: flex), not to individual flex items.
flex-wrap only controls wrapping. flex-flow is a shorthand that sets both flex-direction and flex-wrap in one declaration.

Practice in the Live Editor

Open the HTML editor, toggle between nowrap and wrap, and resize the container to see items break onto new lines.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful