Flex Shorthand Patterns
Master the flex shorthand and understand common values like flex: 1, flex: none, and flex: auto.
Flex Shorthand Patterns is a free CSS Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CSS Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The flex Shorthand Revisited
The flex shorthand sets flex-grow, flex-shrink, and flex-basis in one declaration. Understanding the shorthand variants is essential for real-world layouts.
flex: 1
flex: 1 is equivalent to flex: 1 1 0%. Items start from zero basis and grow equally to fill available space. This is the most common equal-column shorthand.
.equal-cols > * {
flex: 1; /* all columns equal width */
}flex: auto
flex: auto = flex: 1 1 auto. Items start from their natural content size and then grow/shrink proportionally. Wider content gets more space when growing.
.nav-links > a {
flex: auto; /* each link sized to its text, then grows equally */
}flex: none
flex: none = flex: 0 0 auto. Item is rigid — it does not grow or shrink. Size is determined by its natural content width or explicit width/height.
.logo {
flex: none;
width: 120px; /* always exactly 120px */
}flex: 0 0 Xpx
A fixed-size, non-flexible item. This is the most explicit way to create sidebar panels of exact widths:
.sidebar-left { flex: 0 0 240px; }
.sidebar-right { flex: 0 0 180px; }
.main-content { flex: 1; }flex: 1 vs flex: 1 1 auto
Key difference: with flex: 1 (basis 0%), all items start from 0 and grow proportionally. With flex: 1 1 auto, items start from their natural content size then grow. This affects how remaining space is distributed.
flex: 2 Ratio
Use non-equal flex-grow values for proportional distributions:
.main { flex: 2; } /* gets 2/3 of space */
.side { flex: 1; } /* gets 1/3 of space */Combining fixed and flexible
The most common real-world pattern: fixed sidebar + flexible main content:
.layout {
display: flex;
gap: 24px;
}
.sidebar { flex: 0 0 280px; }
.content { flex: 1; min-width: 0; }min-width: 0 Flex Trick
Flex items have a default min-width: auto. This can prevent them from shrinking below their content size. Set min-width: 0 on items that should shrink freely (like text containers with truncation).
.text-col {
flex: 1;
min-width: 0; /* allows text truncation to work */
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}Card Grid Pattern
Responsive card grid with flexible-but-bounded cards:
.card-grid {
display: flex;
flex-wrap: wrap;
gap: 16px;
}
.card {
flex: 1 1 280px;
min-width: 200px;
max-width: 400px;
}Debugging flex Shorthand
Use browser DevTools to inspect computed flex-grow, flex-shrink, and flex-basis values. The Flexbox inspector overlay also shows free space and item sizes visually.
Quick Check
What does flex: auto expand to?
Recap
Memorize the key flex shorthands: flex: 1 (equal columns from zero), flex: auto (grow from natural size), flex: none (rigid), flex: 0 0 Xpx (fixed size). Use min-width: 0 on flex children that contain text with truncation. Combine fixed and flexible items for classic sidebar layouts.
Frequently asked questions
Is the “Flex Shorthand Patterns” lesson free?
Yes — the full text of “Flex Shorthand Patterns” is free to read here on the web, and the CSS Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CSS Academy course, upgrade to CoddyKit PRO.
What will I learn in “Flex Shorthand Patterns”?
Master the flex shorthand and understand common values like flex: 1, flex: none, and flex: auto. You practise CSS Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start CSS Academy?
No prior experience is required. CSS Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Flex Shorthand Patterns” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this CSS Academy lesson?
Yes. Every CSS Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.