Concepts

Layout and alignment

Choose a direction, cross-axis alignment and spacing.

SwiftUI.js stacks use CSS flexbox; grids use CSS grid. They follow SwiftUI's composition model with browser layout rules.

ContainerDirectionCross-axis alignment
HStackHorizontal rowtop, center, bottom
VStackVertical columnleading, center, trailing
ZStackOverlapping layersCombined horizontal/vertical alignment
import { HStack, Spacer, Text } from '@swiftuijs/ui';

<HStack alignment="center" spacing={12}>
  <Text>Account</Text>
  <Spacer />
  <Text>Settings</Text>
</HStack>

Usage and limitations

  • spacing controls gaps between adjacent children; use shared tokens for consistent spacing.
  • Spacer expands only when the parent has available space along the stack's main axis.
  • A row does not wrap automatically. Allow wrapping explicitly or switch composition for compact containers.
  • CSS shrink/stretch rules apply. Avoid deeply nested wrappers added only to force alignment; check long labels and enlarged text.
  • Native layout proposals and measurement behavior are not emulated. See responsive layouts for container adaptation.