2020-03-22 11:38:02 +08:00
---
category: Components
2022-11-09 12:28:04 +08:00
group: Layout
2020-03-22 11:38:02 +08:00
title: Space
2024-03-22 14:22:42 +08:00
description: Set components spacing.
2022-11-30 20:14:41 +08:00
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*ZiJ3SbOH9SUAAAAAAAAAAAAADrJ8AQ/original
2023-02-09 22:17:31 +08:00
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*37T2R6O9oi0AAAAAAAAAAAAADrJ8AQ/original
2020-03-22 11:38:02 +08:00
---
## When To Use
2022-10-18 16:23:10 +08:00
- Avoid components clinging together and set a unified space.
2022-11-27 01:58:55 +08:00
- Use Space.Compact when child form components are compactly connected and the border is collapsed (After version `antd@4.24.0` Supported).
2020-03-22 11:38:02 +08:00
2023-10-11 14:45:09 +08:00
### 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.
2022-11-09 12:28:04 +08:00
## Examples
2022-11-17 17:31:26 +08:00
<!-- prettier - ignore -->
2022-11-09 12:28:04 +08:00
< code src = "./demo/base.tsx" > Basic Usage< / code >
< code src = "./demo/vertical.tsx" > Vertical Space< / code >
< code src = "./demo/size.tsx" > Space Size< / code >
< code src = "./demo/align.tsx" > Align< / code >
< code src = "./demo/wrap.tsx" > Wrap< / code >
< code src = "./demo/split.tsx" > Split< / code >
< code src = "./demo/compact.tsx" > Compact Mode for form component< / code >
< code src = "./demo/compact-buttons.tsx" > Button Compact Mode< / code >
< code src = "./demo/compact-button-vertical.tsx" > Vertical Compact Mode< / code >
< code src = "./demo/compact-debug.tsx" debug > Input addon debug< / code >
< code src = "./demo/compact-nested.tsx" debug > Nested Space Compact< / code >
< code src = "./demo/debug.tsx" debug > Diverse Child< / code >
< code src = "./demo/gap-in-line.tsx" debug > Flex gap style< / code >
2020-03-22 11:38:02 +08:00
## API
2023-08-08 18:27:48 +08:00
Common props ref: [Common props](/docs/react/common-props)
2022-11-17 17:31:26 +08:00
| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
| align | Align items | `start` \| `end` \|`center` \|`baseline` | - | 4.2.0 |
2024-02-05 11:45:42 +08:00
| classNames | Semantic className | [Record<SemanticDOM, string> ](#semantic-dom ) | - | |
2022-11-17 17:31:26 +08:00
| direction | The space direction | `vertical` \| `horizontal` | `horizontal` | 4.1.0 |
2022-12-22 14:12:26 +08:00
| size | The space size | [Size ](#size ) \| [Size\[\]](#size) | `small` | 4.1.0 \| Array: 4.9.0 |
2022-11-17 17:31:26 +08:00
| split | Set split | ReactNode | - | 4.7.0 |
2024-02-05 11:45:42 +08:00
| styles | Semantic style | [Record<SemanticDOM, CSSProperties> ](#semantic-dom ) | - | |
2022-11-17 17:31:26 +08:00
| wrap | Auto wrap line, when `horizontal` effective | boolean | false | 4.9.0 |
2020-11-27 13:40:40 +08:00
### Size
`'small' | 'middle' | 'large' | number`
2022-10-18 16:23:10 +08:00
### 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
2023-10-11 10:31:36 +08:00
- InputNumber
2022-10-18 16:23:10 +08:00
- Select
- TimePicker
- TreeSelect
2022-11-17 17:31:26 +08:00
| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
| block | Option to fit width to its parent\'s width | boolean | false | 4.24.0 |
| direction | Set direction of layout | `vertical` \| `horizontal` | `horizontal` | 4.24.0 |
| size | Set child component size | `large` \| `middle` \| `small` | `middle` | 4.24.0 |
2023-04-11 10:25:24 +08:00
2024-02-05 11:45:42 +08:00
## Semantic DOM
2023-05-31 13:43:38 +08:00
2024-02-05 11:45:42 +08:00
< code src = "./demo/_semantic.tsx" simplify = "true" > < / code >
2023-05-31 13:43:38 +08:00
2023-04-11 10:25:24 +08:00
## Design Token
< ComponentTokenTable component = "Space" > < / ComponentTokenTable >