Layout
5 componentsFlex, Grid, HStack, VStack, and Spacer — composable layout primitives built on flexbox and CSS grid. No dependencies, no magic.
Import
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
<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
<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
<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
<!-- 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
<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
<!-- Push items to opposite ends -->
<HStack gap={2}>
<div>Logo</div>
<Spacer />
<div>Login</div>
<div>Sign up</div>
</HStack>API Reference — Flex
| Prop | Type | Default | Description |
|---|---|---|---|
direction | 'row' | 'column' | 'row-reverse' | 'column-reverse' | 'row' | flex-direction value. |
gap | number | string | 0 | Gap 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' | false | flex-wrap: wrap or wrap-reverse. |
grow | boolean | false | flex-grow: 1. |
shrink | boolean | false | flex-shrink: 1. |
as | string | 'div' | HTML element tag to render (e.g. "section", "article"). |
class | string | '' | Extra CSS classes. |
children | Snippet | — | Content placed inside the flex container. |
API Reference — Grid
| Prop | Type | Default | Description |
|---|---|---|---|
cols | number | string | 1 | Column count, or a custom grid-template-columns string. |
rows | number | string | undefined | Row count, or a custom grid-template-rows string. |
gap | number | string | undefined | Gap for both axes. |
gapX | number | string | undefined | column-gap only. |
gapY | number | string | undefined | row-gap only. |
padding | number | string | 0 | Padding shorthand. Same rem scale as gap. |
as | string | 'div' | HTML element tag to render. |
class | string | '' | Extra CSS classes. |
children | Snippet | — | Grid cell content. |
API Reference — HStack
| Prop | Type | Default | Description |
|---|---|---|---|
gap | number | string | 0 | Gap between children. |
align | 'start' | 'center' | 'end' | 'stretch' | 'baseline' | 'center' | align-items value. |
justify | 'start' | 'center' | 'end' | 'between' | 'around' | 'evenly' | 'start' | justify-content value. |
wrap | boolean | false | Allow children to wrap to the next row. |
as | string | 'div' | HTML element tag to render. |
class | string | '' | Extra CSS classes. |
children | Snippet | — | Row content. |
API Reference — VStack
| Prop | Type | Default | Description |
|---|---|---|---|
gap | number | string | 0 | Gap 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 | Snippet | — | Column content. |
API Reference — Spacer
| Prop | Type | Default | Description |
|---|---|---|---|
size | number | string | undefined | Fixed size in rem units. When omitted the spacer grows to fill remaining space (flex: 1). |