---
title: "Grid"
description: "Intrinsic card grids, explicit tracks and aligned subgrids. Responsive to available space without a breakpoint utility generator."
slug: "grid"
---

import { DocPage, PageHeader, SkillPanel, Example, ExampleLabel, ExampleHint, ExampleCode, SourceFiles, SourceNote, StatesSection, CodeBlock, Demo, DemoCode, ChangelogEntries, ArchBody, StatsClaim, StatsCards, PageOverlay, DocText, DocLink, H2, SkillField, SkillText, SkillRow, SkillGrid, Variant, ApiPill, Dim, CodeCard, TableCard } from "../../lib/components/index";

<DocPage meta={meta}>

<PageHeader slug="grid" title="Grid" introStyle="max-width:38rem;">
  Intrinsic card grids, explicit tracks and aligned subgrids. Responsive to available space without a breakpoint utility generator. Every code block is the live demo - the shown source is the executed source, and each card carries a device toolbar that really resizes the sandbox.
</PageHeader>

<h2 id="intrinsic" class="h2-display">Intrinsic columns without breakpoints</h2>

<DocText><code>grid</code> only enables Grid. Add <code>grid-cols-auto</code> for auto-fit columns with a preferred minimum; <code>--layout-min</code> defaults to 16rem. Empty tracks collapse, and populated tracks share spare space. This is the card-wall pattern: team directories, feature matrices and gallery grids that reflow as the page widens - no media queries. Resize the demo with the toolbar and watch tracks appear and collapse.</DocText>

```html example schema="none"
<div class="grid grid-cols-auto gap-4" style="--layout-min: 12rem" data-demo="grid">
  <div class="demo-tile p-4" data-variant="muted">Research</div>
  <div class="demo-tile p-4" data-variant="muted">Design</div>
  <div class="demo-tile p-4" data-variant="muted">Engineering</div>
</div>
```


```css
grid-template-columns:
  repeat(auto-fit, minmax(min(100%, var(--layout-min)), 1fr));
```


<DocText>The inner minimum prevents the preferred track width itself from exceeding a narrow container. It does not wrap long identifiers, shrink arbitrary media or eliminate intrinsic child overflow. Set those policies on the content.</DocText>

<div class="sep" />

<h2 id="explicit" class="h2-display">Explicit tracks and spans</h2>

<DocText>Fixed track counts with explicit spans compose the classic dashboard: a full-width header, a filter rail and a results region that takes the remaining columns.</DocText>

<div class="overflow-x-auto mb-6">
  <table class="table" data-variant="simple">
    <thead>
      <tr>
        <th scope="col">Concern</th>
        <th scope="col">Classes</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Columns</td>
        <td><code>grid-cols-1</code> through <code>grid-cols-12</code>; equal <code>minmax(0, 1fr)</code> tracks.</td>
      </tr>
      <tr>
        <td>Rows</td>
        <td><code>grid-rows-1</code> through <code>grid-rows-6</code>.</td>
      </tr>
      <tr>
        <td>Spans</td>
        <td><code>col-span-1...12</code>, <code>row-span-1...6</code>, <code>col-span-full</code>, <code>row-span-full</code>.</td>
      </tr>
      <tr>
        <td>Other tracks</td>
        <td><code>grid-cols-none, grid-rows-none, auto-cols-auto, auto-rows-auto</code>.</td>
      </tr>
      <tr>
        <td>Subgrid</td>
        <td><code>grid-cols-subgrid, grid-rows-subgrid</code>.</td>
      </tr>
      <tr>
        <td>Alignment</td>
        <td><code>items-\*</code>, <code>justify-items-start/end/center/stretch</code>, <code>justify-self-auto/start/end/center/stretch</code>, <code>place-items-start/end/center/stretch/baseline</code>, <code>place-self-auto/start/end/center/stretch</code>.</td>
      </tr>
    </tbody>
  </table>
</div>

```html example schema="none"
<div class="grid grid-cols-3 gap-4">
  <header class="col-span-full demo-tile p-2">Dashboard - col-span-full</header>
  <aside class="demo-tile p-2" data-variant="muted">Filters</aside>
  <section class="col-span-2 demo-tile p-2" data-variant="accent">Results - col-span-2</section>
</div>
```


<DocText>A span larger than the available explicit tracks can create implicit columns. Keep spans compatible with every responsive track configuration; do not use a fixed span in a one-column auto-fit layout without an intentional override.</DocText>

<div class="sep" />

<h2 id="alignment" class="h2-display">Alignment inside tracks</h2>

<DocText>Items stretch to fill their track area by default. <code>place-items-\*</code> sets the default for every cell (<code>items-\*</code> and <code>justify-items-\*</code> address the block and inline axes separately); <code>justify-self-\*</code> and <code>place-self-\*</code> override one item - centering an icon in its cell, or pinning an action to the end of a row.</DocText>

```html example schema="none"
<div class="stack gap-4">
  <div>
    <p class="demo-label">place-items-center on the grid</p>
    <div class="grid grid-cols-3 gap-2 place-items-center demo-outline" style="grid-auto-rows: 4rem">
      <div class="demo-tile size-8"></div>
      <div class="demo-tile size-8"></div>
      <div class="demo-tile size-8"></div>
    </div>
  </div>
  <div>
    <p class="demo-label">justify-self-\* / place-self-\* per item</p>
    <div class="grid grid-cols-3 gap-2 demo-outline" style="grid-auto-rows: 4rem">
      <div class="demo-tile size-8 justify-self-start" data-variant="accent"></div>
      <div class="demo-tile size-8 place-self-center" data-variant="accent"></div>
      <div class="demo-tile size-8 justify-self-end" data-variant="accent"></div>
    </div>
  </div>
</div>
```


<div class="sep" />

<h2 id="subgrid" class="h2-display">Share track alignment with subgrid</h2>

<DocText>Cards in a row usually carry different amounts of body copy, but their footers should still line up - pricing tiers, feature cards, article teasers. Subgrid lets each card adopt the parent's row tracks, so one row height is negotiated across all cards.</DocText>

```html example schema="none"
<div class="grid grid-cols-2 gap-4" data-demo="subgrid">
  <div
    class="grid row-span-3 grid-rows-subgrid"
    style="border: 1px solid var(--border); border-radius: var(--radius-md)"
  >
    <h3 style="margin: 0.75rem; font-size: 1rem">Card A</h3>
    <p class="text-sm text-muted-foreground" style="margin: 0 0.75rem"
      >Short body - its footer still aligns with Card B because the row tracks are shared.</p
    >
    <button class="btn justify-self-start" type="button" data-variant="outline" data-size="sm" style="margin: 0.75rem"
      >Open</button
    >
  </div>
  <div
    class="grid row-span-3 grid-rows-subgrid"
    style="border: 1px solid var(--border); border-radius: var(--radius-md)"
  >
    <h3 style="margin: 0.75rem; font-size: 1rem">Card B</h3>
    <p class="text-sm text-muted-foreground" style="margin: 0 0.75rem"
      >A much longer body that would push a naive footer down. Subgrid keeps both footers on one line.</p
    >
    <button class="btn justify-self-start" type="button" data-variant="outline" data-size="sm" style="margin: 0.75rem"
      >Open</button
    >
  </div>
</div>
```


<DocText>Each card spans three parent rows and adopts those rows as its subgrid. Subgrid is a structure contract, not a universal card rule. Without support, the cards retain ordinary independent grids; shared row alignment is the enhancement. CSS Grid is layout, not an ARIA grid widget.</DocText>

<div class="sep" />

<h2 id="real-world" class="h2-display">A realistic card wall</h2>

<DocText>The same auto-fit track list drives a typical content listing - article teasers, product cards, team directories. Each card is ordinary component markup (card, title, description, badge); the grid owns the tracks and nothing here measures the viewport. Resize with the toolbar: the wall deals out one, two, three or more columns as the frame widens.</DocText>

```html example schema="none"
<div class="grid grid-cols-auto gap-4" style="--layout-min: 10rem">
  <article class="card">
    <div class="card-header">
      <h3 class="card-title">Getting started</h3>
      <p class="card-description">Install and render your first component in minutes.</p>
    </div>
    <div class="card-footer">
      <span class="badge" data-variant="secondary">Guide</span>
    </div>
  </article>
  <article class="card">
    <div class="card-header">
      <h3 class="card-title">Design tokens</h3>
      <p class="card-description">One source of truth for color, radius and shadow.</p>
    </div>
    <div class="card-footer">
      <span class="badge" data-variant="secondary">Reference</span>
    </div>
  </article>
  <article class="card">
    <div class="card-header">
      <h3 class="card-title">Container queries</h3>
      <p class="card-description">Components that react to the space they get.</p>
    </div>
    <div class="card-footer">
      <span class="badge" data-variant="secondary">Pattern</span>
    </div>
  </article>
  <article class="card">
    <div class="card-header">
      <h3 class="card-title">Theming</h3>
      <p class="card-description">Drop-in palettes from any tweakcn export.</p>
    </div>
    <div class="card-footer">
      <span class="badge" data-variant="secondary">Guide</span>
    </div>
  </article>
  <article class="card">
    <div class="card-header">
      <h3 class="card-title">Grid layouts</h3>
      <p class="card-description">Intrinsic tracks without breakpoint utilities.</p>
    </div>
    <div class="card-footer">
      <span class="badge" data-variant="secondary">Pattern</span>
    </div>
  </article>
  <article class="card">
    <div class="card-header">
      <h3 class="card-title">Dark mode</h3>
      <p class="card-description">One theme, two palettes, zero flash.</p>
    </div>
    <div class="card-footer">
      <span class="badge" data-variant="secondary">Reference</span>
    </div>
  </article>
</div>
```


<div class="sep" />

<h2 id="advanced" class="h2-display">Real world: the holy-grail layout</h2>

<DocText>When the skeleton is stable - header, nav, main, aside, footer - a fixed 12-track grid with explicit spans states the structure directly: <code>grid grid-cols-12 gap-4</code>, <code>col-span-full</code> for the chrome, <code>col-span-3</code> / <code>col-span-6</code> / <code>col-span-3</code> for the body. The middle spans sum to 12, so every item lands on a declared track and no implicit columns are created. Resize with the toolbar and watch the <code>minmax(0, 1fr)</code> tracks compress while the proportions hold - auto-fit would have reflowed the skeleton; spans keep it.</DocText>

```html example schema="none"
<div class="grid grid-cols-12 gap-4">
  <header class="col-span-full demo-tile h-12" data-variant="secondary">col-span-full - header</header>
  <nav class="col-span-3 demo-tile h-32" data-variant="muted">col-span-3 - nav</nav>
  <main class="col-span-6 demo-tile h-32" data-variant="accent">col-span-6 - main</main>
  <aside class="col-span-3 demo-tile h-32" data-variant="muted">col-span-3 - aside</aside>
  <footer class="col-span-full demo-tile h-10" data-variant="secondary">col-span-full - footer</footer>
</div>
```


<div class="sep" />

<h2 id="references" class="h2-display">Platform references</h2>

<DocText><a class="link" href="https://www.w3.org/TR/css-grid-2/" target="_blank" rel="noopener">CSS Grid and subgrid</a> · <a class="link" href="https://www.w3.org/TR/css-contain-3/" target="_blank" rel="noopener">CSS container queries</a></DocText>

</DocPage>
