CSS Academy · Lesson

Flex Shorthand Patterns

Master the flex shorthand and understand common values like flex: 1, flex: none, and flex: auto.

Lesson 3 of 413 steps

Flex Shorthand Patterns is a free CSS Academy lesson on CoddyKit. This is 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, and your progress syncs across the web and the CoddyKit app. The CSS Academy course includes 4 lessons in total.

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.

<div class="equal-cols">
  <div>A</div>
  <div>B</div>
  <div>C</div>
</div>

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.

<div class="nav-links">
  <a href="#">Home</a>
  <a href="#">About Us</a>
  <a href="#">Contact</a>
</div>

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.

<div class="row">
  <div class="logo">Logo</div>
  <div>Flexible content</div>
</div>

flex: 0 0 Xpx

A fixed-size, non-flexible item. This is the most explicit way to create sidebar panels of exact widths:

<div class="layout">
  <div class="sidebar-left">Left</div>
  <div class="main-content">Main</div>
  <div class="sidebar-right">Right</div>
</div>

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:

<div class="split">
  <div class="main">Main (2/3)</div>
  <div class="side">Side (1/3)</div>
</div>

Combining fixed and flexible

The most common real-world pattern: fixed sidebar + flexible main content:

<div class="layout">
  <div class="sidebar">Sidebar 280px</div>
  <div class="content">Flexible content</div>
</div>

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).

<div class="row">
  <div class="text-col">This is a very long line of text that needs to truncate with an ellipsis inside a flex item.</div>
</div>

Card Grid Pattern

Responsive card grid with flexible-but-bounded cards:

<div class="card-grid">
  <div class="card">Card 1</div>
  <div class="card">Card 2</div>
  <div class="card">Card 3</div>
</div>

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.

Free to start

Learn CSS with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
40
Lessons
159

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. 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. The CSS Academy course includes 4 lessons in total.

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, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.

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.

All lessons in this course

  1. Flex Item Alignment Override with align-self
  2. Order Property and Visual Reordering
  3. Flex Shorthand Patterns
  4. Common Flexbox Layouts: Nav Cards Media Object
← Back to CSS Academy