2016-04-20 18:51:31 +08:00
---
category: Components
2016-04-22 14:52:19 +08:00
title: Button
2024-03-22 14:22:42 +08:00
description: To trigger an operation.
2024-01-29 14:50:36 +08:00
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*7va7RKs3YzIAAAAAAAAAAAAADrJ8AQ/original
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*3T4cRqxH9-8AAAAAAAAAAAAADrJ8AQ/original
2022-11-09 12:28:04 +08:00
demo:
cols: 2
group:
title: General
order: 1
2016-04-20 18:51:31 +08:00
---
2016-05-25 09:43:26 +08:00
## When To Use
2016-04-22 14:52:19 +08:00
2024-06-12 14:27:15 +08:00
A button means an operation (or a series of operations). Clicking a button will trigger its corresponding business logic.
2016-04-22 14:52:19 +08:00
2020-07-21 10:07:38 +08:00
In Ant Design we provide 5 types of button.
2020-01-03 15:22:16 +08:00
2024-06-12 14:27:15 +08:00
- Primary button: used for the main action, there can be at most one primary button in a section.
- Default button: used for a series of actions without priority.
2023-08-29 09:14:48 +08:00
- Dashed button: commonly used for adding more actions.
2020-05-06 10:15:33 +08:00
- Text button: used for the most secondary action.
2020-01-03 15:22:16 +08:00
- Link button: used for external links.
2020-01-03 15:30:05 +08:00
And 4 other properties additionally.
2020-01-03 15:22:16 +08:00
- `danger` : used for actions of risk, like deletion or authorization.
- `ghost` : used in situations with complex background, home pages usually.
2024-06-12 14:27:15 +08:00
- `disabled` : used when actions are not available.
- `loading` : adds a loading spinner in button, avoids multiple submits too.
2020-01-03 15:22:16 +08:00
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/basic.tsx" > Type< / code >
2024-09-03 17:39:02 +08:00
< code src = "./demo/color-variant.tsx" version = "5.21.0" > Color & Variant< / code >
2022-11-09 12:28:04 +08:00
< code src = "./demo/icon.tsx" > Icon< / code >
2024-04-07 22:42:20 +08:00
< code src = "./demo/icon-position.tsx" version = "5.17.0" > Icon Position< / code >
2022-11-17 13:20:58 +08:00
< code src = "./demo/debug-icon.tsx" debug > Debug Icon< / code >
2023-01-06 09:46:00 +08:00
< code src = "./demo/debug-block.tsx" debug > Debug Block< / code >
2022-11-09 12:28:04 +08:00
< code src = "./demo/size.tsx" > Size< / code >
< code src = "./demo/disabled.tsx" > Disabled< / code >
< code src = "./demo/loading.tsx" > Loading< / code >
< code src = "./demo/multiple.tsx" > Multiple Buttons< / code >
< code src = "./demo/ghost.tsx" > Ghost Button< / code >
< code src = "./demo/danger.tsx" > Danger Buttons< / code >
< code src = "./demo/block.tsx" > Block Button< / code >
< code src = "./demo/legacy-group.tsx" debug > Deprecated Button Group< / code >
< code src = "./demo/chinese-chars-loading.tsx" debug > Loading style bug< / code >
2023-08-08 14:03:31 +08:00
< code src = "./demo/component-token.tsx" debug > Component Token< / code >
2024-04-07 19:14:56 +08:00
< code src = "./demo/linear-gradient.tsx" > Gradient Button< / code >
2022-11-09 12:28:04 +08:00
2016-04-22 14:52:19 +08:00
## API
2023-08-08 18:27:48 +08:00
Common props ref: [Common props](/docs/react/common-props)
2020-08-07 15:50:53 +08:00
Different button styles can be generated by setting Button properties. The recommended order is: `type` -> `shape` -> `size` -> `loading` -> `disabled` .
2016-04-22 14:52:19 +08:00
2019-07-11 14:14:33 +08:00
| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
2024-04-11 15:29:10 +08:00
| autoInsertSpace | We add a space between two Chinese characters by default, which can be removed by setting `autoInsertSpace` to `false` . | boolean | `true` | 5.17.0 |
2020-08-07 15:50:53 +08:00
| block | Option to fit button width to its parent width | boolean | false | |
2024-02-05 11:45:42 +08:00
| classNames | Semantic DOM class | [Record<SemanticDOM, string> ](#semantic-dom ) | - | 5.4.0 |
2024-09-03 17:39:02 +08:00
| color | Set button color | `default` \| `primary` \| `danger` | - | 5.21.0 |
2020-08-07 15:50:53 +08:00
| danger | Set the danger status of button | boolean | false | |
2020-06-29 21:43:22 +08:00
| disabled | Disabled state of button | boolean | false | |
| ghost | Make background transparent and invert text and border colors | boolean | false | |
| href | Redirect url of link button | string | - | |
| htmlType | Set the original html `type` of `button` , see: [MDN ](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-type ) | string | `button` | |
| icon | Set the icon component of button | ReactNode | - | |
2024-04-07 22:42:20 +08:00
| iconPosition | Set the icon position of button | `start` \| `end` | `start` | 5.17.0 |
2020-06-29 21:43:22 +08:00
| loading | Set the loading status of button | boolean \| { delay: number } | false | |
2023-02-01 10:11:53 +08:00
| shape | Can be set button shape | `default` \| `circle` \| `round` | `default` | |
2020-10-21 23:17:08 +08:00
| size | Set the size of button | `large` \| `middle` \| `small` | `middle` | |
2024-02-05 11:45:42 +08:00
| styles | Semantic DOM style | [Record<SemanticDOM, CSSProperties> ](#semantic-dom ) | - | 5.4.0 |
2020-06-29 21:43:22 +08:00
| target | Same as target attribute of a, works when href is specified | string | - | |
2023-07-14 17:05:59 +08:00
| type | Set button type | `primary` \| `dashed` \| `link` \| `text` \| `default` | `default` | |
2024-04-11 15:29:10 +08:00
| onClick | Set the handler to handle `click` event | (event: React.MouseEvent< HTMLElement , MouseEvent > ) => void | - | |
2024-09-03 17:39:02 +08:00
| variant | Set button variant | `outlined` \| `dashed` \| `solid` \| `filled` \| `text` \| `link` | - | 5.21.0 |
2016-04-22 14:52:19 +08:00
2019-10-25 09:56:30 +08:00
It accepts all props which native buttons support.
2018-10-28 20:57:23 +08:00
2024-02-05 11:45:42 +08:00
## Semantic DOM
2023-04-11 11:37:31 +08:00
2024-02-05 11:45:42 +08:00
< code src = "./demo/_semantic.tsx" simplify = "true" > < / code >
2023-04-11 11:37:31 +08:00
2023-03-12 14:13:03 +08:00
## Design Token
< ComponentTokenTable component = "Button" > < / ComponentTokenTable >
2019-01-10 11:47:11 +08:00
## FAQ
2024-09-03 17:39:02 +08:00
### How to choose type and color & variant?
Type is essentially syntactic sugar for colors and variants. It internally provides a set of mapping relationships between colors and variants for the type. If both exist at the same time, the type will be used first.
```jsx
< Button type = "primary" > click< / Button >
```
Equivalent
```jsx
< Button color = "primary" variant = "solid" >
click
< / Button >
```
2024-03-26 18:20:28 +08:00
### How to close the click wave effect?
If you don't need this feature, you can set `disabled` of `wave` in [ConfigProvider ](/components/config-provider#api ) as `true` .
```jsx
< ConfigProvider wave = {{ disabled: true } } >
< Button > click< / Button >
< / ConfigProvider >
```
2016-04-22 14:52:19 +08:00
< style >
2022-11-17 13:20:58 +08:00
.site-button-ghost-wrapper {
padding: 16px;
background: rgb(190, 200, 200);
2020-04-27 21:40:52 +08:00
}
2016-04-22 14:52:19 +08:00
< / style >