2016-04-20 18:51:31 +08:00
---
category: Components
2016-11-09 14:43:32 +08:00
type: General
2016-04-22 14:52:19 +08:00
title: Button
2020-05-31 11:48:34 +08:00
cover: https://gw.alipayobjects.com/zos/antfincdn/qZWIjVIkQ7/Button.svg
2016-04-20 18:51:31 +08:00
---
2016-04-22 14:52:19 +08:00
To trigger an operation.
2016-05-25 09:43:26 +08:00
## When To Use
2016-04-22 14:52:19 +08:00
2016-11-29 17:13:24 +08:00
A button means an operation (or a series of operations). Clicking a button will trigger corresponding business logic.
2016-04-22 14:52:19 +08:00
2020-01-03 15:30:05 +08:00
In Ant Design we provide 4 types of button.
2020-01-03 15:22:16 +08:00
- Primary button: indicate the main action, one primary button at most in one section.
- Default button: indicate a series of actions without priority.
- Dashed button: used for adding action commonly.
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.
2020-01-03 15:30:05 +08:00
- `disabled` : when actions is not available.
- `loading` : add loading spinner in button, avoiding multiple submits too.
2020-01-03 15:22:16 +08:00
2016-04-22 14:52:19 +08:00
## API
To get a customized button, just set `type` /`shape`/`size`/`loading`/`disabled`.
2019-07-11 14:14:33 +08:00
| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
2019-11-21 10:16:58 +08:00
| disabled | disabled state of button | boolean | `false` | |
| ghost | make background transparent and invert text and border colors | boolean | `false` | |
2019-07-11 14:14:33 +08:00
| 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` | |
2019-08-13 14:07:17 +08:00
| icon | set the icon component of button | ReactNode | - | |
2019-07-11 14:14:33 +08:00
| loading | set the loading status of button | boolean \| { delay: number } | `false` | |
| shape | can be set to `circle` , `round` or omitted | string | - | |
2020-03-01 18:24:59 +08:00
| size | set the size of button | `large` \| `middle` \| `small` | | |
2019-07-11 14:14:33 +08:00
| target | same as target attribute of a, works when href is specified | string | - | |
2020-05-06 10:15:33 +08:00
| type | can be set to `primary` `ghost` `dashed` `danger` `link` `text` or omitted (meaning `default` ) | string | `default` | |
2019-07-11 14:14:33 +08:00
| onClick | set the handler to handle `click` event | (event) => void | - | |
2019-11-21 10:16:58 +08:00
| block | option to fit button width to its parent width | boolean | `false` | |
2019-11-22 15:32:11 +08:00
| danger | set the danger status of button | boolean | `false` | |
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
2019-01-10 11:47:11 +08:00
## FAQ
2019-10-25 09:56:30 +08:00
### How to remove space between 2 chinese characters
2019-06-21 00:28:33 +08:00
2019-10-25 09:56:30 +08:00
Following the Ant Design specification, we will add one space between if Button contains two Chinese characters only. If you don't need that, you can use [ConfigProvider ](/components/config-provider/#API ) to set `autoInsertSpaceInButton` as `false` .
2019-01-10 11:47:11 +08:00
2020-02-29 16:15:43 +08:00
< img src = "https://gw.alipayobjects.com/zos/antfincdn/MY%26THAPZrW/38f06cb9-293a-4b42-b183-9f443e79ffea.png" style = "box-shadow: none; margin: 0; width: 100px" alt = "Button with two Chinese characters" / >
2016-04-22 14:52:19 +08:00
< style >
2016-12-09 13:02:16 +08:00
[id^=components-button-demo-] .ant-btn {
2016-04-22 14:52:19 +08:00
margin-right: 8px;
margin-bottom: 12px;
}
2020-04-27 21:40:52 +08:00
[id^="components-button-demo-"] .ant-btn-rtl {
margin-right: 0;
margin-left: 8px;
}
2018-02-08 15:51:53 +08:00
[id^=components-button-demo-] .ant-btn-group > .ant-btn,
[id^=components-button-demo-] .ant-btn-group > span > .ant-btn {
2016-12-02 15:06:59 +08:00
margin-right: 0;
}
2019-12-23 16:36:40 +08:00
[data-theme="dark"] .site-button-ghost-wrapper {
2020-01-03 19:00:01 +08:00
background: rgba(255, 255, 255, 0.2);
2019-12-23 16:36:40 +08:00
}
2016-04-22 14:52:19 +08:00
< / style >