Button
To trigger an operation.
When To Use
A button means an operation (or a series of operations). Clicking a button will trigger its corresponding business logic.
In Ant Design we provide 5 types of button.
- 🔵 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.
- 😶 Dashed button: commonly used for adding more actions.
- 🔤 Text button: used for the most secondary action.
- 🔗 Link button: used for external links.
And 4 other properties additionally.
- 🔴
danger: used for actions of risk, like deletion or authorization. - 👻
ghost: used in situations with complex background, home pages usually. - 🚫
disabled: used when actions are not available. - 🔃
loading: adds a loading spinner in button, avoids multiple submits too.
Examples
-
Syntactic sugar ·
basic -
Color & Variant ·
color-variant -
Icon ·
icon -
Icon Placement ·
icon-placement -
Size ·
size -
Disabled ·
disabled -
Loading ·
loading -
Multiple Buttons ·
multiple -
Ghost Button ·
ghost -
Danger Buttons ·
danger -
Block Button ·
block -
Gradient Button ·
linear-gradient -
Custom Wave ·
wave -
Custom disabled backgroundColor ·
custom-disabled-bg -
Custom semantic dom styling ·
style-class
API
Common props ref:Common props
Different button styles generated by setting Button properties. The recommended order is: type -> shape -> size -> loading -> disabled.
| Property | Description | Type | Default | Version | Global Config |
|---|---|---|---|---|---|
| autoInsertSpace | We add a space between two Chinese characters by default, which removed by setting autoInsertSpace to false. | boolean | true | 5.17.0 | 5.17.0 |
| block | Option to fit button width to its parent width | boolean | false | × | |
| classNames | Customize class for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string> | - | 6.0.0 | 6.0.0 |
| color | Set button color | default | primary | danger | PresetColors | primary when variant="solid" | default, primary and danger: 5.21.0, PresetColors: 5.23.0, solid default color: 6.4.0 | 5.25.0 |
| danger | Syntactic sugar. Set the danger status of button. will follow color if provided | boolean | false | × | |
| 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 | submit | reset | button | button | × | |
| icon | Set the icon component of button | ReactNode | - | × | |
| iconPlacement | Set the icon position of button | start | end | start | - | × |
Set the icon position of button, please use iconPlacement instead | start | end | start | 5.17.0 | × | |
| loading | Set the loading status of button | boolean | { delay: number, icon: ReactNode } | false | icon: 5.23.0 | × |
| loadingIcon | (Only supports global configuration) Set the loading icon of button | ReactNode | <LoadingOutlined /> | 6.3.0 | |
| onClick | Set the handler to handle click event | (event: React.MouseEvent<HTMLElement, MouseEvent>) => void | - | × | |
| shape | Can be used to set button shape | default | circle | round | default | 5.27.0 | |
| size | Set the size of button | large | medium | small | medium | × | |
| styles | Customize inline style for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties> | - | 6.0.0 | 6.0.0 |
| target | Same as target attribute of a, works when href is specified | string | - | × | |
| type | Syntactic sugar. Set button type. Will follow variant & color if provided | primary | dashed | link | text | default | default | × | |
| variant | Set button variant | outlined | dashed | solid | filled | text | link | - | 5.21.0 | 5.25.0 |
It accepts all props which native buttons support.
PresetColors
type PresetColors = 'blue' | 'purple' | 'cyan' | 'green' | 'magenta' | 'pink' | 'red' | 'orange' | 'yellow' | 'volcano' | 'geekblue' | 'lime' | 'gold';
Semantic DOM
| Semantic node | Native description | Version |
|---|---|---|
root | Root element with comprehensive button styling including border, background, padding, border-radius, box-shadow, transitions, cursor, font-weight, alignment, and layout properties | 6.0.0 |
icon | Icon element with font-size, color inheritance, and SVG style reset for proper icon display | 5.5.0 |
content | Content element that wraps button text with typography styles including nowrap, text-align center, and Chinese character spacing optimization | 6.0.0 |
Semantic description source: vendor/components/button/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.
| Token | Type | Native description |
|---|---|---|
fontWeight | CSSProperties['fontWeight'] | Font weight of text |
iconGap | CSSProperties['gap'] | Gap between icon and text |
defaultShadow | string | Shadow of default button |
primaryShadow | string | Shadow of primary button |
dangerShadow | string | Shadow of danger button |
primaryColor | string | Text color of primary button |
defaultColor | string | Text color of default button |
defaultBg | string | Background color of default button |
defaultBorderColor | string | Border color of default button |
dangerColor | string | Text color of danger button |
defaultHoverBg | string | Background color of default button when hover |
defaultHoverColor | string | Text color of default button when hover |
defaultHoverBorderColor | string | Border color of default button |
defaultActiveBg | string | Background color of default button when active |
defaultActiveColor | string | Text color of default button when active |
defaultActiveBorderColor | string | Border color of default button when active |
borderColorDisabled | string | Border color of disabled button |
defaultGhostColor | string | Text color of default ghost button |
ghostBg | string | Background color of ghost button |
defaultGhostBorderColor | string | Border color of default ghost button |
solidTextColor | string | Default text color for solid buttons. |
textTextColor | string | Default text color for text buttons |
textTextHoverColor | string | Default text color for text buttons on hover |
textTextActiveColor | string | Default text color for text buttons on active |
paddingInline | CSSProperties['paddingInline'] | Horizontal padding of button |
paddingInlineLG | CSSProperties['paddingInline'] | Horizontal padding of large button |
paddingInlineSM | CSSProperties['paddingInline'] | Horizontal padding of small button |
paddingBlock | CSSProperties['paddingBlock'] | Vertical padding of button |
paddingBlockLG | CSSProperties['paddingBlock'] | Vertical padding of large button |
paddingBlockSM | CSSProperties['paddingBlock'] | Vertical padding of small button |
onlyIconSize | number | string | Icon size of button which only contains icon |
onlyIconSizeLG | number | string | Icon size of large button which only contains icon |
onlyIconSizeSM | number | string | Icon size of small button which only contains icon |
linkHoverBg | string | Background color of link button when hover |
textHoverBg | string | Background color of text button when hover |
contentFontSize | number | Font size of button content |
contentFontSizeLG | number | Font size of large button content |
contentFontSizeSM | number | Font size of small button content |
contentLineHeight | number | Line height of button content |
contentLineHeightLG | number | Line height of large button content |
contentLineHeightSM | number | Line height of small button content |
defaultBgDisabled | string | See native declaration and inherited types |
dashedBgDisabled | string | See native declaration and inherited types |
Declaration source: vendor/components/button/style/token.ts
import type { CSSProperties } from 'react';
import type { CSSObject } from '@ant-design/cssinjs';
import { unit } from '@ant-design/cssinjs';
import { AggregationColor } from '../../color-picker/color';
import { isBright } from '../../color-picker/components/ColorPresets';
import { PresetColors } from '../../theme/interface';
import type { FullToken, GenStyleFn, GetDefaultToken, PresetColorKey } from '../../theme/internal';
import { getLineHeight, mergeToken } from '../../theme/internal';
import getAlphaColor from '../../theme/util/getAlphaColor';
/** Component only token. Which will handle additional calculation of alias token */
export interface ComponentToken {
/**
* @desc 文字字重
* @descEN Font weight of text
*/
fontWeight: CSSProperties['fontWeight'];
/**
* @desc 图标文字间距
* @descEN Gap between icon and text
*/
iconGap: CSSProperties['gap'];
/**
* @desc 默认按钮阴影
* @descEN Shadow of default button
*/
defaultShadow: string;
/**
* @desc 主要按钮阴影
* @descEN Shadow of primary button
*/
primaryShadow: string;
/**
* @desc 危险按钮阴影
* @descEN Shadow of danger button
*/
dangerShadow: string;
/**
* @desc 主要按钮文本颜色
* @descEN Text color of primary button
*/
primaryColor: string;
/**
* @desc 默认按钮文本颜色
* @descEN Text color of default button
*/
defaultColor: string;
/**
* @desc 默认按钮背景色
* @descEN Background color of default button
*/
defaultBg: string;
/**
* @desc 默认按钮边框颜色
* @descEN Border color of default button
*/
defaultBorderColor: string;
/**
* @desc 危险按钮文本颜色
* @descEN Text color of danger button
*/
dangerColor: string;
/**
* @desc 默认按钮悬浮态背景色
* @descEN Background color of default button when hover
*/
defaultHoverBg: string;
/**
* @desc 默认按钮悬浮态文本颜色
* @descEN Text color of default button when hover
*/
defaultHoverColor: string;
/**
* @desc 默认按钮悬浮态边框颜色
* @descEN Border color of default button
*/
defaultHoverBorderColor: string;
/**
* @desc 默认按钮激活态背景色
* @descEN Background color of default button when active
*/
defaultActiveBg: string;
/**
* @desc 默认按钮激活态文字颜色
* @descEN Text color of default button when active
*/
defaultActiveColor: string;
/**
* @desc 默认按钮激活态边框颜色
* @descEN Border color of default button when active
*/
defaultActiveBorderColor: string;
/**
* @deprecated use `colorBorderDisabled` instead
* @desc 禁用状态边框颜色
* @descEN Border color of disabled button
*/
borderColorDisabled: string;
/**
* @desc 默认幽灵按钮文本颜色
* @descEN Text color of default ghost button
*/
defaultGhostColor: string;
/**
* @desc 幽灵按钮背景色
* @descEN Background color of ghost button
*/
ghostBg: string;
/**
* @desc 默认幽灵按钮边框颜色
* @descEN Border color of default ghost button
*/
defaultGhostBorderColor: string;
/**
* @desc 主要填充按钮的浅色背景颜色
* @descEN Background color of primary filled button
*/
/**
* @desc 默认实心按钮的文本色
* @descEN Default text color for solid buttons.
*/
solidTextColor: string;
/**
* @desc 默认文本按钮的文本色
* @descEN Default text color for text buttons
*/
textTextColor: string;
/**
* @desc 默认文本按钮悬浮态文本颜色
* @descEN Default text color for text buttons on hover
*/
textTextHoverColor: string;
/**
* @desc 默认文本按钮激活态文字颜色
* @descEN Default text color for text buttons on active
*/
textTextActiveColor: string;
/**
* @desc 按钮横向内间距
* @descEN Horizontal padding of button
*/
paddingInline: CSSProperties['paddingInline'];
/**
* @desc 大号按钮横向内间距
* @descEN Horizontal padding of large button
*/
paddingInlineLG: CSSProperties['paddingInline'];
/**
* @desc 小号按钮横向内间距
* @descEN Horizontal padding of small button
*/
paddingInlineSM: CSSProperties['paddingInline'];
/**
* @desc 按钮纵向内间距
* @descEN Vertical padding of button
* @deprecated not used
*/
paddingBlock: CSSProperties['paddingBlock'];
/**
* @desc 大号按钮纵向内间距
* @descEN Vertical padding of large button
* @deprecated not used
*/
paddingBlockLG: CSSProperties['paddingBlock'];
/**
* @desc 小号按钮纵向内间距
* @descEN Vertical padding of small button
* @deprecated not used
*/
paddingBlockSM: CSSProperties['paddingBlock'];
/**
* @desc 只有图标的按钮图标尺寸
* @descEN Icon size of button which only contains icon
*/
onlyIconSize: number | string;
/**
* @desc 大号只有图标的按钮图标尺寸
* @descEN Icon size of large button which only contains icon
*/
onlyIconSizeLG: number | string;
/**
* @desc 小号只有图标的按钮图标尺寸
* @descEN Icon size of small button which only contains icon
*/
onlyIconSizeSM: number | string;
/**
* @desc 链接按钮悬浮态背景色
* @descEN Background color of link button when hover
*/
linkHoverBg: string;
/**
* @desc 文本按钮悬浮态背景色
* @descEN Background color of text button when hover
*/
textHoverBg: string;
/**
* @desc 按钮内容字体大小
* @descEN Font size of button content
*/
contentFontSize: number;
/**
* @desc 大号按钮内容字体大小
* @descEN Font size of large button content
*/
contentFontSizeLG: number;
/**
* @desc 小号按钮内容字体大小
* @descEN Font size of small button content
*/
contentFontSizeSM: number;
/**
* @desc 按钮内容字体行高
* @descEN Line height of button content
* @deprecated not used
*/
contentLineHeight: number;
/**
* @desc 大号按钮内容字体行高
* @descEN Line height of large button content
* @deprecated not used
*/
contentLineHeightLG: number;
/**
* @desc 小号按钮内容字体行高
* @descEN Line height of small button content
* @deprecated not used
*/
contentLineHeightSM: number;
/**
* @desc type='default' 禁用状态下的背景颜色
* @descE background color when type='default' is disabled
*/
defaultBgDisabled: string;
/**
* @desc type='dashed' 禁用状态下的背景颜色
* @descE background color when type='dashed' is disabled
*/
dashedBgDisabled: string;
}
type ShadowColorMap = {
/**
* @desc 预设按钮的阴影色
* @descEN Shadow colors of preset button
*/
[Key in `${PresetColorKey}ShadowColor`]: string;
};
type PresetColorHoverActiveMap = {
[Key in `${PresetColorKey}Hover` | `${PresetColorKey}Active`]: string;
};
type GroupToken = {
/**
* @desc 按钮组边框颜色
* @descEN Border color of button group
* @internal Button.Group 已废弃相关token不应该在显示在文档上
*/
groupBorderColor: string;
};
export interface ButtonToken
extends FullToken<'Button'>,
ShadowColorMap,
PresetColorHoverActiveMap,
GroupToken {
/**
* @desc 按钮横向内边距
* @descEN Horizontal padding of button
*/
buttonPaddingHorizontal: CSSProperties['paddingInline'];
/**
* @desc 按钮纵向内边距
* @descEN Vertical padding of button
*/
buttonPaddingVertical: CSSProperties['paddingBlock'];
/**
* @desc 只有图标的按钮图标尺寸
* @descEN Icon size of button which only contains icon
*/
buttonIconOnlyFontSize: number | string;
}
FAQ
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 colors and variants will be used first.
<Button type="primary">click</Button>
Equivalent
<Button color="primary" variant="solid">
click
</Button>
How to close the click wave effect?
If you don't need this feature, you can set disabled of wave in ConfigProvider as true.
<ConfigProvider wave={{ disabled: true }}>
<Button>click</Button>
</ConfigProvider>
Design Guide
Shared native props
Tips: The following generic properties apply to most antd components; those not supported are described separately.
| Property | Description | Type | Default |
|---|---|---|---|
| style | The additional style | CSSProperties | - |
| className | The additional css class | string | - |
| rootClassName | ClassName on the root element | string | - |
| autoFocus | Auto focus when component mounted, only effective for focusable elements like forms, links, etc. | boolean | false |
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/button/Button.tsxvendor/components/button/ButtonGroup.tsxvendor/components/button/DefaultLoadingIcon.tsxvendor/components/button/IconWrapper.tsxvendor/components/button/buttonHelpers.tsxvendor/components/button/style/token.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.