Enable Wrapping of Flex Items using CSS3

To enable wrapping of Flex Items using CSS3, the flex-wrap property is used. Set the value wrap to enable wrapping.

Following is the code for enabling wrapping of flex items using CSS3 −


 Live Demo

<!DOCTYPE html>
body {
   font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
.container {
   height: 300px;
   display: flex;
   width: 300px;
   border: 2px solid red;
   flex-wrap: wrap;
div {
   width: 150px;
   height: 100px;
   color: white;
   text-align: center;
   font-size: 20px;
.first {
   background-color: rgb(55, 0, 255);
.second {
   background-color: red;
.third {
   background-color: rgb(140, 0, 255);
<h1>Flex wrap example</h1>
<div class="container">
<div class="first">First Div</div>
<div class="second">Second Div</div>
<div class="third">Third Div</div>


The above code will produce the following output −

Updated on: 11-May-2020


Kickstart Your Career

Get certified by completing the course

Get Started