Course contentsShow
← Web Development
Lesson 624 of 2,98211. Utility-First CSS with TailwindFree lesson

Flexbox Utilities: Container and Item Properties

Build flex layouts with flex, flex-row/col, justify-*, items-*, gap-*, and flex-grow/shrink utilities.

Flexbox Utilities: Container and Item Properties

What you'll learn: How to build flexible layouts using Tailwind's flexbox utilities for both containers and their child items.

Understanding Flexbox in Tailwind

Tailwind provides utility classes that map directly to CSS flexbox properties, letting you create responsive layouts without writing custom CSS. Think of flexbox like arranging books on a shelf—you control both how the shelf behaves (the container) and how each book fits (the items).

Container Properties

Start by making an element a flex container with the flex class. Then control its direction:

  • flex-row – items flow horizontally (default)
  • flex-col – items stack vertically

Control how items are distributed along the main axis with justify-*:

  • justify-start, justify-center, justify-end
  • justify-between – space between items
  • justify-around – space around items

Control cross-axis alignment with items-*:

  • items-start, items-center, items-end
  • items-stretch – items fill the container height

Add spacing between items with gap-* utilities: gap-4, gap-8, etc.

Item Properties

Individual flex items can control their own behavior:

  • flex-grow – item expands to fill available space
  • flex-shrink – item shrinks when space is tight
  • flex-1 – shorthand for grow and shrink equally

These properties give you fine-grained control without leaving your HTML.

Example Pattern

A typical navigation bar might use: <nav class="flex justify-between items-center gap-4"> to space links evenly while keeping them vertically centered with consistent gaps.

Key Takeaway: Tailwind's flexbox utilities let you build complex, responsive layouts by combining container properties (flex, flex-row/col, justify-*, items-*, gap-*) with item properties (flex-grow, flex-shrink, flex-1) directly in your markup.