Layout
Pages are built from a few layout components: Section for bands, Container for width, Grid and Flex for arrangement. Spacing comes from their gap props, not from margins on the children.
The primitives
Box
A plain element with no layout of its own. Use it for a background, a surface or a polymorphic tag (as="article").
Flex
A flex row or column with direction, align, justify, wrap and gap. Defaults: row, gap 3.
Grid
A CSS grid with 1 to 6 columns, or columns="auto" to fit as many as the width allows. Default gap 4.
Container
Centres content at a maximum width with 16px side padding (24px from the sm breakpoint).
Section
A full-width <section> band. No padding by default; pick a size for vertical rhythm.
Inset
Pulls an image or table to the edges of a Card. p="sm" cancels 16px of card padding, p="md" 20px.
Row
One clickable line with leading and trailing slots, for sidebars, menus and lists. Not a page layout tool.
Spacing comes from gap
Put siblings in a Flex or Grid and set gap on the parent. Don't add mt-* or mb-* to the children: margins don't collapse in flex and grid, they fight the parent's gap, and they break when the order changes. Flex and Grid share one gap scale:
| gap | Class | Size |
|---|---|---|
0 | gap-0 | 0 |
1 | gap-1 | 4px |
2 | gap-2 | 8px |
3 | gap-3 | 12px |
4 | gap-4 | 16px |
5 | gap-6 | 24px |
6 | gap-8 | 32px |
7 | gap-12 | 48px |
From step 5 the gap numbers no longer match Tailwind's: gap="5" is gap-6. Inside a card, wrap the children in <Flex direction="column" gap="3">.
Grid
For card grids, use columns="auto". It fits as many columns as the container allows at minWidth and wraps by itself, so it needs no breakpoints and works inside sidebars and panels. maxColumns (2 to 6) caps the count on wide screens.
| minWidth | Smallest column |
|---|---|
xs | 10rem (160px) |
sm | 14rem (224px) |
md | 18rem (288px, default) |
lg | 24rem (384px) |
xl | 32rem (512px) |
Fixed counts (columns 1 to 6) stay fixed at every width unless you set stack: "mobile" goes to one column below the md breakpoint, "tablet" below lg, and "auto" goes from 3 or more columns to 2 below lg and 1 below md. The default is 2 columns.
// Cards: as many 14rem columns as fit, never more than 3
<Grid columns="auto" minWidth="sm" maxColumns="3" gap="4">…</Grid>
// A fixed 4-column row that collapses on smaller screens
<Grid columns="4" stack="auto" gap="5">…</Grid>Container and Section
Container sets the reading width. It always centres and adds side padding.
| size | Class | Max width |
|---|---|---|
xs | max-w-md | 448px |
sm | max-w-2xl | 672px |
md | max-w-4xl | 896px (default) |
lg | max-w-6xl | 1152px |
xl | max-w-8xl | 1408px |
full | max-w-none | No limit |
Section has no padding unless you give it a size. Backgrounds and surfaces go on the Section so they run full width; the Container inside keeps the content narrow.
| size | Padding |
|---|---|
none | No padding (default) |
1 / 2 / 3 / 4 | py-6 / py-10 / py-16 / py-24 |
compact | py-8, md:py-12 |
strip | py-10, md:py-14 |
body | py-16, md:py-24 |
hero | py-24, md:py-32 |
Putting it together
A section of cards
Starter
One project and community support.
Team
Unlimited projects and shared billing.
Enterprise
Single sign-on and an uptime agreement.
import { Card, Container, Flex, Grid, Section, Text } from "@shavin/ui";
const PLANS = [
{ title: "Starter", desc: "One project and community support." },
{ title: "Team", desc: "Unlimited projects and shared billing." },
{ title: "Enterprise", desc: "Single sign-on and an uptime agreement." },
];
export function Plans() {
return (
<Section size="1">
<Container size="md">
<Grid columns="auto" minWidth="xs" gap="4">
{PLANS.map((plan) => (
<Card key={plan.title} padding="md">
<Flex direction="column" gap="3">
<Text size="sm" weight="semibold" color="fg">{plan.title}</Text>
<Text size="sm" color="subtle">{plan.desc}</Text>
</Flex>
</Card>
))}
</Grid>
</Container>
</Section>
);
}Related
For an app with a sidebar and header, start from AppFrame instead of composing the shell yourself. For how layouts respond to their container and the screen, see the responsive rules.