CSS Portal

CSS flex-wrap Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The flex-wrap property controls whether flex items are forced onto a single line or allowed to form multiple lines inside a flex container. When wrapping is permitted, the items create additional flex lines along the container’s cross axis; each line is treated as a separate row (or column, depending on axis orientation) and items on later lines participate in layout and alignment independently of items on earlier lines. Allowing wrapping is a common way to prevent overflow of child elements and to enable more fluid, content-driven layouts where items naturally reflow when container size changes.

Because wrapping affects how items are distributed across the container’s axes, it must be considered together with how the container is established and oriented — for example, with display set to create a flex formatting context and the chosen flex-direction, which defines the main and cross axes. There is also a shorthand that combines orientation and wrapping behavior, flex-flow, making it convenient to set both aspects in a single declaration. Changes to the axis orientation or enabling wrapping can dramatically alter visual order, line breaks, and the direction in which new lines are added.

When multiple lines exist, the spacing and distribution of those lines along the cross axis is controlled separately from individual item alignment — for that purpose align-content becomes important, since it governs how the lines themselves are packed or stretched inside the container. Wrapping also interacts with item sizing behaviors (flex-basis, min/max constraints, and growth/shrink behavior) so that the same set of items can produce very different layouts depending on whether wrapping is allowed. Practically, enabling wrapping is a key tool for responsive design: it lets items reorganize into multiple rows or columns as available space changes, avoiding horizontal overflow and enabling predictable stacking without resorting to absolute positioning or media-query-only approaches.

Definition

Initial value
nowrap
Applies to
Flex containers
Inherited
No
Computed value
As specified
Animatable
No
JavaScript syntax
object.style.flexWrap

Interactive Demo

Item 1
Item 2
Item 3
Item 4
Item 5
Item 6

Syntax

flex-wrap: nowrap | wrap | wrap-reverse

Values

  • nowrapIndicates that flex items line up on a single line. This is the default value.
  • wrapIndicates that flex elements inside the container are located in several horizontal rows (in case of overflow). Flex elements are placed from left to right with the ltr direction (global HTML dir attribute, or CSS direction property with ltr value), and with rtl value they are placed from right to left.
  • wrap-reverseIndicates that the flex elements inside the container are arranged in several horizontal rows (in case of overflow) similar to the wrap value, but the lines are formed in the reverse order.

Example

<body>
<div class='container'>
<h2>flex-wrap: wrap</h2>

<div class='flex-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 class='item'>Item 5</div>
<div class='item'>Item 6</div>
<div class='item'>Item 7</div>
<div class='item'>Item 8</div>
<div class='item'>Item 9</div>
</div>
</div>
</body>
/* Simple demo of flex-wrap */
body {
  margin: 0;
  padding: 24px;
  font-family: system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #f3f4f6;
  color: #111827;
}

.container {
  max-width: 900px;
  margin: 0 auto;
}

h2 {
  margin: 0 0 12px 0;
  font-size: 18px;
  font-weight: 600;
}

.flex-container {
  display: flex;                 /* establishes flex formatting context */
  flex-wrap: wrap;              /* allow items to wrap onto multiple lines */
  gap: 12px;                    /* spacing between items and lines */
  padding: 16px;
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

.item {
  /* fixed base size so items will wrap when container is narrower */
  flex: 0 0 150px;              /* do not grow or shrink, base width 150px */
  height: 100px;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(16, 24, 40, 0.06);
}

/* Example alternative states (commented):
.flex-container-nowrap { flex-wrap: nowrap; }
.flex-container-wrap-reverse { flex-wrap: wrap-reverse; }
*/

Browser Support

The following information will show you the current browser support for the CSS flex-wrap property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!