CSS: CSS Flexbox Items

🗓 Last updated: 2026-11-30👤 Written by: Casey✓ Reviewed by: Dana🏷 Category: CSS Tutorial

Flexbox item properties give you fine control over individual children within a flex container.

Properties in this section: flex-grow flex-shrink flex-basis flex order align-self align-items

1. Flex Item Properties

(1) Quick Reference

Property Values Purpose
flex-grow 0, 1, 2, ... How much item grows relative to siblings
flex-shrink 0, 1, 2, ... How much item shrinks relative to siblings
flex-basis auto, 100px, 50% Initial size before grow/shrink
flex 1, 0 0 200px, 1 1 auto Shorthand for grow, shrink, basis
order 0, 1, -1 Visual order (doesn't affect DOM)
align-self auto, flex-start, flex-end, center Override parent's align-items

2. flex-grow

Controls how much a flex item grows relative to other items:

▶ Example

▶ Try it Yourself

3. flex: 1 Shorthand

flex: 1 is the most common shorthand:

▶ Example

▶ Try it Yourself

flex: 1 means flex-grow: 1; flex-shrink: 1; flex-basis: 0% — "grow to fill available space equally."


4. order

Changes visual order without affecting DOM order:

▶ Example

▶ Try it Yourself

Note: order only changes visual order, not DOM order. Screen readers still follow DOM order.


5. align-self

Overrides parent's align-items for individual items:

▶ Example

▶ Try it Yourself

Properties in this section: flex-grow flex-shrink flex-basis flex order align-self align-items

❓ FAQ

Q What does flex: 1 mean? How does it differ from flex: auto and flex: none?
A flex: 1 is shorthand for flex-grow: 1; flex-shrink: 1; flex-basis: 0% — content width is ignored entirely and remaining space is split proportionally. flex: auto has basis auto, so items take their content size first then share what's left; flex: none doesn't grow or shrink at all. Equal columns use flex: 1, "size to content then split the rest" uses flex: auto.
Q What's the difference between flex-basis and width? Which should I use on items?
A The main-axis size is decided by flex-basis; width is only a fallback — when basis isn't auto, width doesn't participate in the calculation. That's why setting width on items in a horizontal flex container often seems to do nothing. Convention: hand main-axis sizing to flex-basis or the flex shorthand; width only matters on the cross axis.
Q Why won't my items share the remaining space even with flex-grow set?
A First confirm the parent has display: flex, then confirm free space actually exists — when items already fill the container there's nothing for grow to distribute. Also check whether the item's flex value is locking grow to 0, e.g. flex: 0 0 auto. Inspecting the computed flex values in DevTools is the fastest way.
Q How do I stop a flex item from being squashed?
A Set flex-shrink: 0 on it. All items default to shrink 1 and compress proportionally when space runs out, which deforms fixed-size elements like logos and avatars. Typical pattern: flex: 0 0 120px (no grow/shrink, fixed 120px) next to an adaptive item with flex: 1.
Q Long content inside a flex item breaks my layout — how do I fix it?
A A flex item's default minimum width is the min-content of its content, so long words and URLs keep it from shrinking. Fix: add min-width: 0 (or overflow: hidden) so the item can shrink below its content; to truncate text add overflow: hidden; text-overflow: ellipsis; white-space: nowrap. This is one of the most common flexbox pitfalls.
Q Does order change the DOM order? Does it affect accessibility?
A No. order only changes visual placement; DOM order stays the same. Screen readers still follow DOM order and Tab focus does too — when visual order and focus order disagree, keyboard users get lost. Use order to fine-tune where individual items appear, not to rearrange whole blocks.
Q Which wins: align-self or align-items?
A align-self has higher priority — it overrides the parent's align-items for a single item. Typical case: parent sets align-items: center for everyone while one badge sets align-self: flex-start to stick to the top. Items without an align-self (default auto) inherit the container's align-items.
Q All my items have flex: 1 — why aren't they equal width?
A flex: 1 uses basis 0%, which should split evenly, but the default min-width: auto refuses to compress below the content's minimum width — the item with more content gets wider. Adding min-width: 0 to every item restores strict equality. Different padding and borders (box-sizing) can also cause visual inequality.
Q How do I build a fixed-width sidebar with an adaptive content area?
A Sidebar gets flex: 0 0 250px (no grow/shrink, fixed 250px), content gets flex: 1 (takes everything left). If you want the sidebar to compress on narrow screens, change the middle value to 1: flex: 0 1 250px. To move the whole sidebar below on small screens, switch the container to flex-direction: column in a media query.

📖 Summary

📝 Exercises

  1. Create a flex container with 5 items. Use order to show the 3rd item first and the 1st item last.
  2. Use flex-grow to implement "three equal columns," then make the center column twice the width of the sides.
  3. Create a "fixed sidebar + adaptive content" layout: sidebar uses flex: 0 0 250px, content uses flex: 1.
  4. In a container, align the first two items to the top and the third to the bottom using align-self.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏