Skip to main content
Login

Sign in to access your account

Grid System - National Design System

A grid lays out its children in columns that adapt to the screen width

Overview

A grid is one class, nds-grid, on the element that holds the items. CSS custom properties in its style set the layout: a column count, a minimum column width, or a track template. Each can take another value on tablets and phones. Every child fills its cell. Only a divided grid runs a script.

Pick another component when:

  • the items sit in one row or one column at their own widths: Flex
  • the page needs regions, such as a title, a body and a side column: Section

Markup

Preview
1
2
3
4
<!-- One equal column per child, all in one row --> <div class="nds-grid"> <div class="nds-card nds-stroke">1</div> <div class="nds-card nds-stroke">2</div> <div class="nds-card nds-stroke">3</div> <div class="nds-card nds-stroke">4</div> </div>

Built-in Features

  • Auto-fit Columns

    With no settings, the children share the row in equal columns.

  • Minimum Width Wrapping

    Set --min-width, and the items wrap once they cannot fit at that width. No media queries needed.

  • Responsive Column Tokens

    Set a column count for each screen size with --max-col, --mid-col and --min-col. A value you leave out falls back to the next larger one.

  • Custom Track Layouts

    Set columns of different widths for each screen size with --max-track, --mid-track and --min-track.

  • Adaptive Gap Scaling

    The default gap shrinks from 20px to 16px below 960px. A gap you set stays the same, and never goes under 8px there.

  • Alignment Tokens

    --justify and --align set how the children sit in their cells. nds-center centers them.

  • Container-Aware (opt-in)

    Add nds-cq to any element around a grid, and the grid follows that element's width, such as a sidebar. It is opt-in, because that element no longer takes its width from its content.

Best Practices

  • For a set of like items, such as cards, use a List: a ul that is a grid and sets the items’ look. Keep a plain grid for page regions, fields and link cards.
  • Use Equal columns for a short set of items that must stay in one row. Use a minimum width when the number of columns should follow the space.
  • With a fixed column count, set values for smaller screens too, such as --mid-col: 2 and --min-col: 1. Without them, a phone gets the desktop column count.
  • Use tracks for columns of different widths, such as main content and a side column. Add --mid-track: 1fr to stack them below 960px.
  • Use either column values or track values on one grid, not both. A track value overrides the column count at the same screen size.
  • Do not use a grid for one column of content. Normal page flow already does that.
  • Do not build the page structure from grids inside grids. Use Section for page regions.
  • Add nds-cq only when a grid sits in a narrow column and must follow that column’s width. Not on an element that takes its width from its content, such as an inline-block or a flex item with no width: it shrinks to nothing.
  • Set --gap with a spacing token, such as var(--spacing-md).
  • Use nds-divided for items with no border or background of their own. Cards already have an edge.

API

Classes

Class Element Effect
nds-grid The element that holds the items Makes it a full-width grid
nds-center .nds-grid Centers each child in its column and centers the text inside. Sets --justify: center
nds-divided .nds-grid Draws a line in the middle of each row gap, in the divider color. The last row draws none. The default gap doubles
nds-cq Any element around a grid Makes the grid inside follow this element’s width. See the next table
nds-last-row Each item in the last row of a divided grid Set by the script, which moves it when the row changes. The grid’s row lines read it: the last row draws none. Do not set it yourself

CSS Custom Properties

Set these in the style of .nds-grid.

Property Default Controls
--max-col auto-fit Number of equal columns at 960px and up
--mid-col --max-col Number of columns from 600px to 959px
--min-col --mid-col Number of columns below 600px
--max-track none A grid-template-columns value at 960px and up. It overrides the column count
--mid-track --max-track Track value from 600px to 959px
--min-track --mid-track Track value below 600px
--min-width 0 Smallest column width. With no column count, as many columns as fit, and the rest wrap
--gap var(--spacing-2xl) Space between rows and columns. The default is 16px below 960px. On a divided grid, the default doubles
--row-gap, --col-gap --gap Space between rows, or between columns, alone
--justify stretch justify-items: how a child sits across its column
--align start align-items. Children fill the row height, so it changes only a child with its own height

Screen and Container Widths

Values Screen width Inside .nds-cq
--max-col, --max-track 960px and up wider than 768px
--mid-col, --mid-track 600px to 959px 768px or less
--min-col, --min-track below 600px 480px or less

The container widths apply only inside an nds-cq element. The screen widths still apply there too.

JavaScript

Method Effect
NDS.Grid.init() Watches every divided grid on the page. It runs at page load
NDS.Grid.refresh(el) Marks the last row of el, or of every divided grid inside it, now, and watches a grid added after load
NDS.Grid.destroy(el) Stops watching el, or the divided grids inside it, and removes their nds-last-row marks

The script runs only for a grid with nds-divided, and for a Drawer list in columns under a divided Drawer. It measures the rows, so a grid whose column count changes with its width marks itself again when it resizes. For a view that may hold other components, call NDS.init.mount(el) after it mounts and NDS.init.destroy(el) before it goes, rather than the grid calls. The full API is in the banner of _js/nds-grid.js.

// A divided grid built after load: mark its last row now container.appendChild(grid); NDS.Grid.refresh(grid);
Last Modified Date: 08/11/2026 - 04:21 PM
Was this page useful?
60% of users said Yes from 2843 Feedbacks