Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App
Next Article:
HTML | DOM Style flex Property
Next article icon

HTML | DOM Style flex Property

Last Updated : 08 Aug, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

The HTML DOM Style flex property sets/returns the length of the item, relative to rest of flexible items inside the same container. The flexGrow, flexShrink, and the flexBasis are the properties of Flex property. 

Syntax:

  • It is used to return the style flex property:
 object.style.flex
  • It is used to set the flex property:
object.style.flex = "flex-grow flex-shrink flex-basis|auto| initial|inherit"

Return Values: It returns a string value, which represents the flex property of an element

Property values:

ValueDescription
flex-growIt specify how much the item will grow relative to the rest of the flexible items
flex-shrinkIt specify how much the item will shrink relative to the rest of the flexible items
flex-basisIt specify the length of the item. Legal values: "auto", "inherit" and number followed by "%", "px", "em"
autoSame as 1 1 auto
initialSame as 0 1 auto
inheritInherit the property from it's parent element.

Example-1: Same length of all div. 

html
<!DOCTYPE html> <html>  <head>     <title>         HTML | DOM Style flex Property     </title>     <style>         #gfg {             width: 220px;             height: 60px;             border: 1px solid black;             display: -webkit-flex;             /* Safari */             display: flex;         }     </style> </head>  <body>     <center>         <h1 style="color: green;">           GeeksforGeeks         </h1>                <h2 style="color: black;">           DOM Style flex Property         </h2>              <div id="gfg">          <div style="background-color:green;">Geeks             <div style="background-color:lightblue;">For                     <div style="background-color:green;">                       Geeks                     </div>             </div>          </div>       </div>         <br>                <button onclick="GEEKS()">CLICK</button>                <script>             function GEEKS() {                 var x = document.getElementById("gfg");                 var y = x.getElementsByTagName("DIV");                 var i = 0;                 for (i; i < y.length; i++) {                     // IE10                     y[i].style.msFlex = "1";                                         // Safari 6.1+                     y[i].style.WebkitFlex = "1";                      y[i].style.flex = "1";                 }             }         </script>     </center> </body>  </html> 

Output: 

Before Click on the Button:

  

After Click on the Button:

  

Example-2: Flex items according to its content: 

html
<!DOCTYPE html> <html>  <head>     <title>         HTML | DOM Style flex Property     </title>     <style>         #gfg {             width: 220px;             height: 300px;             border: 1px solid black;             display: -webkit-flex;             /* Safari */             display: flex;         }     </style> </head>  <body>     <center>         <h1 style="color: green;">           GeeksforGeeks         </h1>         <h2 style="color: black;">           DOM Style flex Property         </h2>         <div id="gfg">             <div style="background-color:green;">               Geeks1            </div>             <div style="background-color:lightblue;">               For1           </div>             <div style="background-color:green;">               GEEKS1           </div>         </div>         <br>                <button onclick="GEEKS()">CLICK</button>                <script>             function GEEKS() {                 var x =                   document.getElementById("gfg");                 var y =                   x.getElementsByTagName("DIV");                 var i = 0;                 for (i; i < y.length; i++) {                     // IE10                     y[i].style.msFlex = "0";                      // Safari 6.1+                     y[i].style.WebkitFlex = "0";                      y[i].style.flex = "1 125px";                 }             }         </script>     </center> </body>  </html> 

Output: 

Before Click on the Button:

  

After Click on the Button: 

 

Supported Browsers: The browser supported by DOM Style flex property are listed below:

  • Google Chrome 29 and above
  • Edge 12 and above
  • Internet Explorer 11.0 and above
  • Firefox 20.0 and above
  • Opera 12.1 and above
  • Apple Safari 9.0 and above

Next Article
HTML | DOM Style flex Property

J

jeetesh16
Improve
Article Tags :
  • Web Technologies
  • HTML
  • HTML-DOM

Similar Reads

    HTML | DOM Style flexWrap Property
    DOM flexGrow property is used to determine whether the flexible items should wrap or not. Syntax: Return flexWrap property:object.style.flexWrapSet flexWrap property:object.style.flexWrap = "nowrap|wrap|wrap-reverse| initial|inherit" Properties: nowrap: It specifies that the flexible items will not
    3 min read
    HTML | DOM Style flexFlow Property
    The Style flexFlow property in HTML DOM is used to specify the value for two different properties flexDirection property and flexWrap property. The flexDirection property is used to specify the direction of flexible items and flexWrap property is used to specify the flexible item should wrap or not.
    4 min read
    HTML | DOM Style flexGrow Property
    The HTML DOM style flexGrow property is used as a measure to determine how much an item will grow relative to the rest of the flexible items inside the same container. Syntax: Return flexGrow property:object.style.flexGrowSet flexGrow property:object.style.flexGrow = "number|initial|inherit" Propert
    3 min read
    HTML | DOM Style flexBasis Property
    The DOM Style flexBasis property is used to set or return the initial length of a flexible item. Note: If the element is not a flexible item, this property would have no effect. Syntax: It returns the flexBasis Property:object.style.flexBasisIt used to set the flexBasis Property:object.style.flexBas
    4 min read
    HTML | DOM Style flexShrink Property
    The Style flexShrink property in HTML DOM is used to set how the specific item can be shrink in relation to the remaining flexible items within the container. Syntax: It is used to return the flexShrink property.object.style.flexShrinkIt is used to set the flexShrink property.object.style.flexShrink
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences