flex-wrap - CSS: Cascading Style Sheets | MDN (2024)

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2015.

The flex-wrap CSS property sets whether flex items are forced onto one line or can wrap onto multiple lines. If wrapping is allowed, it sets the direction that lines are stacked.

Try it

The flex-flow property shorthand can be used to set both the flex-direction and flex-wrap properties, which define the flex container's main and cross axes, respectively.

Syntax

css

flex-wrap: nowrap; /* Default value */flex-wrap: wrap;flex-wrap: wrap-reverse;/* Global values */flex-wrap: inherit;flex-wrap: initial;flex-wrap: revert;flex-wrap: revert-layer;flex-wrap: unset;

Values

The flex-wrap property is specified as a single keyword chosen from the following values below:

nowrap

The flex items are laid out in a single line which may cause the flex container to overflow. The cross-start is the equivalent of inline-start or block-start, depending on the flex-direction value. This is the default value.

wrap

The flex items break into multiple lines. The cross-start is the equivalent of inline-start or block-start, depending on the current writing mode, and the flex-direction value.

wrap-reverse

Behaves the same as wrap, but cross-start and cross-end are inverted.

Formal definition

Initial valuenowrap
Applies toflex containers
Inheritedno
Computed valueas specified
Animation typediscrete

Formal syntax

flex-wrap = 
nowrap |
wrap |
wrap-reverse

Examples

Setting flex container wrap values

HTML

html

<h4>This is an example for flex-wrap:wrap</h4><div class="content"> <div class="red">1</div> <div class="green">2</div> <div class="blue">3</div></div><h4>This is an example for flex-wrap:nowrap</h4><div class="content1"> <div class="red">1</div> <div class="green">2</div> <div class="blue">3</div></div><h4>This is an example for flex-wrap:wrap-reverse</h4><div class="content2"> <div class="red">1</div> <div class="green">2</div> <div class="blue">3</div></div>

CSS

css

/* Common Styles */.content,.content1,.content2 { color: #fff; font: 100 24px/100px sans-serif; height: 150px; width: 897px; text-align: center;}.content div,.content1 div,.content2 div { height: 50%; width: 300px;}.red { background: orangered;}.green { background: yellowgreen;}.blue { background: steelblue;}/* Flexbox Styles */.content { display: flex; flex-wrap: wrap;}.content1 { display: flex; flex-wrap: nowrap;}.content2 { display: flex; flex-wrap: wrap-reverse;}

Results

Specifications

Specification
CSS Flexible Box Layout Module Level 1
# flex-wrap-property

Browser compatibility

BCD tables only load in the browser

See also

flex-wrap - CSS: Cascading Style Sheets | MDN (2024)

FAQs

What does Flex-wrap wrap do in CSS? ›

The flex-wrap CSS property sets whether flex items are forced onto one line or can wrap onto multiple lines. If wrapping is allowed, it sets the direction that lines are stacked.

How to prevent flex items from growing? ›

Using flex-grow Property

The Setting the flex-grow property to the 0 prevents the flex items from the growing.

How do you prevent flex from wrapping in CSS? ›

In this article we are going to learn about how to avoid wrapping flex items with CSS, this can be done by using the flex-wrap property with nowrap value to avoid flex-items to wrap.

What is the difference between Flex flow wrap and flex-wrap? ›

The 'flex-flow' property is a shorthand property for setting both the 'flex-direction' and 'flex-wrap' properties, which determines the main and cross axes of your flex items. The 'flex-direction' property sets the direction of the flex items while 'flex-wrap' property determines if the flex items should wrap or not.

What is the benefit of Flex in CSS? ›

CSS Flexbox

It works with various kinds of display devices and screen sizes. Flex layout makes it easier to design and build responsive web pages without using many float and position properties in the CSS code. To start using Flexbox, you have to create a flex container using the display: flex property.

How do wrappers work in CSS? ›

CSS content wrapping is the careful application of CSS properties to ensure content or text is wrapped according to the size of the container or block-level element on a web page. Correctly CSS wrapped content includes appropriate line breaks that ensure readable and clear content blocks.

How does flex work in CSS? ›

CSS Flexbox Example

The flex-wrap property tells the container to wrap its child elements onto the next line if there's not enough space for them on the first line. Here, the flex-basis property sets the width of each column to be 50% of the container width, so they will be equal in size.

What does flex grow do in CSS? ›

The flex-grow CSS property defines how much an element grows relative to other flexible items inside the same parent element. It determines how much space to allocate to an item in a flex parent when the available space exceeds the combined size of all the items.

How do you avoid flex items to shrink? ›

You can prevent elements like <svg> icons getting squished in a flexbox context by setting flex to none . This is really handy if you have a supporting icon because the default behaviour of a flex parent is to not wrap, which means elements will be forced to shrink as space runs out.

What is the difference between CSS grid and Flex wrap? ›

The basic difference between CSS grid layout and CSS flexbox layout is that flexbox was designed for layout in one dimension - either a row or a column. Grid was designed for two-dimensional layout - rows, and columns at the same time.

What are the disadvantages of Flex in CSS? ›

One of the major drawbacks of using flexbox is performance issues. The use of flexbox can increase the page loading time if you have a larger project. You can compare the page loading time through Chrome development tools using the flexbox and the same pages constructed without using flexbox.

What can I use instead of Flex in CSS? ›

I usually pick out positioning and display techniques based on the situation. If I want to display an image to the right of my text and I want the text to flow around it, then I will float the image. If I want three columns of content then I might use flex. If I want a mix of columns and rows I might use grid.

What is the alternative to Flex-wrap? ›

An alternative to using flex-wrap: wrap would be to switch from flex-direction: row to column using a media query. An other alternative to flex is to remove display: flex on the container and use display: inline-block on all item images.

Does Flex-wrap cause overflow? ›

The initial value of the flex-wrap property is nowrap . This means if a set of flex items is too wide for their flex container, they will overflow it. To make them wrap once they are too wide, add the flex-wrap property with a value of wrap , or use the shorthand flex-flow with values of row wrap or column wrap .

Does Flex Shrink work with Flex-wrap? ›

flex-wrap changes how things shrink

But once you tell your container to flex-wrap , then wrapping become a priority over shrinking. Keep this formula in mind: continue wrapping to new lines until each flex item has its own line, then begin shrinking items once their flex-basis is greater than the container size.

What does wrapping mean in CSS? ›

CSS text wrapping influences how text behaves within a webpage's layout. You can ensure that when a line of text reaches the end of its container (like a box or a column), it doesn't overflow beyond that space. Instead, the words will continue on the next line within the same container.

What does the flex tag do in CSS? ›

The flex CSS shorthand property sets how a flex item will grow or shrink to fit the space available in its flex container.

What does Flex box do in CSS? ›

Flexbox is a one-dimensional layout method for arranging items in rows or columns. Items flex (expand) to fill additional space or shrink to fit into smaller spaces. This article explains all the fundamentals.

What is the difference between flexbox wrap and grid? ›

Grid and flexbox. The basic difference between CSS grid layout and CSS flexbox layout is that flexbox was designed for layout in one dimension - either a row or a column. Grid was designed for two-dimensional layout - rows, and columns at the same time.

References

Top Articles
STAGES OF CLAY and 4'S
Neon Abyss Items Guide: Every Item in the Game, and What it Does – GameSpew
Corgsky Puppies For Sale
Parc Soleil Drowning
Buff Streams .Io
Academic Calendar Biola
Munsif Epaper Urdu Daily Online Today
Jsmainnn
Jacob Chapel Live Stream
Fatshark Forums
Swap Shop Elberton Ga
Email Hosting » Affordable Mail Solution with Personal Domain | IONOS
Nissan 300Zx For Sale Craigslist
John W Creasy Died December 16 2003
The Center Breakfast, Lunch & Snack Menus September 2024
Stepmom Full Video Hd
2006 Lebanon War | Summary, Casualties, & Israel
Omni Id Portal Waconia
R/Chinatime
Papa's Games Unblocked Games
Gas Buddy Prices Near Me Zip Code
American Flat Track Season Resumes At Orange County Fair Speedway - FloRacing
Cookie Clicker The Advanced Method
What Does Exp Wed Mean On Hulu
Ryan Conner Telegram
Connection | Scoop.it
Seconds Valuable Fun Welcoming Gang Back Andy Griffith's Birthday A Top Wish So A Happy Birthday FZSW A Fabulous Man Kevin Talks About Times From Ten Day Weekend Fun Labor Day Break
Christian Horner: Red Bull team principal to remain in role after investigation into alleged inappropriate behaviour
Between Friends Comic Strip Today
Big Boobs Indian Photos
Kris Carolla Obituary
Stephanie Ruhle's Husband
Find The Eagle Hunter High To The East
Best Places To Eat In Winter Park Fl
Patient Portal Bayfront
MyChart | University Hospitals
Sim7 Bus Time
Fx Channel On Optimum
2010 Ford F-350 Super Duty XLT for sale - Wadena, MN - craigslist
Roe V. Wade: The Abortion Rights Controversy in American History?second Edition, Revised and Expanded (Landmark Law Cases and American Society) - Taylor, Bob: 9780700617548
Target Minute Clinic Hours
Goose Band Setlists
Rg353M Vs Rg351Mp
Opsb Pay Dates
Star Wars Galaxy Of Heroes Webstore
Cranes for sale - used and new - TrucksNL
Exposedrealfun Collage
Ssndob Cm
Thc Detox Drinks At Walgreens
Evalue Mizzou
Greythr Hexaware Bps
I spruced up my kitchen for £131 - people can’t believe it’s the same room
Latest Posts
Article information

Author: Duane Harber

Last Updated:

Views: 5833

Rating: 4 / 5 (51 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Duane Harber

Birthday: 1999-10-17

Address: Apt. 404 9899 Magnolia Roads, Port Royceville, ID 78186

Phone: +186911129794335

Job: Human Hospitality Planner

Hobby: Listening to music, Orienteering, Knapping, Dance, Mountain biking, Fishing, Pottery

Introduction: My name is Duane Harber, I am a modern, clever, handsome, fair, agreeable, inexpensive, beautiful person who loves writing and wants to share my knowledge and understanding with you.