Open In App

HTML | DOM Style flexWrap Property

Last Updated : 08 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

DOM flexGrow property is used to determine whether the flexible items should wrap or not. 

Syntax:

  • Return flexWrap property:
object.style.flexWrap
  • Set flexWrap property:
object.style.flexWrap = "nowrap|wrap|wrap-reverse|
initial|inherit"

Properties:

  • nowrap: It specifies that the flexible items will not wrap.
  • wrap: It specifies that the flexible items will wrap if necessary.
  • wrap-reverse: It specifies that the flexible items will wrap, if necessary, in reverse order.
  • initial: It is used to set the property to its default value.
  • inherit: It is used to inherit the property values from the parent element.

Return Value: It returns a string, representing the flex-wrap property of the element. 

Example-1: Showing nowrap property 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
       HTML | DOM Style flexWrap Property
    </title>
</head>
    <body>
 
        <center>
            <h1>Geeks
              <button onclick="wrap()">
                Press
              </button>
            </h1>
        </center>
 
        <h4>
          Clicking on the 'Press' button will set the
          value of the flexWrap property to "nowrap".
        </h4>
 
        <style>
            #main {
                width: 150px;
                height: 150px;
                border: 1px solid #c3c3c3;
                display: -webkit-flex;
                -webkit-flex-wrap: wrap;
                display: flex;
                flex-wrap: wrap;
            }
             
            #main div {
                width: 50px;
                height: 50px;
            }
        </style>
 
        <div id="main">
            <div style="background-color:green;">G</div>
            <div style="background-color:white;">E</div>
            <div style="background-color:green;">E</div>
            <div style="background-color:white;">K</div>
            <div style="background-color:green;">S</div>
 
        </div>
 
        <script>
            function wrap() {
 
                // SAFARI
                document.getElementById(
                        "main").style.WebkitFlexWrap =
                    "nowrap";
 
                // Other Standard Browsers
                document.getElementById(
                        "main").style.flexWrap =
                    "nowrap";
            }
        </script>
 
    </body>
 
</html>


Output: 

Before clicking on the button: 

 

After clicking on the button: 

 

Example-2: Showing wrap-reverse property 

html




<!DOCTYPE html>
<html>
 
<body>
    <h1>
      <center>
        Geeks <button onclick="wrap()">Press
        </button>
      </center>
      </h1>
 
       <h4>Clicking on the 'Press' button will set the
       value of the flexWrap property to "wrap-reverse".</h4>
 
    <style>
        #main {
            width: 150px;
            height: 150px;
            border: 1px solid #c3c3c3;
            display: -webkit-flex;
            -webkit-flex-wrap: wrap;
            display: flex;
            flex-wrap: wrap;
        }
         
        #main div {
            width: 50px;
            height: 50px;
        }
    </style>
 
    <div id="main">
        <div style="background-color:green;">G</div>
        <div style="background-color:white;">E</div>
        <div style="background-color:green;">E</div>
        <div style="background-color:white;">K</div>
        <div style="background-color:green;">S</div>
 
    </div>
 
    <script>
        function wrap() {
           
            // SAFARI
            document.getElementById(
              "main").style.WebkitFlexWrap =
              "nowrap";
           
            // Other Standard Browsers
            document.getElementById(
              "main").style.flexWrap =
              "wrap-reverse";
        }
    </script>
 
</body>
 
</html>


Output: 

Before clicking on the button: 

 After clicking on the button: 

 

Example-3: Showing initial property 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML | DOM Style flexWrap Property
    </title>
</head>
 
<body>
 
    <center>
        <h1>Geeks <button onclick="wrap()">Press
        </button></h1>
    </center>
 
    <h4>Clicking on the 'Press' button will set the
    value of the flexWrap property to "initial".</h4>
 
    <style>
        #main {
            width: 150px;
            height: 150px;
            border: 1px solid #c3c3c3;
            display: -webkit-flex;
            -webkit-flex-wrap: wrap;
            display: flex;
            flex-wrap: wrap;
        }
         
        #main div {
            width: 50px;
            height: 50px;
        }
    </style>
 
    <div id="main">
        <div style="background-color:green;">G</div>
        <div style="background-color:white;">E</div>
        <div style="background-color:green;">E</div>
        <div style="background-color:white;">K</div>
        <div style="background-color:green;">S</div>
 
    </div>
 
    <script>
        function wrap() {
 
            // SAFARI
            document.getElementById(
                    "main").style.WebkitFlexWrap =
                "nowrap";
 
            // Other Standard Browsers
            document.getElementById(
                    "main").style.flexWrap =
                "initial";
        }
    </script>
 
</body>
 
</html>


Output: 

Before clicking on the button: 

 

After clicking on the button:

  

Example-4: Showing inherit property 

html




<!DOCTYPE html>
<html>
 
<body>
    <h1>
      <center>
        Geeks <button onclick="wrap()">Press
        </button>
      </center>
      </h1>
 
       <h4>Clicking on the 'Press' button will set
     the value of the flexWrap property to "inherit".</h4>
 
    <style>
        #main {
            width: 150px;
            height: 150px;
            border: 1px solid #c3c3c3;
            display: -webkit-flex;
            -webkit-flex-wrap: wrap;
            display: flex;
            flex-wrap: wrap;
        }
         
        #main div {
            width: 50px;
            height: 50px;
        }
    </style>
 
    <div id="main">
        <div style="background-color:green;">G</div>
        <div style="background-color:white;">E</div>
        <div style="background-color:green;">E</div>
        <div style="background-color:white;">K</div>
        <div style="background-color:green;">S</div>
 
    </div>
 
    <script>
        function wrap() {
           
            // SAFARI
            document.getElementById(
              "main").style.WebkitFlexWrap =
              "nowrap";
           
            // Other Standard Browsers
            document.getElementById(
              "main").style.flexWrap =
              "inherit";
        }
    </script>
 
</body>
 
</html>


Output: 

Before clicking on the button: 

 

After clicking on the button: 

 

Browser Support: The listed browsers support DOM flexWrap property:

  • Google Chrome 29 and above
  • Edge 12 and above
  • Firefox 28 and above
  • Internet Explorer 11.0 and above
  • Opera 17 and above
  • Safari 9 and above


Previous Article
Next Article

Similar Reads

HTML DOM Style backgroundClip Property
The DOM style backgroundClip Property is used to set or return the painting area of the background. Syntax: It is used to return the backgroundClip property.object.style.backgroundClip It is used to set the backgroundClip property. object.style.backgroundClip = "border-box|padding-box|content-box|initial|inherit" Property Values: border-box propert
1 min read
HTML DOM Style borderTop Property
The DOM style borderTop property is used to set or return the three different border-top property such as border-top-width, border-top-style, and border-top-color of an element. Syntax: It returns the borderTop property. object.style.borderTopIt is used to set the borderTop property. object.style.borderTop = "width style color|initial|inherit" Prop
2 min read
HTML | DOM Style columnGap Property
The DOM Style columnGap property specifies the gap between the columns. Syntax : For return the value: object.style.columnGap For set the value: object.style.columnGap = "length|normal|initial|inherit" Property Values: length: Set the column gap in length unit. normal: The default value of column gap. initial: Sets the default value. inherit: Inher
4 min read
HTML DOM Style boxSizing Property
The DOM Style boxSizing property is used to set or return how an object should be made to fit an element taking into consideration its padding, border, and content. This property can be useful when fitting elements into their desired position by automatically calculating their dimensions. Syntax: It returns the boxSizing Property:object.style.boxSi
5 min read
HTML | DOM Style borderImageSource Property
The DOM Style borderImageSource Property is used to set or return the image to be used instead of the styles given by the border-style property. Syntax: To get the borderImageSource propertyobject.style.borderImageSourceTo set the borderImageSource propertyobject.style.borderImageSource = "none | image | initial | inherit" Return Values: It returns
3 min read
HTML | DOM Style wordBreak Property
The DOM Style wordBreak Property is used to set or return the word-break property. The word-break property is used to specify how to break the word when the word is reached at the end of the line. The line breaks in the text can occur in a certain wordBreak property. Syntax: It is used to return the wordbreak Property:object.style.wordBreak It is u
2 min read
HTML | DOM Style pageBreakBefore Property
The pageBreakBefore property in HTML DOM is used to set or return the page-break-before characteristics before the specified element in HTML document. This property works in print and print preview mode. The pageBreakBefore property has no effect on absolutely positioned elements in the HTML DOM. The page break before attribute can only be effected
2 min read
HTML | DOM Style borderImageOutset Property
In the Style borderImageOutset Space which contains the border, image is to be painted is called the border-image space. By default, the boundaries of the border image area match with the boundaries of the element’s border-box. However, these boundaries can be extended using the border-image-outset property.The border-image-outset property specifie
4 min read
HTML | DOM Style maxHeight Property
The maxHeight property set/return the maximum height of an element. The maxHeight property affect only on block-level elements, absolute or fixed position elements. Syntax: It is used to set the maxHeight property:object.style.maxHeight = "none|length|%|initial|inherit"It is used to return the maxHeight property:object.style.maxHeight Return Values
2 min read
HTML | DOM Style columnRuleWidth Property
The Style columnRuleWidth property in HTML DOM is used to define or determine the width of the rule between the columns. Syntax: It returns the columnRuleWidth property.object.style.columnRuleWidthIt is used to set columnRuleWidth property.object.style.columnRuleWidth = "medium|thin|thick|length| initial|inherit" Property Values: thin: It is used t
3 min read
Article Tags :