2016-04-20 18:51:31 +08:00
---
category: Components
2016-04-22 14:52:19 +08:00
title: Button
2022-11-30 20:14:41 +08:00
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*BrFMQ5s7AAQAAAAAAAAAAAAADrJ8AQ/original
2023-02-09 22:17:31 +08:00
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*Lp1kTYmSsgoAAAAAAAAAAAAADrJ8AQ/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-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-07-21 10:07:38 +08:00
In Ant Design we provide 5 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-10-02 13:15:41 +08:00
- `disabled` : when actions are not available.
2020-01-03 15:30:05 +08:00
- `loading` : add loading spinner in button, avoiding 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 >
< code src = "./demo/icon.tsx" > Icon< / 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 >
2016-04-22 14:52:19 +08:00
## API
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 |
| --- | --- | --- | --- | --- |
2020-08-07 15:50:53 +08:00
| block | Option to fit button width to its parent width | boolean | false | |
| 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 | - | |
| 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` | |
2020-06-29 21:43:22 +08:00
| target | Same as target attribute of a, works when href is specified | string | - | |
2020-09-17 23:06:55 +08:00
| type | Can be set to `primary` `ghost` `dashed` `link` `text` `default` | string | `default` | |
2022-12-15 17:48:29 +08:00
| onClick | Set the handler to handle `click` event | (event: MouseEvent) => void | - | |
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
2023-03-12 14:13:03 +08:00
## Design Token
< ComponentTokenTable component = "Button" > < / ComponentTokenTable >
2019-01-10 11:47:11 +08:00
## FAQ
2020-08-07 15:50:53 +08:00
### How to remove space between 2 chinese characters?
2019-06-21 00:28:33 +08:00
2022-12-22 14:12:26 +08:00
Following the Ant Design specification, we will add one space between if Button (exclude Text button and Link 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 >
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 >