Space
Spaces, separators and compact groups: Space, SpaceCompact and SpaceAddon.
When to use
Space sets equal spacing between individual elements: buttons, tags or fields. SpaceCompact connects compatible controls with a common border without gaps. SpaceAddon adds a cell with a signature to such a compact group.
If you need to distribute free space and align immediate children without wrappers, use Flex.
Individual elements and intervals
In Svelte, pass individual elements through items: text, numbers, snippets, or objects with key and children. Stable key are needed so that the correct instances of interactive elements are preserved when rearranged.
| Problem | Setting | Example |
|---|---|---|
| Explode individual elements | items, size |
Spacing between elements |
| Place elements in a column | orientation="vertical" |
Vertical spacing |
| Set up two axes | Value pair size |
Interval size |
| Add separators | separator |
Separators between elements |
| Save state when rearranging | Objects with key |
Durable items keys |
One children snippet is considered one item. Several buttons inside it do not become separate Space elements: there will be no gaps between them. Empty strings, null, undefined and boolean regular Space are skipped.
size is selected in the order local prop → ConfigProvider.space.size → small. small/medium/large and numeric gap in px are available; the pair specifies intervals along two axes. The generic componentSize does not define gap Space. orientation takes precedence over vertical, wrap allows horizontal group wrapping, align controls the alignment of wrappers.
Compact groups
SpaceCompact also receives independent items, but does not create additional DOM wrappers for them. Through context, controls learn their position, overall size, and adjacent boundaries. Field group connects Select, Input and Button.
Do not combine multiple controls into one snippet if they need to get their own edges. Nested Compacts inherit their position in the overall group. block stretches the group across its width; The transfer of the usual Space is not used here, since it would break the overall frame.
On a narrow screen, limit the width, allow the field to shrink via min-width:0, or change the composition. Vertical group is shown for Button. An arbitrary HTML container does not automatically receive the styling of a compatible control.
SpaceAddon is a native cell, not an input field. variant, status and disabled change its appearance; Disable the adjacent field itself separately.
Design and context
Space has root, item and separator slots available via classNames/styles as an object or function from props. styles contains CSS strings. ConfigProvider.space specifies the overall size and design; the passed nested record replaces the entire parent record. General settings show the priority of local values.
SpaceCompact and SpaceAddon do not have their own semantic classNames/styles; use class/style. The regular Space gap presets are based on the theme's general margins. bind:nativeElement returns the root div after the mount.
All three components have their own prefixCls. A non-empty value specifies the full prefix; empty string and undefined use ConfigProvider.prefixCls with the suffixes -space, -space-compact and -space-addon respectively. Compact's local prefix changes its container, and Addon and fields choose their own classes independently. Independent prefixes show two areas with the same local names: the Badge spacing and decoration remain isolated, the text in the fields is preserved.
theme.cssVar.prefix specifies the namespace of theme variables separate from CSS classes. The service variables of Addon variants and statuses follow the common provider prefix without dots, regardless of the local prefixCls. These internal variables are not public design tokens. Semantic callbacks of regular Space receive the original local props.prefixCls.
Wrappers and decorative separator do not replace the semantics of nested elements. For buttons, links, and fields, maintain accessible names and keyboard focus sequence.
Examples
Spacing between elements
Each items element gets its own wrapper and indentation. Snippets are used for Svelte components.
<script lang="ts">
import { Button, Space } from '@woodger/antd';
let count = $state(0);
</script>
{#snippet action()}
<Button type="primary" onclick={() => { count += 1; }}>{("Save (")}{count})</Button>
{/snippet}
{#snippet link()}<a href={("/contacts")}>{("Contacts")}</a>{/snippet}
<Space wrap items={([{ key: 'text', children: "Actions" }, {
key: 'save',
children: action
}, { key: 'link', children: link }])} />
Vertical spacing
orientation="vertical" arranges elements in a column. The width of root and item is set explicitly for cards to the full available width.
<script lang="ts">
import { Card, Space } from '@woodger/antd';
</script>
{#snippet first()}<Card
title={("Preparation")}
>{("Select components.")}</Card>{/snippet}
{#snippet second()}
<Card title={("Check")}>
{("Check status and availability.")}
</Card>
{/snippet}
<Space
orientation="vertical"
size="medium"
style="width:100%"
styles={{ item: 'width:100%' }}
items={([first, second])}
/>
Interval size
Presets follow the theme. The number specifies px; a pair of values sets the horizontal and vertical spacing separately.
<script lang="ts">
import { Button, Space } from '@woodger/antd';
let preset = $state('small');
let horizontal = $state(12);
let vertical = $state(20);
</script>
<style>
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
label {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
</style>
{#snippet action()}<Button>{("Action")}</Button>{/snippet}
<div class="controls">
<label>{("Size Space ")}<select
bind:value={preset}
><option
value="small"
>small</option><option
value="medium"
>medium</option><option
value="large"
>large</option><option
value="custom"
>{("Pair of numbers")}</option></select></label>
{#if preset === 'custom'}
<label>{("Horizontal gap ")}<input
type="range"
min="0"
max="32"
bind:value={horizontal}
/><output>{horizontal}</output></label>
<label>{("Vertical gap ")}<input
type="range"
min="0"
max="32"
bind:value={vertical}
/><output>{vertical}</output></label>
{/if}
</div>
<Space wrap size={preset === 'custom' ? [horizontal, vertical] : preset as 'small'
| 'medium'
| 'large'} items={([action, action, action])} />
Alignment of elements
start, center, end and baseline are visible on elements of different heights. stretch from the current React API is not supported in the installed package.
<script lang="ts">
import { Button, Space, type SpaceProps } from '@woodger/antd';
let align = $state<NonNullable<SpaceProps['align']>>('center');
</script>
<style>
label {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 16px;
}
</style>
{#snippet big()}<span style="
font-size: 32px;
line-height: 1.5;
">{("Aa")}</span>{/snippet}
{#snippet button()}<Button>{("Button")}</Button>{/snippet}
<label>{("Alignment Space ")}<select
bind:value={align}
>
<option
value="start"
>
{("Home")}
</option>
<option value="center">
{("Center")}
</option>
<option value="end">
{("End")}
</option>
<option value="baseline">
{("Baseline")}
</option>
</select></label>
<Space {align} wrap items={(["Text", big, button])} />
Line breaks
wrap transfers individual items. In this example, the horizontal gap is 8px, the vertical gap is 16px.
<script lang="ts">
import { Button, Space } from '@woodger/antd';
</script>
{#snippet action()}<Button>{("Action")}</Button>{/snippet}
<Space wrap size={[8, 16]} items={(Array.from({ length: 10 }, (_, key) => ({
key,
children: action
})))} />
Separators between elements
separator can be a string or a snippet. Empty values are ignored; There is no separator after the last element.
<script lang="ts">
import { Divider, Space } from '@woodger/antd';
let lines = $state(false);
</script>
<style>
label {
display: block;
margin-bottom: 16px;
}
</style>
{#snippet separator()}<Divider orientation="vertical" />{/snippet}
<label><input type="checkbox" bind:checked={lines} />{(" Vertical lines")}</label>
<Space wrap separator={lines ? separator : '·'} items={([
"Description",
null,
"Delivery",
false,
"Payment"
])} />
Compact field group
SpaceCompact connects the borders of Select, Input and Button. Each control is passed to a separate item; the action uses the current values.
<script lang="ts">
import { Button, Input, Select, SpaceCompact } from '@woodger/antd';
let protocol = $state<'https' | 'http' | undefined>('https');
let domain = $state('woodger.org');
let result = $state('');
</script>
<style>
output {
display: block;
margin-top: 16px;
overflow-wrap: anywhere;
}
</style>
{#snippet scheme()}<Select
aria-label={("Address protocol")}
bind:value={protocol}
options={([
{
value: 'https',
label: 'https://'
},
{ value: 'http', label: 'http://' }
])}
style="
width: 96px;
flex: none;
"
/>{/snippet}
{#snippet input()}<Input
aria-label={("Domain address")}
bind:value={domain}
style="
min-width: 0;
flex: 1;
"
/>{/snippet}
{#snippet action()}<Button type="primary" onclick={() => {
result = ("" + String((protocol ?? 'https')) + "://" + String((domain.trim())) + "");
}}>{("Assemble")}</Button>{/snippet}
<SpaceCompact block items={([scheme, input, action])} />
<output aria-label={("Collected address")}>{(result
|| ("Address not collected yet"))}</output>
Vertical group of buttons
Vertical connection is for Button. orientation specifies the axis.
<script lang="ts">
import { Button, SpaceCompact } from '@woodger/antd';
let selected = $state(("Overview"));
</script>
{#snippet overview()}
<Button onclick={() => { selected = ("Overview"); }}>
{("Overview")}
</Button>
{/snippet}
{#snippet examples()}
<Button onclick={() => { selected = ("Examples"); }}>
{("Examples")}
</Button>
{/snippet}
{#snippet reference()}
<Button onclick={() => { selected = ("Help"); }}>
{("Help")}
</Button>
{/snippet}
<SpaceCompact orientation="vertical" items={([overview, examples, reference])} />
<p><output aria-label={("Group section")}>{selected}</output></p>
Additional cell SpaceAddon
SpaceAddon creates a native compact group cell. The option is specified for both the cell and the field.
<script lang="ts">
import { Input, SpaceAddon, SpaceCompact, type SpaceAddonProps } from '@woodger/antd';
let variant = $state<NonNullable<SpaceAddonProps['variant']>>('outlined');
let value = $state('12');
</script>
<style>
label {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
margin-bottom: 16px;
}
</style>
{#snippet prefix()}<SpaceAddon {variant}>{("Weight")}</SpaceAddon>{/snippet}
{#snippet input()}<Input
aria-label={("Shipping weight")}
bind:value
{variant}
style="
min-width: 0;
flex: 1;
"
/>{/snippet}
{#snippet suffix()}<SpaceAddon {variant}>{("kg")}</SpaceAddon>{/snippet}
<label>{("Addon Option ")}<select
bind:value={variant}
><option
value="outlined"
>outlined</option><option
value="filled"
>filled</option><option
value="borderless"
>borderless</option><option
value="underlined"
>underlined</option></select></label>
<SpaceCompact block items={([prefix, input, suffix])} />
Semantic slots
The classNames object and the styles function style root, item, and separator separately. These props are missing in Compact.
<script lang="ts">
import { Space } from '@woodger/antd';
</script>
<Space wrap items={(["Preparation", "Check", "Issue"])} separator="/"
classNames={{ root: 'custom-space' }}
styles={({ props }) => ({
root: `
padding: 12px;
border: 1px dashed var(--ant-color-border);
border-radius: 8px;
`,
item: props.wrap ? `
padding: 4px 8px;
background: var(--ant-color-primary-bg);
` : '',
separator: `
color: #722ed1;
font-weight: 600;
`
})}
/>
Resistant keys items
Stable key preserve instances of components when rearranged. The field text remains the same after changing the order.
<script lang="ts">
import { Button, Input, Space } from '@woodger/antd';
let reversed = $state(false);
let value = $state(("Draft"));
</script>
{#snippet input()}<Input
aria-label={("Draft title")}
bind:value
style="width:140px"
/>{/snippet}
{#snippet text()}<span>{("Name")}</span>{/snippet}
<Space wrap items={(reversed
? [{ key: 'input', children: input }, { key: 'label', children: text }]
: [{ key: 'label', children: text }, { key: 'input', children: input }])}
/>
<p><Button
onclick={() => { reversed = !reversed; }}
>{("Swap")}</Button></p>
General settings Space
ConfigProvider.space: size and semantic defaults, local priority and theme aliases.
<script lang="ts">
import { Checkbox, ConfigProvider, InputNumber, Space } from '@woodger/antd';
let gap = $state(20);
let local = $state(false);
const items = ["First", "Second"];
</script>
<style>
.settings {
display: grid;
gap: 16px;
margin-bottom: 24px;
}
label {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
.examples {
display: grid;
gap: 16px;
}
</style>
<div class="settings">
<label>{("Provider span\n ")}<InputNumber aria-label={("Space provider gap")} value={gap} min={0} max={32}
onValueChange={next => { gap = next ?? 0; }} />
</label>
<Checkbox bind:checked={local}>{("Local size Space")}</Checkbox>
</div>
<ConfigProvider componentSize="large"
space={{
size: gap,
class: 'space-provider-root',
classNames: { item: 'space-provider-item' },
styles: { item: `
border: 1px dashed #d48806;
padding: 4px;
` }
}}
theme={{ components: { Space: { paddingXS: 10 } } }}>
<div class="examples">
<Space items={(items)} size={local ? 6 : undefined} class="inherited-space" wrap />
<Space items={(items)} size="small" class="alias-space" wrap />
<ConfigProvider space={{ size: 4 }}>
<Space items={(items)} class="nested-space" wrap />
</ConfigProvider>
</div>
</ConfigProvider>
The neighboring area uses the common prefix neighbor. Local Compact changes container; Addon and Input retain their own classes and styling.
Independent prefixes Space
Space, Compact and Addon choose their own classes. Two areas with the same local names save spacing, Badge, and field design.
<script lang="ts">
import {
Badge,
Checkbox,
ConfigProvider,
Input,
Space,
SpaceAddon,
SpaceCompact
} from '@woodger/antd';
let custom = $state(true);
let local = $state(true);
let addon = $state(false);
let draft = $state('');
let weight = $state('12');
const prefix = $derived(custom ? 'suite' : 'ant');
</script>
<style>
.example {
display: grid;
gap: 20px;
min-width: 0;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.scope {
display: grid;
gap: 16px;
min-width: 0;
}
p { margin: 0; }
output { overflow-wrap: anywhere; }
</style>
{#snippet editor()}
<Input bind:value={draft} aria-label={("Draft Space with prefix")}
style="
width: 112px;
max-width: 100%;
" />
{/snippet}
{#snippet counter()}<Badge count={5} class="prefix-space-badge" />{/snippet}
{#snippet start()}
<SpaceAddon prefixCls={addon ? 'project-addon' : ''}
status="warning" class="prefix-main-addon">{("Weight")}</SpaceAddon>
{/snippet}
{#snippet field()}
<Input bind:value={weight} aria-label={("Compact weight with prefix")}
status="warning" style="
min-width: 0;
flex: 1;
" />
{/snippet}
{#snippet end()}
<SpaceAddon
prefixCls={addon ? 'project-addon' : ''}
status="warning"
>{("kg")}</SpaceAddon>
{/snippet}
{#snippet neighborCounter()}<Badge count={3} class="prefix-neighbor-badge" />{/snippet}
{#snippet neighborStart()}
<SpaceAddon prefixCls={addon ? 'project-addon' : ''} variant="filled"
class="prefix-neighbor-addon">{("Weight")}</SpaceAddon>
{/snippet}
{#snippet neighborField()}
<Input value="42" readonly variant="filled" aria-label={("Weight of adjacent group")}
style="
min-width: 0;
flex: 1;
" />
{/snippet}
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("General prefix Space suite")}</Checkbox>
<Checkbox bind:checked={local}>{("Local prefixes Space and Compact")}</Checkbox>
<Checkbox bind:checked={addon}>{("Local Prefix Addon")}</Checkbox>
</div>
<ConfigProvider prefixCls={prefix} theme={{ cssVar: { prefix: 'space-theme' } }}>
<div class="scope">
<Space prefixCls={local ? 'project-space' : ''} class="prefix-space-main"
items={([{ key: 'editor', children: editor }, {
key: 'badge',
children: counter
}, "Label"])}
size="small" separator="|" wrap />
<SpaceCompact prefixCls={local ? 'project-compact' : ''} class="prefix-compact-main"
items={([start, field, end])} block />
</div>
</ConfigProvider>
<ConfigProvider prefixCls="neighbor">
<div class="scope">
<Space prefixCls={local ? 'project-space' : ''} class="prefix-space-neighbor"
items={([neighborCounter, "Neighboring area"])} size="medium" wrap />
<SpaceCompact prefixCls={local ? 'project-compact' : ''} class="prefix-compact-neighbor"
items={([neighborStart, neighborField])} block />
</div>
</ConfigProvider>
<output
aria-label={("Prefixes Space")}
>{("\n General: ")}{prefix}; Space: {(local ? 'project-space' : prefix + '-space')};
Compact: {(local ? 'project-compact' : prefix + '-space-compact')};
Addon: {(addon ? 'project-addon' : prefix + '-space-addon')}
</output>
<p>
{("The neighboring area uses the common prefix neighbor. Local Compact changes container; Addon and Input retain their own classes and styling.")}
</p>
</div>
Actions and project address
Saved review example: vertical, separators, counter and address assembly via SpaceCompact.
<script lang="ts">
import { Button, Input, Space, SpaceAddon, SpaceCompact } from '@woodger/antd';
let vertical = $state(false);
let separator = $state(false);
let clicks = $state(0);
let domain = $state('example');
let address = $state('');
</script>
<style>
.controls {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
.controls label {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px;
}
output {
display: block;
margin-top: 16px;
}
</style>
{#snippet first()}<Button
type="primary"
onclick={() => { clicks++; }}
>{("Save (")}{clicks})</Button>{/snippet}
{#snippet second()}<Button>{("Preview")}</Button>{/snippet}
{#snippet third()}<a href={("#space")}>{("Help")}</a>{/snippet}
{#snippet addon()}<SpaceAddon>https://</SpaceAddon>{/snippet}
{#snippet domainInput()}<Input
aria-label={("Project domain")}
bind:value={domain}
style="
width: 100%;
min-width: 0;
"
/>{/snippet}
{#snippet open()}<Button type="primary" onclick={() => {
address = ("" + String((domain.trim())) + ".org");
}}>{("Open")}</Button>{/snippet}
<div class="controls">
<label><input type="checkbox" bind:checked={vertical} />{(" Vertical")}</label>
<label><input type="checkbox" bind:checked={separator} />{(" Separators")}</label>
</div>
<Space
items={([
{ key: 'save', children: first },
{ key: 'preview', children: second },
{ key: 'help', children: third }
])}
{vertical}
wrap
separator={separator ? '·' : undefined}
/>
<div style="margin-top:16px"><SpaceCompact block size="medium" items={([
addon,
domainInput,
open
])} /></div>
{#if address}<output aria-label={("Project address")}>{address}</output>{/if}
API
Themes of the ant.design live page are mapped to the public API of the installed package. Full definitions of Props are in @woodger/antd.
| Theme | Example or limitation |
|---|---|
| Basic Usage | Separate snippets in items. |
| Vertical Space | Cards in a column. |
| Space Size | Presets and a couple of numbers. |
| Align | Available types of alignment; stretch is marked as space. |
| Wrap | Separate spacing between lines. |
| separator | String or Divider snippet. |
| Compact Mode for form component | Select, Input and Button. |
| Button Compact Mode | Size and actions of buttons. |
| Vertical Compact Mode | Buttons in a column. |
| Custom semantic dom styling | Class object and style function. |
| CSS prefix | Separate prefixes Space, Compact and Addon in independent areas. |
| Property | Description | Type | Default |
|---|---|---|---|
prefixCls | Full local CSS prefix. The empty string and undefined inherit the common provider prefix. | string | ConfigProvider.prefixCls + "-space" |
items | Individual elements: scalars, snippets or key/children objects. If present, takes precedence over children. | readonly (SpaceContent | SpaceItem)[] | — |
children | One common item. Multiple elements within a snippet are not automatically split. | Snippet | — |
orientation | Sets horizontal or vertical position. | horizontal | vertical | horizontal |
vertical | Short recording of vertical orientation. | boolean | false |
size | small/medium/large, px number or gap pair. Local size takes precedence; componentSize is not involved. | SpaceSize | [SpaceSize, SpaceSize] | ConfigProvider.space.size / small |
align | Alignment items; stretch of the current React API is missing. | start | end | center | baseline | center horizontal |
wrap | Transfer of individual items in a horizontal position. | boolean | false |
separator | Separator between non-empty items. | SpaceContent | — |
classNames | The root, item and separator classes. | SpaceSlots | function | — |
styles | CSS lines for slots; the function receives info.props. | SpaceSlots | function | — |
nativeElement | bind:nativeElement; root is missing if the items array is empty. | HTMLDivElement | — |
ConfigProvider.space
| Property | Description | Type | Default |
|---|---|---|---|
size | Total interval if there is no local size. | SpaceSize | readonly [SpaceSize, SpaceSize] | small |
class | The general root class to which the local class is appended. | string | — |
style | Root CSS after context styles.root and before local styles.root/style. | string | — |
classNames | An object or function with classes root/item/separator. | SpaceSemantic | — |
styles | Object or function with CSS root/item/separator. The nested space record is replaced entirely. | SpaceSemantic | — |
SpaceCompact
items and children accept the same content format. size — small/medium/large, by default inherits the provider size. orientation/vertical set the axis, block stretches root to the full width. class, rootClassName, style and bind:nativeElement refer to the container.
prefixCls specifies the full container prefix. Without a non-empty value, ConfigProvider.prefixCls + "-space-compact" is used. Child controls choose their prefixes regardless of the local Compact.
SpaceAddon
children - content snippet. variant: outlined, filled, borderless or underlined, default is outlined. status: error/warning, disabled: boolean; class/style and bind:nativeElement refer to the cell. These parameters formalize the addon, the state of the field is transferred to the field itself separately.
prefixCls specifies the full prefix of the cell; empty string and undefined use ConfigProvider.prefixCls + "-space-addon". Local SpaceCompact.prefixCls does not change this choice.
Semantic DOM
Space creates a root div, a wrapper div item for each non-empty value, and a span separator between them. classNames/styles accept an object or function. Empty strings, null, undefined and boolean for Space are ignored; A stable key is needed to rearrange dynamic items.
SpaceCompact creates a root div and passes the context to individual items without additional DOM wrappers. Therefore, controls should be independent items, and not several neighbors within one snippet. Nested Compacts inherit their position in the overall group.
SpaceAddon creates a div with the contents of the cell. This is not an input field: disabled specifies the cell's appearance; the field is disabled separately. ConfigProvider.space sets the defaults of regular Space; Compact/Addon does not have semantic props.
Semantic callbacks Space get the original local props.prefixCls. Class prefix and theme.cssVar.prefix are independent; Addon service variables follow the common provider prefix without dots.
Registration tokens
Space, SpaceCompact and Addon do not have their own component tokens. Spacing sizes small/medium/large use common paddingXS/padding/paddingLG; theme.components.Space can refine these aliases. Typography and direction are inherited from the provider. The Compact size refers to the controls, and the Space size refers to the distance between them.
| Token | Current value |
|---|---|
padding | 16 |
paddingLG | 24 |
paddingXS | 8 |
FAQ
Which size has priority?
Space's local size overlaps ConfigProvider.space.size; without them, small is used. ComponentSize specifies the size of the controls, not the gap Space.
Why did the elements inside children stick together?
One children snippet is considered one item. Pass individual snippets to items.
When to choose Flex?
When you need to manage immediate children without wrappers and distribute free space.
Why does Compact not transfer fields?
This is a connected group without a gap. For a narrow screen, adjust the dimensions or change the composition.
Is it possible to connect any components?
The control must support the Compact context. The examples tested Select, Input, Button and SpaceAddon; a regular container itself does not receive a common frame.