HTML & CSS Masterclass Tutorial

Comprehensive guide to modern HTML and CSS development.

CSS Grid

CSS Grid Layout

While Flexbox is for one-dimensional layouts (a row OR a column), CSS Grid is for two-dimensional layouts (Rows AND Columns simultaneously).

Key Concepts

  • display: grid; applied to the parent container.
  • grid-template-columns and grid-template-rows define the grid tracks. You can use pixels, percentages, or the powerful fr (fractional) unit.
  • gap adds spacing between the grid items.

Example: grid-template-columns: 1fr 2fr 1fr; creates three columns where the middle one is twice as wide as the outer ones.

Try It Yourself

Edit the code below and click Run to see the result live.

Source Code
Result
Topics