Module 2 / Layout: flexbox & grid
Module 2 · Core utilities

Layout: flexbox & grid

The two layout engines you'll use in every project — flexbox and grid, each in one line of classes.

0/3 lessons

Flexbox in one line

Learn

Flexbox is your one-dimensional layout engine. Turn it on with `flex`, pick a direction (`flex-row` or `flex-col`), then control spacing along each axis: justify for the main axis and items for the cross axis. Add `gap-*` for consistent spacing between children.

The most common combo: `flex items-center justify-between gap-4` — a horizontal row with vertically centered content, space pushed to the edges, and a 16px gap.

flex

Turns on flexbox (display: flex). The starting point for every flex layout.

flex-row / flex-col

Row = horizontal (default). Col = vertical stack. Add `-reverse` to flip order.

justify-*

Main-axis alignment: start, end, center, between, around, evenly.

items-*

Cross-axis alignment: start, end, center, baseline, stretch.

gap-*

Spacing between children. Uses the spacing scale — gap-4 = 16px.

flex-wrap

Allow items to wrap to the next line instead of squeezing. Pair with wrap-reverse if needed.

Practice
Loading…
Recall0/1
Recall

In a flex container, `justify-between` does what?

Grid made simple

Learn

CSS Grid is for two-dimensional layouts — rows AND columns simultaneously. Tailwind exposes the most-used grid properties: define columns with `grid-cols-*`, make an item span multiple columns with `col-span-*`, and use `gap-*` for consistent gutters.

A responsive card grid is as simple as `grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6`. The same gap scale works across both flex and grid — one mental model for spacing.

grid grid-cols-3 gap-4 → three equal columns, 16px gutters grid grid-cols-12 gap-2 → classic 12-column page grid col-span-2 → this item spans 2 of N columns grid-rows-3 → explicitly set 3 rows
Grid cols go up to 12 by default. For anything custom (like 7 columns), use arbitrary values: grid-cols-[7] or grid-cols-[repeat(7,minmax(0,1fr))].
Practice
Loading…
Recall0/1
Recall

Which utility creates a 4-column grid with 24px gaps?

Display & positioning

Learn

Not everything is flex or grid. Tailwind gives you direct control over the display (`block`, `inline`, `inline-block`, `hidden`) and position (`relative`, `absolute`, `fixed`, `sticky`) properties. These are your precision tools.

The `hidden` utility applies `display: none` — completely removes the element from layout. Compare with `invisible` which hides it visually but preserves its space.

UtilityCSS equivalentWhen to use
blockdisplay: blockFull-width elements like sections
inline-blockdisplay: inline-blockButtons that sit inline with text
hiddendisplay: noneConditionally hide elements entirely
relativeposition: relativeAnchor point for absolute children
absoluteposition: absoluteOverlays, badges, positioned icons
fixedposition: fixedSticky navbars, floating buttons
stickyposition: stickySticky headers inside scroll containers
Practice
Loading…
Recall0/1
Recall

In Tailwind, `hidden` does what?