Skip to main content

Grid

Create powerful and responsive multi-column layouts.

Overview

The Grid component is a wrapper around CSS Grid, providing a simple and declarative way to create complex layouts. It allows you to specify the number of columns for different screen sizes, as well as the gap between them.

Usage

import { Grid } from '@/components/layout/grid';
import { Card } from '@/components/ui/card';

export function MyLayout() {
return (
<Grid cols={1} md={2} lg={3} gap={6}>
<Card>Item 1</Card>
<Card>Item 2</Card>
<Card>Item 3</Card>
<Card>Item 4</Card>
<Card>Item 5</Card>
<Card>Item 6</Card>
</Grid>
);
}

Props

PropTypeDescription
colsnumberThe number of columns on mobile screens.
smnumberThe number of columns on small screens.
mdnumberThe number of columns on medium screens.
lgnumberThe number of columns on large screens.
xlnumberThe number of columns on extra-large screens.
gapnumberThe spacing between grid items (Tailwind spacing scale).

Best Practices

  • Do this: Use the Grid component for arranging cards, widgets, and other repeating elements.
  • Do this: Use the responsive props (sm, md, lg, xl) to ensure your layout looks great on all devices.
  • Don't do this: Use Grid for simple one-dimensional layouts; use Stack or Flex instead.