Currently Empty: ₹0.00
CSS Flex Shorthand
CSS CODES & EXAMPLES
CSS Flex Shorthand
Learn how the flex shorthand combines
flex-grow, flex-shrink, and
flex-basis into one powerful CSS declaration.
01
What is Flex Shorthand?
Combine three Flexbox properties
The CSS flex property is a shorthand for
flex-grow, flex-shrink, and
flex-basis.
Remember:
The common three-value pattern is:
flex: grow shrink basis;
02
Basic Syntax
Three values in one declaration
flex-shorthand.css
.item {
flex: 1 1 200px;
}The three values represent: grow, shrink, and basis.
03
Three-Value Syntax
flex-grow + flex-shrink + flex-basis
three-values.css
.item {
flex: 1 1 250px;
}
1
flex-grow
Can receive extra space
1
flex-shrink
Can shrink when needed
250px
flex-basis
Initial main size
04
flex: 1
Common responsive pattern
The value flex: 1 is a very common way to make
flex items share available space. It is especially useful for
equal-width cards and columns.
flex-one.css
.item {
flex: 1;
}Flex 1
Flex 1
Flex 1
05
flex: 0 1 auto
Useful explicit default-style pattern
This three-value form explicitly sets grow to
0, shrink to 1, and basis to
auto.
flex-auto.css
.item {
flex: 0 1 auto;
}Meaning:
Do not grow automatically, allow shrinking, and use the
item’s main-size information as the basis.
06
flex: 0 0 200px
Fixed-size flex item
With grow and shrink both set to 0, the item
does not participate in flexible growth or shrinking.
fixed-flex.css
.item {
flex: 0 0 200px;
}Fixed 200px
Flexible Item
07
flex: 1 1 250px
Flexible item with a starting sizeThis is useful when you want an item to start around
250px, grow when extra space exists, and shrink
when the container becomes smaller.
responsive-flex.css
.item {
flex: 1 1 250px;
}1 1 250px
1 1 250px
1 1 250px
08
Two-Value Syntax
Grow and shrink values
The flex shorthand also supports shorter forms.
When two unitless numbers are supplied, they represent grow
and shrink.
two-values.css
.item {
flex: 2 1;
}Example:
flex: 2 1; means grow factor
2 and shrink factor 1, with the
basis using the shorthand’s omitted-value rules.
09
One-Value Syntax
Quick Flexbox patternsflex: 1;Flexible item that shares available space.
flex: 2;Gets a larger grow factor than flex: 1.
flex: 0;Does not grow and uses a zero flex basis.
flex: auto;Commonly maps to 1 1 auto.
flex: none;Commonly maps to 0 0 auto.
10
Flex Shorthand vs Separate Properties
Same concept, shorter code
separate-properties.css
.item {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 250px;
}Can be written as:
shorthand.css
.item {
flex: 1 1 250px;
}
11
Responsive Course Cards
Practical website example
12
Important Points
Quick revision
✓
flex is shorthand for
flex-grow, flex-shrink, and
flex-basis.
✓
The three-value syntax follows:
grow shrink basis.
✓
flex: 1 is commonly used for equal flexible
columns.
✓
flex: none is useful when an item should not
grow or shrink.
✓
A length or percentage can be used as the flex basis.
✓
Flex shorthand makes responsive layout CSS shorter and easier to maintain.
13
Practice Task
Build a responsive three-column layout🎯 Your Challenge
Create three responsive cards using the Flex shorthand.
-
Set the parent to
display: flex; -
Add
gap: 20px; -
Give every card
flex: 1 1 250px; - Add a mobile media query.
- Change the card basis and observe the result.
14
CSS Flex Shorthand Live Runner
Run and experiment with the exampleLIVE PREVIEW



