Skip to content

Grid ​

A 24-column grid layout system. Pair it with oas-grid-item to divide column widths, with support for gap, offset and a custom total column count; setting columns switches to an auto equal-width layout (simple-grid).

Basic grid ​

Three equal columns

span 8
span 8
span 8

Unequal columns ​

Unequal columns

span 6
span 12
span 6

Offset ​

Offset

span 12
span 8 offset 4
span 4 offset 6

Custom total columns ​

Custom cols

span 6 / 12 cols
span 6 / 12 cols
span 4
span 8

Auto columns (simple-grid) ​

Setting columns divides the width equally with repeat(n, 1fr); child span is ignored (span only takes effect without columns), and it coexists with the 24-column grid without conflict.

columns auto equal-width

1
2
3
4
5
6

columns ignores span

span 8 ignored
span 24 ignored
span 8 ignored
span 24 ignored

Responsive column counts ​

columns accepts breakpoint shorthand: a base value plus space-separated breakpoint:value pairs (same protocol as span: sm=640 / md=768 / lg=1024 / xl=1280, mobile-first). Children stay auto equal-width and ignore span. Resize the window to see the count adapt.

columns breakpoints: 1 → sm:2 → md:3

1
2
3
4
5
6

<640px 1 column per row; ≥640px 2; ≥768px 3.

Min child width (auto-fit grid) ​

min-child-width sets the minimum width of each child (e.g. 180px; bare numbers are treated as px). The grid derives its column count automatically from the available width via auto-fit + minmax — children reflow without any breakpoints. When combined with columns, columns wins (min-child-width is ignored); in this mode child span / offset are also disabled (auto placement).

min-child-width auto-fit grid

1
2
3
4
5
6
7
8

Narrow or widen the container to see the column count change automatically — no breakpoints needed.

Large gap ​

Gap

span 8
span 8
span 8

Separated row/column gutters ​

gap supports a two-value syntax: space- or comma-separated row column (8 16 / 8,16) controls row-gap and column-gap independently; a single value still applies to both axes (zero regression). The row-gap / column-gap attributes can be set individually and override the matching axis of gap.

gap two values: row 8 / column 24

row 8 / col 24
row 8 / col 24
row 8 / col 24
row 8 / col 24
row 8 / col 24
row 8 / col 24

gap comma pair + row-gap/column-gap attributes

column-gap="32"
column-gap="32"
gap="4,32"
gap="4,32"
gap="4,32"
gap 8 + row-gap 24
gap 8 + row-gap 24
gap 8 + row-gap 24
row 24 / col 8
row 24 / col 8
row 24 / col 8

Responsive breakpoints ​

span / offset accept breakpoint shorthand: a base value plus space-separated breakpoint:value pairs (breakpoints sm=640 / md=768 / lg=1024 / xl=1280, mobile-first). Resize the window to see the columns adapt.

span breakpoints: 24 → md:12 → lg:8

span 24 / md 12 / lg 8
span 24 / md 12 / lg 8
span 24 / md 12 / lg 8

<640px each item fills a row; ≥768px two per row; ≥1024px three equal columns.

offset breakpoints: 0 → md:4

span 24 / md 16
span 4 offset 4 (md+)

From ≥768px the right item starts at column 5 and spans 4 columns (offset 4 / span 4).

Auto-width columns ​

span="auto" sizes an item to its natural content width (no column span); it can be combined with offset.

span=auto columns

auto width
auto offset 4
span 8
span 4

Container alignment ​

justify controls the inline axis (justify-items), align the block axis (align-items); valid values are applied directly, invalid values fall back to stretch with a dev warning.

justify (inline axis)

justify="start"(default behavior)
span 8
span 8
justify="center"
span 8
span 8
justify="end"
span 8
span 8

align (block axis, fixed height)

align="start"
short
h 40
h 64
align="center"
short
h 40
h 64
align="baseline"
short
h 40
h 64

Reordering (order / push / pull) ​

  • order expresses reordering: the DOM/source order (and screen-reader semantics) stays unchanged, only the visual order changes.
  • push / pull shift the start line right / left by N columns on top of offset (net shift = push − pull combined with offset); a net shift ≤ 0 falls back to auto-placement.

Last column first (order)

source col 1 (order 0)
source col 2 (order 0)
source col 3 (order -1 → first)

push/pull shift

span 6
span 6 push 6 (6 cols right)
span 6 offset 6
span 6 offset 6 pull 6 (pulled back)

Custom order

A (order 3)
B (order 1)
C (order 2)
D (order 0)

Visual order: D (0) → B (1) → C (2) → A (3).

Collapsed rows (collapsed-rows) ​

collapsed-rows sets how many rows stay visible in the collapsed state (row model accumulates child span/offset): children beyond the limit are hidden and an Expand tail cell appears (spanning the remaining columns of its row); clicking expands, and the tail turns into Collapse to fold back. The collapsed state writes back to the controlled collapsed attribute and emits oas-collapse. Not enabled under columns / min-child-width auto layout (the row model relies on span/offset semantics); the row model counts in 24 columns, so with a non-24 cols the row estimate deviates from the real layout (push/pull are not counted either) — avoid that combination. When the total row count does not exceed collapsed-rows, collapsed is never written (nothing to fold: everything stays visible with no tail cell).

collapsed-rows=1 query filters

Filter 1
Filter 2
Filter 3
Filter 4 (row 2)
Filter 5 (row 2)
Filter 6 (row 2)

Only the first row shows by default (filters 1–3); click the Expand tail to reveal all, Collapse to fold back.

Child flex passthrough ​

The oas-grid-item flex attribute writes the CSS flex shorthand inline (not consumed by grid layout per CSS spec, zero interference) — a passthrough for host scenarios that place the item into flex containers.

API ​

oas-grid ​

Attributes ​

AttributeDescriptionTypeDefault
alignBlock-axis alignment (align-items): start / center / end / stretch / baseline; invalid values fall back to stretch with a dev warning (deduped)string—
collapsedControlled collapsed attr for collapsed-rows (bootstrapped collapsed by default; host/tail can toggle)——
collapsed-rowsRows visible when collapsed; overflow hidden with an expand/collapse tail cell (writes back collapsed, emits oas-collapse)string1
colsTotal column countstring24
column-gapIndependent column gap (same rules)string—
columnsAuto equal column count (simple-grid; child span ignored when set): supports breakpoint shorthand (e.g. 3 md:2 sm:1; breakpoints sm=640/md=768/lg=1024/xl=1280); takes precedence over min-child-widthstring—
gapGap; a single value applies to both axes, two space-separated values set row column (e.g. 8 16 = row 8, column 16); three or more values are invalid and silently fall back to 0string0
justifyInline-axis alignment (justify-items): start / center / end / stretch; invalid values fall back to stretch with a dev warning (deduped)string—
min-child-widthMinimum child width (e.g. 180px; bare numbers read as px): auto-fit + minmax derives the column count from container width (breakpoint-free fluid reflow); columns wins when both are set, and child span/offset are inert in this modestring—
row-gapIndependent row gap overriding the matching axis of gap (numbers as px)string—

Events ​

EventDescription
oas-collapseEmitted on collapsed-rows tail toggle, detail: { collapsed }

Slots ​

NameDescription
defaultGrid children (oas-grid-item)

CSS Variables ​

CSS VariableDefault
--oas-grid-columnsrepeat(${base ?? 1}, 1fr)

oas-grid-item ​

Attributes ​

AttributeDescriptionTypeDefault
flexWrites the CSS flex shorthand inline (unused by grid; passthrough for flex contexts)string—
offsetNumber of columns offset on the left; supports breakpoint shorthand (e.g. 0 lg:4: base value + space-separated breakpoint:value, breakpoints sm=640 / md=768 / lg=1024 / xl=1280)string0
orderOrdering weight (number, default 0); higher values appear later, for reordering columns (equivalent to offset-based push/pull scenarios)string0
pullShifts the start line left by N columns (same rules)string0
pushShifts the start line right by N columns (net = push−pull on top of offset)string0
spanNumber of columns spanned; supports auto (natural content width) and breakpoint shorthand (e.g. 24 md:12: base value + space-separated breakpoint:value, breakpoints sm=640 / md=768 / lg=1024 / xl=1280)string24

Slots ​

NameDescription
defaultGrid cell content

CSS Variables ​

CSS VariableDefault
--oas-grid-item-column${baseColumn}

oas-grid renders as CSS Grid where each child occupies a share of the 24 columns; oas-grid-item declares its footprint with span. Setting columns divides equally and ignores span, so plain elements can be placed directly.

Released under the MIT OR Apache-2.0 License.