Skip to content

Grid

Responsive CSS grid that adapts its column count to its own width via container queries.

Import

import { Grid } from "@hyzer-labs/ui"

Demo

Column counts are container queries against the Grid's own width. A Grid in a sidebar and one in a hero each pick their own layout, whatever the window is doing. Each key names the band ending at its width token: sm below 640px, md to 968px, lg to 1200px, xl beyond. Use the slider to change the grid's width.

md band → 2 columns

Cell 1
Cell 2
Cell 3
Cell 4
Cell 5
Cell 6
<Grid columns={{ sm: 1, md: 2, lg: 3 }}>
	<Card>…</Card>
	<!-- … -->
</Grid>

Props

NameTypeDefaultNote
columnsnumber | { sm?: number; md?: number; lg?: number; xl?: number } | { min: string }{ sm: 1, md: 2, lg: 3 }Band keys name the band ending at their width token: sm below 640px, md to 968px, lg to 1200px, xl beyond — fixed system constants, because queries cannot read tokens. { min } is the fluid, fully var-driven mode.
gap'none' | 'sm' | 'md' | 'lg' | 'near' | 'away''md'near/away are the density distances — they tighten inside data-density-shift regions.
align'start' | 'center' | 'end' | 'stretch' | 'baseline''stretch'Shared LayoutAlign scale (Stack/Cluster/Grid).
padding'none' | 'sm' | 'md' | 'lg' | 'near' | 'away''none'Both axes, on the grid root — the column breakpoints measure the padded-down width. Shared LayoutPadding scale.
paddingInline'none' | 'sm' | 'md' | 'lg' | 'near' | 'away'Per-axis override — wins over padding on the inline axis. Same LayoutPadding scale.
paddingBlock'none' | 'sm' | 'md' | 'lg' | 'near' | 'away'Per-axis override — wins over padding on the block axis. Same LayoutPadding scale.
asstring'div'
classstringMerged after the hz-grid class.
childrenSnippet

Theme hooks

What this component promises your CSS. The reference theme styles exactly these — from @layer hz-theme, so your unlayered rules win. See Styling Components for the how.

Root class: .hz-grid

Data attributes

HookValuesStyles
data-gap'none' | 'sm' | 'md' | 'lg' | 'near' | 'away'Track gap. Default md.
data-align'start' | 'center' | 'end' | 'stretch' | 'baseline'align-items. Default stretch.
data-padding'none' | 'sm' | 'md' | 'lg' | 'near' | 'away'Padding, applied to the root so container queries measure the space the tracks actually get. Default none.
data-fluidpresent in fluid modeRead-only: present when columns is {min}. Target it to style fluid grids apart from banded ones — the mode is set by the prop, not the attribute.

Part classes

HookValuesStyles
.hz-grid-layoutchild elementThe real grid. The root is a size container only (an element cannot container-query itself), so track and gap rules live here.

Accessibility

Grid is a layout primitive with no ARIA semantics. Reading and focus order follow DOM order.