CSS
🎯 CSS flex Property
The flex CSS property is a shorthand property used in Flexbox layouts that defines how a flex item grows, shrinks, and its initial size inside a container.
It combines flex-grow, flex-shrink, and flex-basis into a single rule for easier layout control.
🔹 flex Syntax
flex: flex-grow flex-shrink flex-basis;
🔹 flex Values
1️⃣ flex-grow
Defines how much a flex item grows relative to others when extra space is available.
2️⃣ flex-shrink
Defines how much a flex item shrinks when space is limited.
3️⃣ flex-basis
Sets the initial size of the flex item before growing or shrinking.
4️⃣ auto
The item size is calculated automatically based on content.
5️⃣ initial
Resets the property to default value (0 1 auto).
🧩 Example Usage
.container {
display: flex;
}
.item {
flex: 2 1 150px;
}
This means the item grows more than others, shrinks normally, and starts with 150px base width.
-
✔️ Quick Summary
- flex is a shorthand for flex-grow, flex-shrink, flex-basis
- Used in Flexbox layouts for responsive design
- Helps control item sizing behavior inside containers
