Draw the layout, get the code
CSS Grid is powerful, but placing items by line numbers is hard to picture. This builder shows a grid you can click and drag across. Span cells, and the tool writes the grid-column and grid-row values for you. If items overlap, you get a warning.
The fr unit
fr means a fraction of the free space. grid-template-columns: 1fr 2fr gives the second column twice the width of the first. Mix fr with fixed sizes: 240px 1fr makes a sidebar and a flexible main area. It's more readable than percentages, and it accounts for gaps.
Grid or Flexbox
If you're thinking about rows and columns together, use Grid. If you're lining things up along one line, use Flexbox. Grid shines for page structure, dashboards and galleries. Nothing stops you from nesting one in the other.
Items without a placement
Items you don't place flow into the next free cell, in source order. That's auto-placement, and it's fine for galleries. Set explicit placement only for items that need a specific spot.
Named lines let you write grid-column: sidebar-start / main-end instead of numbers. They help on bigger layouts. Subgrid lets a child grid use its parent's tracks, and it's supported in current browsers, though this builder focuses on the main grid.
Accessibility
Grid lets you place items visually in any order. Keep the HTML order logical, since keyboard focus and screen readers follow the source, not the picture. If the visual order and DOM order disagree, people get lost.
Your layouts stay in your browser.
When Grid beats Flexbox
Grid is built for layouts where rows and columns both matter. A magazine page, a dashboard with tiles of different sizes, a photo gallery with a tall item: all natural for Grid. Flexbox handles one direction at a time.
Define columns with fr units to split space, like 1fr 2fr 1fr. Use repeat and minmax for responsive grids that add columns as the screen widens.
Click and drag cells in the builder to place items and copy the code.
Naming areas
Grid template areas read like a sketch of the page. Name them header, sidebar, main and footer, and rearrange them in a media query for phones. It's easier to read than line numbers.