JGuang

Space

Space · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Space

Set components spacing.

When To Use

  • Avoid components clinging together and set a unified space.
  • Use Space.Compact when child form components are compactly connected and the border is collapsed (After version antd@4.24.0 Supported).

Difference with Flex component

  • Space is used to set the spacing between inline elements. It will add a wrapper element for each child element for inline alignment. Suitable for equidistant arrangement of multiple child elements in rows and columns.
  • Flex is used to set the layout of block-level elements. It does not add a wrapper element. Suitable for layout of child elements in vertical or horizontal direction, and provides more flexibility and control.

Examples

  • Basic Usage · base

  • Vertical Space · vertical

  • Space Size · size

  • Align · align

  • Wrap · wrap

  • separator · separator

  • Compact Mode for form component · compact

  • Button Compact Mode · compact-buttons

  • Vertical Compact Mode · compact-button-vertical

  • Custom semantic dom styling · style-class

API

Common props ref:Common props

Space

PropertyDescriptionTypeDefaultVersionGlobal Config
alignAlign itemsstart | end |center |baseline-4.2.0×
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props: SpaceProps })=> Record<SemanticDOM, string>-5.6.0
directionThe space directionvertical | horizontalhorizontal4.1.0×
orientationThe space directionvertical | horizontalhorizontal×
sizeThe space sizeSize | Size[]small4.1.0 | Array: 4.9.05.6.0
splitSet split, please use separator insteadReactNode-4.7.0×
separatorSet separatorReactNode--×
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props: SpaceProps })=> Record<SemanticDOM, CSSProperties>-5.6.0
verticalOrientation, Simultaneously configure with orientation and prioritize orientationbooleanfalse-×
wrapAuto wrap line, when horizontal effectivebooleanfalse4.9.0×

Size

'small' | 'middle' | 'large' | number

Space.Compact

Use Space.Compact when child form components are compactly connected and the border is collapsed. The supported components are:

  • Button
  • AutoComplete
  • Cascader
  • DatePicker
  • Input/Input.Search
  • InputNumber
  • Select
  • TimePicker
  • TreeSelect
PropertyDescriptionTypeDefaultVersion
blockOption to fit width to its parent's widthbooleanfalse4.24.0
directionSet direction of layoutvertical | horizontalhorizontal4.24.0
orientationSet direction of layoutvertical | horizontalhorizontal
verticalOrientation, Simultaneously configure with orientation and prioritize orientationbooleanfalse-
sizeSet child component sizelarge | medium | smallmedium4.24.0

Space.Addon

This component is available since antd@5.29.0.

Used to create custom cells in compact layouts.

PropertyDescriptionTypeDefaultVersion
childrenCustom contentReactNode-5.29.0

Semantic DOM

Semantic nodeNative descriptionVersion
rootRoot element with flex layout, gap settings, alignment, wrap and other spacing container basic styles—
itemWrapped item element with spacing item layout and styles, providing wrapper for each child element for inline alignment—
separatorSeparator element with divider styling—

Semantic description source: vendor/components/space/demo/_semantic.tsx

Design Token

Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.

Native ComponentToken declares no directly extractable own fields. Shared tokens and inheritance are defined by the declarations below.

Declaration source: vendor/components/space/style/index.ts

import type { CSSObject } from '@ant-design/cssinjs';

import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';

import { genStyleHooks, mergeToken } from '../../theme/internal';

/** Component only token. Which will handle additional calculation of alias token */
// biome-ignore lint/suspicious/noEmptyInterface: ComponentToken need to be empty by default
export interface ComponentToken {}

interface SpaceToken extends FullToken<'Space'> {
  spaceGapSmallSize: number;
  spaceGapMiddleSize: number;
  spaceGapLargeSize: number;
}

Shared native props

Tips: The following generic properties apply to most antd components; those not supported are described separately.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

Install and reproduce an example

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.

Native type references

The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.

  • vendor/components/space/Addon.tsx
  • vendor/components/space/Compact.tsx
  • vendor/components/space/Item.tsx
  • vendor/components/space/context.ts
  • vendor/components/space/index.tsx
  • vendor/components/space/style/addon.ts
  • vendor/components/space/style/compact.ts
  • vendor/components/space/style/index.ts

Source and license

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.