Skip to content

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:

gapClassSize
0gap-00
1gap-14px
2gap-28px
3gap-312px
4gap-416px
5gap-624px
6gap-832px
7gap-1248px

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.

minWidthSmallest column
xs10rem (160px)
sm14rem (224px)
md18rem (288px, default)
lg24rem (384px)
xl32rem (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.

sizeClassMax width
xsmax-w-md448px
smmax-w-2xl672px
mdmax-w-4xl896px (default)
lgmax-w-6xl1152px
xlmax-w-8xl1408px
fullmax-w-noneNo 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.

sizePadding
noneNo padding (default)
1 / 2 / 3 / 4py-6 / py-10 / py-16 / py-24
compactpy-8, md:py-12
strippy-10, md:py-14
bodypy-16, md:py-24
heropy-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.

Component Source
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.

Configure Theme
Theme
Brand Color
Custom
Gray Family
Appearance
Radius
Scaling
Panel Style
Heading Font
Body Font