Space

Space puts an equal gap between elements. SpaceCompact joins buttons and fields into one block, and SpaceAddon adds a cell of text to it.

Import
import { Space, SpaceItem, SpaceCompact, SpaceAddon } from 'svelte-ant-design';
Links
src/lib/Space Report an issue Component README

When to use

  • Use a Space to keep buttons, links or tags apart without margins of your own. For a page layout in columns use Grid.
  • Use a SpaceCompact when several controls make one input: an address with its button, a unit next to a number.
  • Do not join controls that do unrelated things: a joined block reads as one.

Examples

Basic

A Space puts an equal gap between its elements.

vertical
vertical with SpaceItem

Vertical

vertical (or orientation="vertical") makes a column. An element keeps its own width; a SpaceItem fills the width of the column.

size="small"
size="medium"
size="large"
size={40}

Size

size: small (8px, the default), medium (16px), large (24px) or a number of pixels.

align="start"
Text Block
align="center"
Text Block
align="end"
Text Block
align="baseline"
Text Block

Align

align places the elements across the row: start, center (the default of a row), end, baseline or stretch.

separator="|"
separator as a snippet
Draft
3 pages
Updated today

Separator

separator takes a text or a snippet. It is drawn by each SpaceItem before itself and follows {#if} and {#each}.

wrap, size={[8, 16]}

Wrap

wrap lets a row go on in the next line; a pair in size sets the gaps between columns and between rows.

block: Input and Button
Select and InputSearch
InputPassword and two buttons

Compact

SpaceCompact joins controls into one block: their borders overlap and only the outer corners stay round. block makes it as wide as its parent.

size="large"
size="medium"
size="small"

Compact sizes

size of the block is the size of every control that names none of its own.

Compact, vertical

vertical stacks the controls of a block.

SpaceAddon before and after a field
https://
.example.com
with a button
$

Addon

SpaceAddon is a cell of text in a block, as high as the controls beside it.

a block inside a block
with Tooltip and Dropdown

Nested and wrapped

Blocks inside a block are joined as one. A control wrapped in a Tooltip or a Dropdown stays joined; what it opens is not part of the block.

/
Home
/
Library
/
Space

Classes and styles

classNames and styles address the parts root, item and separator.

API

PropertyDescriptionTypeDefault
orientationThe direction of the row; horizontal unless it or vertical says otherwise. It wins over vertical.'horizontal' | 'vertical'—
verticalA shorthand for orientation="vertical".booleanfalse
sizeThe gap: a name or a number of pixels; a pair is the gap between columns and between rows.SpaceSize | [SpaceSize, SpaceSize]'small'
alignAlignment across the row. Without it a row is centered; in a column an element keeps its width and a SpaceItem fills it.'start' | 'end' | 'center' | 'baseline' | 'stretch'—
wrapA horizontal row goes on in the next line.booleanfalse
separatorDrawn between the items, by each SpaceItem before itself.string | Snippet—
classNamesExtra classes for the parts root, item and separator.SpaceClassNames—
stylesInline styles for the same parts.SpaceStyles—
childrenThe elements.Snippet—
class / styleClass and style of the root.string—
native attributesOther attributes of the root <div>.HTMLAttributes<HTMLDivElement>—
Differences from Ant Design: Space does not wrap its children, so an element goes into SpaceItem where it needs a separator or item styles, and without it a block element of a column is as wide as its content; Space.Compact and Space.Addon are SpaceCompact and SpaceAddon; direction and split are not taken (use orientation and separator); classNames and styles are objects, not functions.

SpaceItem API

PropertyDescriptionTypeDefault
childrenOne item.Snippet—
class / styleClass and style of the element of the item.string—
native attributesOther attributes of the <div>.HTMLAttributes<HTMLDivElement>—

SpaceCompact API

PropertyDescriptionTypeDefault
blockAs wide as the parent.booleanfalse
orientationThe direction of the block; horizontal unless it or vertical says otherwise. It wins over vertical.'horizontal' | 'vertical'—
verticalA shorthand for orientation="vertical".booleanfalse
sizeThe size of the controls that name none of their own. middle and default are aliases of medium.'large' | 'medium' | 'middle' | 'small' | 'default'—
childrenThe controls: Button, Input, InputPassword, InputSearch, InputTextArea, Select, SpaceAddon and nested blocks.Snippet—
class / styleClass and style of the root.string—
native attributesOther attributes of the root <div>.HTMLAttributes<HTMLDivElement>—

SpaceAddon API

PropertyDescriptionTypeDefault
childrenThe content of the cell.Snippet—
class / styleClass and style of the cell.string—
native attributesOther attributes of the <div>.HTMLAttributes<HTMLDivElement>—

Design tokens

TokenDescriptionDefault
--ads-space-gap-smallThe gap of size="small".8px
--ads-space-gap-mediumThe gap of size="medium".16px
--ads-space-gap-largeThe gap of size="large".24px
--ads-space-compact-dividerThe line between two solid buttons of a block.rgba(255, 255, 255, 0.4)

Accessibility

  • Space, SpaceCompact and SpaceAddon are layout: they add no roles and move nothing, so a screen reader and the keyboard meet the elements in the order of the page.
  • The text of a SpaceAddon is not a label. Name the control beside it with aria-label or a <label>. A separator is read like any text: give a decorative one aria-hidden.
  • Checked with a real screen reader (Orca with Firefox): it reads the controls of a compact block with their names in the order of the page, the text of an addon before its field and the items of a separated row. Not checked with NVDA, JAWS, VoiceOver or on a phone.