Skip to content

Grid

Based on CSS Grid, this layout component offers powerful 2D layout capabilities compared to Row/Col Flex layouts.

Basic Usage

Set cols to define columns and gap for spacing.

1
2
3
Basic Usage

Column Span

Use span to set how many columns a GridItem spans.

span=2
span=3
span=1
span=6 (full row)
Column Span

Offset

Use offset to set column offset.

A
B (offset=2)
Offset

Different Gaps

gap accepts an array [rowGap, colGap] for separate row and column gaps.

1
2
3
4
5
6
7
8
Different Gaps

Custom Column Template

When cols is a string, it's used directly as CSS grid-template-columns value.

200px
1fr
200px
Custom Column Template

Suffix Element

Set suffix to pin a GridItem to the end of the row.

Content
Suffix
Suffix Element

Use in Nuxt

Grid fully supports Nuxt 3/4 SSR rendering. The example below demonstrates a product list page using Grid layout with useFetch for async data loading.

Product List

Product 1
$ 99.9
Product 2
$ 199.8
Product 3
$ 299.7
Product 4
$ 399.6
Use in Nuxt

SSR Notes:

  • Grid props and inline styles render consistently during SSR.
  • CSS Grid layout is emitted directly on the server and preserved after hydration.
  • Slot content and positioning props such as span, offset, and suffix remain stable in SSR output.

SSR Safety

Grid component has passed complete SSR tests, ensuring consistent rendering between server and client with no Hydration errors.

API

Props

Grid

PropDescriptionTypeDefault
colsColumns count or CSS templatenumber | string12
gapGapnumber | string | [number | string, number | string]0
colGapColumn gap (overrides gap)number | string0
rowGapRow gap (overrides gap)number | string0
collapsedCollapsedbooleanfalse
collapsedRowsCollapsed visible rowsnumber1
justifyItemsHorizontal alignment'start' | 'end' | 'center' | 'stretch'undefined
alignItemsVertical alignment'start' | 'end' | 'center' | 'stretch'undefined
responsiveResponsive breakpoint mode'self' | 'screen'undefined
themeOverridesComponent-level theme variable overridesComponentThemeVarsundefined

Grid Item

PropDescriptionTypeDefault
spanColumn spannumber1
offsetColumn offsetnumber0
suffixSuffix element (pinned to row end)booleanfalse
themeOverridesComponent-level theme variable overridesComponentThemeVarsundefined

Events

This component does not expose component events.

Slots

Grid

SlotDescriptionParameters
defaultGrid content-

Grid Item

SlotDescriptionParameters
defaultGrid item content-

Expose

This component does not expose public instance methods or properties.

Theme Variables

Variable NameDescriptionDefault
--yh-grid-gapGrid gap0
--yh-grid-col-gapGrid column gapvar(--yh-grid-gap, 0)
--yh-grid-row-gapGrid row gapvar(--yh-grid-gap, 0)
--yh-grid-item-paddingItem padding0

Type Exports

NameDescription
YhGridPropsProps type for YhGrid
YhGridItemPropsProps type for YhGridItem
YhGridSlotsSlots type for YhGrid
YhGridItemSlotsSlots type for YhGridItem
YhGridInstancePublic instance type for YhGrid
YhGridItemInstancePublic instance type for YhGridItem

Released under the MIT License.