Overview
The Spacer component provides flexible spacing between elements. It can expand to fill available space or maintain a fixed size, supporting both horizontal and vertical orientations.Usage
Flexible Spacer
By default, a horizontal spacer expands to fill available space:Fixed Size Spacing
Horizontal Stack
Use a fixed size for consistent spacing between inline elements:Vertical Stack
For vertical spacing, set the orientation:Props
The direction of spacing. Horizontal spacers expand horizontally, vertical spacers expand vertically.
Fixed size for the spacer. Can be a number (pixels) or a CSS length string (e.g.,
"1rem", "20px").When size is provided:- Horizontal spacer: width is set to
size, height is1px - Vertical spacer: height is set to
size, width is1px
size is not provided:- Horizontal spacer: expands to fill available space using
flex: 1 - Vertical spacer: no automatic expansion (set explicit height or use within flex container)
Additional CSS classes to apply to the spacer.
Inline styles to apply. The component will merge these with computed spacing styles.
div element props (ComponentProps<"div">).
Behavior
Flexible vs Fixed
- Without
sizeprop: Horizontal spacer expands to fill available space (useful for pushing content to edges) - With
sizeprop: Creates fixed-width or fixed-height gap (useful for consistent spacing)
Size Values
Thesize prop accepts:
- Numbers: interpreted as pixels (e.g.,
20="20px") - Strings: any valid CSS length (e.g.,
"1rem","2em","20px")
Accessibility
The component includes adata-slot="spacer" attribute for styling and testing purposes. Spacers are purely visual and do not affect document structure or screen reader navigation.