๐ŸŒ Detecting your locationโ€ฆ
๐Ÿ“ข Advertisement โ€” Configure AdSense in Appearance โ†’ Customize โ†’ AdSense Settings

CSS Grid Complete Guide 2026: Layouts, Patterns and Responsive Design

โฑ๏ธ2 min read  ยท  381 words
CSS Grid Complete Guide 2026: Layouts, Patterns and Responsive Design

CSS Grid is the most powerful layout system in CSS. In 2026, browser support is 99%+ and CSS Grid is used for everything from page-level layouts to complex card grids and dashboards. This guide covers Grid from basics to advanced patterns.

Grid Basics

/* Enable grid */
.container {
  display: grid;

  /* 3 equal columns */
  grid-template-columns: 1fr 1fr 1fr;

  /* Or shorthand */
  grid-template-columns: repeat(3, 1fr);

  /* Rows */
  grid-template-rows: auto 1fr auto;

  /* Gap between cells */
  gap: 1rem;
}

<div class="container">
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
  <div>Item 4</div>
  <div>Item 5</div>
  <div>Item 6</div>
</div>

Grid Template Areas (Semantic Layout)

.page {
  display: grid;
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
  grid-template-columns: 250px 1fr;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  gap: 1rem;
}

.header  { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main    { grid-area: main; }
.footer  { grid-area: footer; }

Spanning Columns and Rows

.featured {
  grid-column: 1 / 3;    /* span 2 columns */
  /* or: */
  grid-column: span 2;
}

.hero {
  grid-row: 1 / 3;       /* span 2 rows */
}

.full-width {
  grid-column: 1 / -1;   /* span all columns */
}

Auto-Fill and Auto-Fit (Responsive Grid)

/* Cards that auto-wrap: minimum 280px, fill available space */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

/* auto-fill: keeps empty column tracks
   auto-fit: collapses empty tracks */
.card-grid-fit {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

Named Grid Lines

.layout {
  display: grid;
  grid-template-columns:
    [full-start] 1rem
    [content-start] 1fr
    [content-end] 1rem
    [full-end];
}

.bleed-full {
  grid-column: full-start / full-end;
}

.content {
  grid-column: content-start / content-end;
}

Grid vs Flexbox: When to Use Which

  • CSS Grid: Two-dimensional layouts (rows AND columns), page structure, dashboards, complex card layouts
  • Flexbox: One-dimensional (row OR column), navigation bars, button groups, centering content
  • Both together: Grid for page layout, Flexbox for items inside grid cells

Responsive Grid Without Media Queries

/* Works at any viewport width โ€” no breakpoints needed */
.responsive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
  gap: 1rem;
}

Conclusion

CSS Grid is one of the most powerful additions to CSS. Use grid-template-areas for semantic page layout, repeat(auto-fill, minmax(...)) for responsive card grids, and named lines for complex editorial layouts. Combined with Flexbox, you can build any layout without a CSS framework.

โœ๏ธ Leave a Comment

Your email address will not be published. Required fields are marked *

๐ŸŒ Read in:๐Ÿ‡ฌ๐Ÿ‡ง English๐Ÿ‡ฉ๐Ÿ‡ช Deutsch๐Ÿ‡ง๐Ÿ‡ท Portuguรชs๐Ÿ‡ธ๐Ÿ‡ฆ ุงู„ุนุฑุจูŠุฉ๐Ÿ‡ฎ๐Ÿ‡ณ เคนเคฟเคจเฅเคฆเฅ€๐Ÿ‡ง๐Ÿ‡ฉ เฆฌเฆพเฆ‚เฆฒเฆพ