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
  • BS5 Tutorial
  • BS5 Interview Questions
  • BS5 Layout
  • BS5 Content
  • BS5 Components
  • BS5 Helpers
  • BS5 Utilities
  • BS4 Tutorial
  • BS Tutorial
  • Bootstrap Cheatsheet
  • Tailwind
  • CSS Frameworks
  • HTML Formatter
Open In App
Next Article:
Bootstrap 5 Flex Grow and shrink
Next article icon

Bootstrap 5 Flex Grow and shrink

Last Updated : 02 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Bootstrap 5 Flex Grow and shrink is used to apply the expanding and shrinking look to an HTML div in a flexbox. By default, all the flex items will have the width/size until specified.

When we add the .flex-grow-1 to a  flex item it expands and covers up all the space which is available to it. Adding the .flex-grow-0 will keep the width of the flex-item as default. When we add the .flex-shrink-1 to a flex item to shrink whenever it is necessary and when the other items take up all the space that is available. Adding the .flex-shink-0 will stop the flex-item from shrinking. 

Bootstrap 5 Flex Grow and shrink Classes:

  • flex-grow-*: This class is required to be added to any flex item in a flexbox and the flex item will have the grow function when that * is replaced by 1 and they will stay as default when the * will be replaced by 0.
  • flex-shrink-*: This class is required to be added to any flex item in a flexbox and the flex item will have the shrink function when that * is replaced by 1 and they will stay as default when the * will be replaced by 0.

Syntax:

<div class="d-flex">
<div class="flex-grow-*">
....
</div>
</div>
<div class="d-flex">
<div class="flex-shrink-*">
....
</div>
</div>

Example 1: The code below demonstrates how we can use the flex-grow feature in the flexbox and how we can specify the screen size where it will start growing.

HTML
<!doctype html> <html lang="en">  <head>     <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"            rel="stylesheet"           integrity= "sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"            crossorigin="anonymous">     <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"            integrity= "sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"            crossorigin="anonymous">     </script> </head>  <body class="m-2">     <h1 class="text-success">GeeksforGeeks</h1>     <h4>Bootstrap 5 Flex Grow and shrink</h4>     <pre class="mt-4">         1st item having Flex Grow     </pre>     <div class="d-flex">         <div class="p-2 flex-grow-1                      bg-secondary border border-info">             1st Item         </div>         <div class="p-2 bg-secondary                      border border-info">             2nd Item         </div>         <div class="p-2 bg-secondary                       w-25 border border-info">             Third Item         </div>     </div>     <pre class="mt-4">         Responsive Flex Grow     </pre>     <div class="d-flex mt-4">         <div class="p-2 bg-success                      border border-danger">             Flex item         </div>         <div class="p-2 flex-lg-grow-1                      bg-success border                      border-danger">             Flex item         </div>         <div class="p-2 flex-lg-grow-1                      bg-success border                      border-danger">             Flex item         </div>         <div class="p-2 bg-success                      border border-danger">             Flex item         </div>     </div> </body>  </html> 

Output:

Example 2: The code below demonstrates how we can use the flex shrink feature in the flexbox and how we can specify the screen size where it will start shrinking.

HTML
<!doctype html> <html lang="en">  <head>     <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"            rel="stylesheet"           integrity= "sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"            crossorigin="anonymous">     <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"            integrity= "sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"            crossorigin="anonymous">     </script> </head>  <body class="m-2">     <h1 class="text-success">GeeksforGeeks</h1>     <h4>Bootstrap 5 Flex Grow and shrink</h4>     <pre class="mt-4">         1st item having Flex Shrink     </pre>     <div class="d-flex">         <div class="p-2 flex-shrink-1                      bg-secondary border border-info">              1st Item         </div>         <div class="p-2 bg-secondary w-100                      border border-info">             2nd Item         </div>         <div class="p-2 bg-secondary                      w-50 border border-info">             Third Item         </div>     </div>     <pre class="mt-4">         Responsive Flex Shrink     </pre>     <div class="d-flex mt-4">         <div class="p-2 w-25 bg-success border                      border-danger">             Flex item         </div>         <div class="p-2 w-25 flex-md-shrink-0                      bg-success border border-danger">             Flex item         </div>         <div class="p-2 w-25 flex-md-shrink-0                      bg-success border border-danger">             Flex item         </div>         <div class="p-2 w-100 bg-success                      border border-danger">             Flex item         </div>     </div>   </body>  </html> 

Output:

Reference: https://getbootstrap.com/docs/5.0/utilities/flex/#grow-and-shrink 


Next Article
Bootstrap 5 Flex Grow and shrink

P

priyanshuchatterjee01
Improve
Article Tags :
  • Web Technologies
  • Bootstrap
  • Bootstrap-5

Similar Reads

    Bulma Flex grow and flex shrink
    Bulma is an Open source CSS framework developed by Jeremy Thomas. This framework is based on the CSS Flexbox property. It is highly responsive, minimizing the use of media queries for responsive behavior. In this article, we will learn about Bulma flex-grow and flex-shrink properties. The Bulma fram
    2 min read
    Bootstrap 5 Flex Wrap
    Bootstrap 5's flex-wrap utility enables flexible layout control, allowing items to wrap as needed within a flex container. It offers options like nowrap, wrap, and wrap-reverse for responsive design.Bootstrap 5 Flex Wrap Classes:CSS ClassDescriptionflex-wrapChanges how flex items wrap in a flex cont
    2 min read
    Bootstrap 5 Flex Align Self
    Bootstrap5 Flex Align Self property is used to change each item's alignment individually on the cross-axis. By default, it starts from the y-axis, if we want to change the alignment on the x-axis change the value of the class flex-direction to the column. There are some classes that can be used to s
    3 min read
    Bootstrap 5 Flex Align items
    Bootstrap 5 Flex Align items to change the alignment of flex items on the cross-axis using align-items classes. The CSS align-items property sets the distribution of space between and around content items along a flexbox's cross-axis or a grid's block axis. iframe { width: 100%; height: 500px;} @med
    3 min read
    Bootstrap 5 Flex Order
    Bootstrap 5 Flex order class can be used to set the order of the flex items inside the flex irrespective of their position in the DOM. We have to select options to make an item first or the last remaining items will follow the order. The order takes integer values from 0-5 and some custom values are
    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