Layout

5 components

Flex, Grid, HStack, VStack, and Spacer — composable layout primitives built on flexbox and CSS grid. No dependencies, no magic.

Import

ts
import Flex   from '$lib/components/Flex.svelte';
import Grid   from '$lib/components/Grid.svelte';
import HStack from '$lib/components/HStack.svelte';
import VStack from '$lib/components/VStack.svelte';
import Spacer from '$lib/components/Spacer.svelte';

Usage

Alpha
Beta
Gamma
svelte
<HStack gap={3}>
  <div>Alpha</div>
  <div>Beta</div>
  <div>Gamma</div>
</HStack>

HStack

Horizontal stack — arranges children left to right with flex-direction: row. Default align="center".

One
Two
Three
svelte
<HStack gap={3}>
  <div>One</div>
  <div>Two</div>
  <div>Three</div>
</HStack>

VStack

Vertical stack — arranges children top to bottom with flex-direction: column.

First
Second
Third
svelte
<VStack gap={3}>
  <div>First</div>
  <div>Second</div>
  <div>Third</div>
</VStack>

Flex

General-purpose flex container. Exposes all flex properties — use it when HStack or VStack are not enough.

direction="row-reverse"

1
2
3

direction="column" align="end"

Right aligned
Items here

justify="between"

Start
End
svelte
<!-- row-reverse -->
<Flex direction="row-reverse" gap={3}>
  <div>1</div>
  <div>2</div>
  <div>3</div>
</Flex>

<!-- column, right-aligned -->
<Flex direction="column" align="end" gap={2}>
  <div>Right aligned</div>
  <div>Items here</div>
</Flex>

Grid

CSS Grid wrapper. A numeric cols value expands to repeat(n, minmax(0, 1fr)); pass a string for any custom template.

1
2
3
4
5
6
svelte
<Grid cols={3} gap={3}>
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
</Grid>

Spacer

Fills remaining space in a flex container (flex: 1 1 0). Pass size for a fixed gap instead.

Spacer pushes Login/Sign up to the right

Logo
Login
Sign up
svelte
<!-- Push items to opposite ends -->
<HStack gap={2}>
  <div>Logo</div>
  <Spacer />
  <div>Login</div>
  <div>Sign up</div>
</HStack>

API Reference — Flex

PropTypeDefaultDescription
direction 'row' | 'column' | 'row-reverse' | 'column-reverse''row'flex-direction value.
gap number | string0Gap between children. Numbers map to rem (n × 0.25rem).
align 'start' | 'center' | 'end' | 'stretch' | 'baseline''stretch'align-items value.
justify 'start' | 'center' | 'end' | 'between' | 'around' | 'evenly''start'justify-content value.
wrap boolean | 'reverse'falseflex-wrap: wrap or wrap-reverse.
grow booleanfalseflex-grow: 1.
shrink booleanfalseflex-shrink: 1.
as string'div'HTML element tag to render (e.g. "section", "article").
class string''Extra CSS classes.
children SnippetContent placed inside the flex container.

API Reference — Grid

PropTypeDefaultDescription
cols number | string1Column count, or a custom grid-template-columns string.
rows number | stringundefinedRow count, or a custom grid-template-rows string.
gap number | stringundefinedGap for both axes.
gapX number | stringundefinedcolumn-gap only.
gapY number | stringundefinedrow-gap only.
padding number | string0Padding shorthand. Same rem scale as gap.
as string'div'HTML element tag to render.
class string''Extra CSS classes.
children SnippetGrid cell content.

API Reference — HStack

PropTypeDefaultDescription
gap number | string0Gap between children.
align 'start' | 'center' | 'end' | 'stretch' | 'baseline''center'align-items value.
justify 'start' | 'center' | 'end' | 'between' | 'around' | 'evenly''start'justify-content value.
wrap booleanfalseAllow children to wrap to the next row.
as string'div'HTML element tag to render.
class string''Extra CSS classes.
children SnippetRow content.

API Reference — VStack

PropTypeDefaultDescription
gap number | string0Gap between children.
align 'start' | 'center' | 'end' | 'stretch' | 'baseline''stretch'align-items value.
justify 'start' | 'center' | 'end' | 'between' | 'around' | 'evenly''start'justify-content value.
as string'div'HTML element tag to render.
class string''Extra CSS classes.
children SnippetColumn content.

API Reference — Spacer

PropTypeDefaultDescription
size number | stringundefinedFixed size in rem units. When omitted the spacer grows to fill remaining space (flex: 1).