CSS Grid Complete Guide: Columns, Rows, fr Units, Areas, auto-fit, minmax and Page Layout Examples

Web Designing 60 min min read Updated: Nov 17, 2026 Intermediate
CSS Grid Complete Guide: Columns, Rows, fr Units, Areas, auto-fit, minmax and Page Layout Examples
Intermediate Topic 2 of 3

What Is CSS Grid?

CSS Grid arranges items in rows and columns at the same time. It is ideal for whole page layouts, galleries and dashboards.

css .grid { display: grid; grid-template-columns: 1fr 2fr 1fr; /* three columns */ gap: 1rem; }

The fr Unit

fr means a fraction of the free space. 1fr 2fr 1fr makes the middle column twice as wide as the others. You can mix units: 250px 1fr is a fixed sidebar plus a flexible main area.

repeat, minmax and auto-fit

css .gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1rem; }

Meaning: make as many columns as fit, each at least 14rem and sharing leftover space equally. The gallery goes from 1 column on phones to 4 or more on large screens, without any media query.

Placing and Spanning Items

css .feature { grid-column: span 2; } /* take 2 columns */ .tall { grid-row: span 2; } /* take 2 rows */ .pinned { grid-column: 1 / 3; grid-row: 1; } /* from line 1 to line 3 */

Named Areas: Page Layout

html <div class="page"> <header>Header</header> <nav>Menu</nav> <main>Main content</main> <aside>Side info</aside> <footer>Footer</footer> </div>
css .page { display: grid; grid-template-columns: 220px 1fr 220px; grid-template-areas: "header header header" "nav main aside" "footer footer footer"; gap: 1rem; min-height: 100vh; } .page > header { grid-area: header; } .page > nav { grid-area: nav; } .page > main { grid-area: main; } .page > aside { grid-area: aside; } .page > footer { grid-area: footer; } @media (max-width: 700px) { .page { grid-template-columns: 1fr; grid-template-areas: "header" "nav" "main" "aside" "footer"; } }

The layout is drawn right in the CSS. On small screens we redraw it as a single column.

Alignment

PropertyEffect
justify-items, align-itemsAlign items inside their cells
justify-content, align-contentAlign the whole grid inside the container
place-items: centerShorthand to center items in cells
grid-auto-rows: minmax(8rem, auto)Size for rows you did not define
Subgrid subgrid lets nested items line up with the parent grid. It is now supported by the major browsers, but check a support table such as MDN or Can I Use before relying on it for older devices.

Practice

  1. Build the page layout with header, nav, main, aside and footer
  2. Create a photo gallery with auto-fit and minmax
  3. Make one featured item span two columns

Conclusion

Grid controls rows and columns together. Use fr units, auto-fit with minmax for responsive galleries and named areas for page layouts.

Quick Summary: Idea; fr; auto-fit; spanning; areas; alignment; subgrid.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators