CSS chapters

Chapter 16 of 17

Grid, spacing and responsive reference

Try this in our CSS Compiler →

The idea

Grid lays out rows and columns. Use minmax() for bounded tracks and gap for consistent spacing. Start with a layout that can shrink; long text and fixed-width children can still overflow a flexible parent. Inspect the smallest supported viewport rather than assuming the desktop result scales down.

Worked example

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 600px) { .grid { grid-template-columns: 1fr; } }

What to check

Two equal tracks become one at the breakpoint. minmax(0, 1fr) allows tracks to shrink below their content's intrinsic minimum width.

Practice task

Create four blocks, put a long word in one, and add an appropriate wrapping rule. Check both wide and narrow layouts.

Check your understanding

Explain the result in your own words before changing the example. Change one thing at a time, compare the result with your prediction, and keep the version that demonstrates the concept clearly.

Try it yourself

Output
Ctrl/Cmd+Enter runs · Ctrl/Cmd+S downloads the project · Local auto-save is always on