Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

CSS Grid Layout | HTML Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. HTML Course

Lesson 20 of 55

·HTML

CSS Grid Layout

11 min

Course progress36%

What you'll learn

Keep these ideas in mind as you work through the lesson.

5 points
  • Defining grid tracks with `grid-template-columns` / `grid-template-rows`
  • Placing items with `grid-column` / `grid-row` and the `span` keyword
  • Fractional (`fr`) and flexible `minmax` units for responsive grids
  • Responsive grid patterns using `auto-fill` and `auto-fit`
  • Alignment properties (`align-items`, `justify-items`) for cell content
  • Grid – Two‑Dimensional Layout

    .grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr); /* three equal columns */
      grid-gap: 1rem;                     /* spacing between tracks */
    }
    
    • grid-template-columns / grid-template-rows define tracks (columns and rows).
    • grid-column / grid-row place items.
    • fr unit distributes free space proportionally.

    Example: Card layout with auto‑fill

    <div class='grid'>
      <div class='card'>…</div>
      <div class='card'>…</div>
      <div class='card'>…</div>
    </div>
    
    .grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
      gap: 1.5rem;
    }
    

    auto-fill creates as many columns as will fit, each at least 200 px wide. Empty tracks collapse automatically.

    Advanced features

    • grid-template-areas – Named layout regions for easier reading.
    • align-items, justify-items – Align content inside each grid cell.
    • subgrid (future) – Allows a child grid to inherit the parent’s column definition.

    Quick checklist for Grid

    1. Grid defined with display:grid? ✅
    2. Tracks defined using fr, minmax, or explicit pixel values? ✅
    3. Gap used for spacing (gap, row-gap, column-gap)? ✅
    4. Items placed with grid-column/grid-row where needed? ✅

    Tip: Pair auto-fill with minmax for truly fluid, responsive grids that adapt to any screen size.

    Make it stickPractice what you've learned1 quiz · 2 practical tests · Optional activities from HTML CourseBrowse activities
    Previous lessonFlexbox LayoutContinue to lesson 21Styling Forms – Layout with Grid & FlexboxBack to HTML Course curriculum