Stack
A flexbox layout component that stacks children with consistent spacing. Use HStack for horizontal layouts and VStack for vertical layouts.
Anatomy
<script>
import { Stack, HStack, VStack } from "@saas-ui/svelte/layout/stack";
</script>
<!-- Vertical stack (default) -->
<Stack gap={4}>
<div>Item 1</div>
<div>Item 2</div>
</Stack>
<!-- Horizontal stack -->
<HStack gap={4}>
<div>Item 1</div>
<div>Item 2</div>
</HStack>
<!-- Explicit vertical stack -->
<VStack gap={4}>
<div>Item 1</div>
<div>Item 2</div>
</VStack>Examples
Basic Accessibility
gap.
<Stack>
<DecorativeBox class="h-20" />
<DecorativeBox class="h-20" />
<DecorativeBox class="h-20" />
</Stack> Horizontal Accessibility
direction="row" to arrange items horizontally instead of vertically.
<div class="flex justify-center">
<Stack direction="row" class="h-20">
<DecorativeBox class="w-40!" />
<DecorativeBox class="w-40!" />
<DecorativeBox class="w-40!" />
</Stack>
</div> Responsive Accessibility
Stack with responsive classes to change layout direction based on viewport size.
<div class="flex justify-center">
<Stack gap={10} class="flex-col md:flex-row">
<DecorativeBox class="size-20!" />
<DecorativeBox class="size-20!" />
<DecorativeBox class="size-20!" />
</Stack>
</div>With H Stack
HStack is a convenience component that defaults to horizontal direction with centered alignment.
<div class="flex justify-center">
<HStack>
<DecorativeBox class="h-10 w-40!" />
<DecorativeBox class="h-5 w-40!" />
<DecorativeBox class="h-20 w-40!" />
</HStack>
</div> With Separator Accessibility
Divider component.
<Stack>
<DecorativeBox class="h-20" />
<Divider />
<DecorativeBox class="h-20" />
<Divider />
<DecorativeBox class="h-20" />
</Stack>With V Stack
VStack is a convenience component that defaults to vertical direction with stretch alignment.
<VStack>
<DecorativeBox class="h-20 w-1/2" />
<DecorativeBox class="h-20 w-1/4" />
<DecorativeBox class="h-20 w-full" />
</VStack>Props
| Prop | Type | Default | Description |
|---|---|---|---|
direction | row | column | row-reverse | col-reverse | column | - |
align | start | center | end | stretch | baseline | stretch | - |
justify | start | center | end | between | around | start | - |
class | text | - | Additional CSS classes to apply. |
children | any | - | The content to be rendered inside the component. |