Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS flex-grow Property

Posted in CSS Tutorial
Updated on Aug 06, 2024
By Mari Selvan
👁️ 14 - Views
⏳ 4 mins
💬 1 Comment
CSS flex-grow Property

Photo Credit to CodeToFun

🙋 Introduction

The flex-grow property in CSS is used in flexbox layouts to define the ability of a flex item to grow relative to the rest of the flex items inside the same container.

This property is a crucial part of creating responsive and dynamic layouts, as it allows flex items to expand and fill available space.

💡 Syntax

The syntax for the flex-grow property is simple and involves specifying a positive number, which represents the proportion of available space the item should take up relative to other flex items.

Syntax
Copied
Copy To Clipboard
element {
  flex-grow: number;
}

Here, number is a unitless value that determines how much of the available space inside the flex container the item should take up.

🎛️ Default Value

The default value of the flex-grow property is 0, which means the flex item will not grow and will only take up the space it needs based on its content.

🏠 Property Values

ValueDescription
numberA unitless value that represents the flex grow factor. A value of 0 means the item will not grow. Positive integers specify how much the item will grow relative to the other flex items.

📄 Example

In this example, we'll create a flex container with three items. The second item will be set to grow twice as much as the first item, while the third item will not grow.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS flex-grow Example</title>
  <style>
    .container {
      display: flex;
    }
    .item {
      padding: 10px;
      color: white;
    }
    .item1 {
      background-color: red;
      flex-grow: 1;
    }
    .item2 {
      background-color: green;
      flex-grow: 2;
    }
    .item3 {
      background-color: blue;
      flex-grow: 0;
    }
  </style>
</head>
<body>
  <h1>Flex-grow Property Example</h1>
  <div class="container">
    <div class="item item1">Item 1</div>
    <div class="item item2">Item 2</div>
    <div class="item item3">Item 3</div>
  </div>
</body>
</html>

🖥️ Browser Compatibility

The flex-grow property is widely supported in modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. It is well-supported across both desktop and mobile browsers, making it a reliable choice for responsive design.

🎉 Conclusion

The flex-grow property is an essential tool for web developers working with flexbox layouts. It provides a simple and effective way to control the distribution of space among flex items, allowing for the creation of flexible and responsive designs.

By understanding and utilizing this property, you can enhance the layout and adaptability of your web projects.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy