Grid
A powerful CSS Grid layout component that makes it easy to create complex grid layouts with minimal code.
Import
import { Grid } from '@beauginbey/vanilla-components';
Basic Usage
The Grid
component provides a simple API for CSS Grid layouts.
Responsive Columns
Create responsive grid layouts with different column counts at different breakpoints.
Custom Grid Templates
For more complex layouts, use custom grid template strings.
Auto-Fit and Auto-Fill
Create responsive grids that automatically adjust to content.
Grid Flow
Control how auto-placed items flow in the grid.
Alignment
Control alignment of grid items.
Gap Control
Fine-tune spacing with separate row and column gaps.
Common Patterns
Image Gallery
Dashboard Layout
Props
Grid
accepts all Box
props plus the following grid-specific props:
Prop | Type | Default | Description |
---|---|---|---|
columns | string | - | Number of columns or custom grid template |
rows | string | - | Number of rows or custom grid template |
flow | 'row' | 'column' | 'dense' | 'row dense' | 'column dense' | 'row' | Grid auto flow direction |
align | 'start' | 'center' | 'end' | 'stretch' | - | Align grid items |
justify | 'start' | 'center' | 'end' | 'stretch' | - | Justify grid items |
gap | number | - | Gap between grid items |
gapX | number | - | Gap between columns |
gapY | number | - | Gap between rows |
All props support responsive values.
Column/Row Values
For columns
and rows
, you can use:
- Preset values:
'1'
,'2'
,'3'
,'4'
,'5'
,'6'
,'12'
- Custom templates:
'1fr 2fr'
,'repeat(3, 1fr)'
,'200px 1fr 200px'
- Auto-responsive:
'repeat(auto-fit, minmax(200px, 1fr))'