What are flex items?

In flexbox, items are the direct children of a flex container. While the container controls the overall layout (direction, wrapping, alignment), flex items control their own sizing and growth.

So far you've learned to control the container with properties like flex-direction, justify-content, and align-items. Now it's time to focus on the items themselves.

Key point:
Flex items are powerful. They can grow to fill available space, shrink to fit tight containers, and override the container's alignment rules.

There are 6 main flex item properties you need to know:

  • flex-grow — How much the item grows when there's extra space
  • flex-shrink — How much the item shrinks when space is tight
  • flex-basis — The starting size before growing or shrinking
  • flex — Shorthand for grow, shrink, and basis
  • align-self — Override the container's alignment for this item
  • order — Change the visual order without touching HTML

flex-grow: sharing available space

flex-grow controls how much an item expands when there's extra space in the container. The default is 0 (don't grow).

flex-grow.css Items with different growth rates

The math is simple: available space is divided among all items by their flex-grow ratio. If one item has flex-grow: 2 and another has flex-grow: 1, the first takes twice as much extra space.

✏️ Try It Yourself — flex-grow Demo
Preview

Practical use case: In a navigation bar, you want the logo fixed-width, search bar to grow and fill space, and user menu fixed-width. Use flex-grow: 0 on logo and menu, flex-grow: 1 on search.

flex-basis and flex-shrink

flex-basis is the starting size of an item before any growing or shrinking happens. It's like width, but smarter — it's the "opinion" of the item before the container makes decisions.

flex-properties.css flex-basis and flex-shrink explained

flex-shrink (default: 1) controls how much an item shrinks when the container is too small. Set it to 0 to prevent shrinking.

Important:
Use flex-basis: 0 with flex-grow: 1 to make items grow equally from zero, ignoring their content size. This is the secret to even-width columns.

The flex shorthand

Instead of writing flex-grow, flex-shrink, and flex-basis separately, use the flex shorthand:

flex-shorthand.css Common flex patterns

Most common patterns:

  • flex: 1 — flexible item that grows and shrinks equally
  • flex: 0 0 300px — fixed-width item (doesn't grow or shrink)
  • flex: auto — item that grows but maintains minimum content size

align-self and order

align-self lets a single item override the container's alignment (the align-items property). Useful when you want one item to behave differently.

align-self-order.css Item-level alignment and ordering

order changes the visual order of items without touching the HTML. This is powerful for responsive design — you can change layout order on mobile without duplicating content.

✏️ Try It Yourself — Card Layout with Flex Properties
Preview
Build a Holy Grail Header

Task: Create a header layout with three sections using flex properties:

  • Logo (fixed 200px width, left side)
  • Search bar (grows to fill available space)
  • User menu (fixed 150px width, right side)

Requirements:

  • All items vertically centered in the header
  • Logo: flex: 0 0 200px
  • Search: flex: 1
  • Menu: flex: 0 0 150px
  • Use a border or background to make each section visible

Hint: Use display: flex on the header. Set gap for spacing. Use align-items: center for vertical alignment. Apply the flex values to each child element.

Key concepts to remember

  • flex-grow controls how items expand. Items share available space proportionally based on their flex-grow values.
  • flex-basis is the starting size before any growing/shrinking. flex-basis: 0 makes items grow from zero.
  • flex-shrink controls shrinking. Set to 0 to prevent an item from shrinking (useful for sidebars).
  • flex shorthand combines grow, shrink, and basis: flex: grow shrink basis.
  • align-self overrides the container's alignment for a single item.
  • order changes visual order without changing HTML — perfect for responsive design.
Power tip:
flex: 1 is your friend. It makes items flexible and responsive without overthinking. For fixed sizes, use flex: 0 0 SIZE.

Test your knowledge

Question 1 of 5
What does flex-grow: 2 mean?
Question 2 of 5
What is flex: 1 shorthand for?
Question 3 of 5
How do you prevent an item from shrinking when the container is too small?
Question 4 of 5
What does align-self do?
Question 5 of 5
Does the order property change the actual HTML order?
0
/5
Great work! You understand flexbox items.
Africa & India's Best AI Academy
🤖 AI-first 🎓 Placement Assistance

You just mastered flexbox items.
Ready for the next challenge?

Join the Best AI Programs — three 5-month courses, fully online, with placement assistance. Week 1 is free.

Explore our AI-era courses →