JGuang

Button

Button · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

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.

PropertyDescriptionTypeDefaultVersionGlobal Config
autoInsertSpaceWe add a space between two Chinese characters by default, which removed by setting autoInsertSpace to false.booleantrue5.17.05.17.0
blockOption to fit button width to its parent widthbooleanfalse×
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-6.0.06.0.0
colorSet button colordefault | primary | danger | PresetColorsprimary when variant="solid"default, primary and danger: 5.21.0, PresetColors: 5.23.0, solid default color: 6.4.05.25.0
dangerSyntactic sugar. Set the danger status of button. will follow color if providedbooleanfalse×
disabledDisabled state of buttonbooleanfalse×
ghostMake background transparent and invert text and border colorsbooleanfalse×
hrefRedirect url of link buttonstring-×
htmlTypeSet the original html type of button, see: MDNsubmit | reset | buttonbutton×
iconSet the icon component of buttonReactNode-×
iconPlacementSet the icon position of buttonstart | endstart-×
iconPositionSet the icon position of button, please use iconPlacement insteadstart | endstart5.17.0×
loadingSet the loading status of buttonboolean | { delay: number, icon: ReactNode }falseicon: 5.23.0×
loadingIcon(Only supports global configuration) Set the loading icon of buttonReactNode<LoadingOutlined />6.3.0
onClickSet the handler to handle click event(event: React.MouseEvent<HTMLElement, MouseEvent>) => void-×
shapeCan be used to set button shapedefault | circle | rounddefault5.27.0
sizeSet the size of buttonlarge | medium | smallmedium×
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-6.0.06.0.0
targetSame as target attribute of a, works when href is specifiedstring-×
typeSyntactic sugar. Set button type. Will follow variant & color if providedprimary | dashed | link | text | defaultdefault×
variantSet button variantoutlined | dashed | solid | filled | text | link-5.21.05.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 nodeNative descriptionVersion
rootRoot element with comprehensive button styling including border, background, padding, border-radius, box-shadow, transitions, cursor, font-weight, alignment, and layout properties6.0.0
iconIcon element with font-size, color inheritance, and SVG style reset for proper icon display5.5.0
contentContent element that wraps button text with typography styles including nowrap, text-align center, and Chinese character spacing optimization6.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.

TokenTypeNative description
fontWeightCSSProperties['fontWeight']Font weight of text
iconGapCSSProperties['gap']Gap between icon and text
defaultShadowstringShadow of default button
primaryShadowstringShadow of primary button
dangerShadowstringShadow of danger button
primaryColorstringText color of primary button
defaultColorstringText color of default button
defaultBgstringBackground color of default button
defaultBorderColorstringBorder color of default button
dangerColorstringText color of danger button
defaultHoverBgstringBackground color of default button when hover
defaultHoverColorstringText color of default button when hover
defaultHoverBorderColorstringBorder color of default button
defaultActiveBgstringBackground color of default button when active
defaultActiveColorstringText color of default button when active
defaultActiveBorderColorstringBorder color of default button when active
borderColorDisabledstringBorder color of disabled button
defaultGhostColorstringText color of default ghost button
ghostBgstringBackground color of ghost button
defaultGhostBorderColorstringBorder color of default ghost button
solidTextColorstringDefault text color for solid buttons.
textTextColorstringDefault text color for text buttons
textTextHoverColorstringDefault text color for text buttons on hover
textTextActiveColorstringDefault text color for text buttons on active
paddingInlineCSSProperties['paddingInline']Horizontal padding of button
paddingInlineLGCSSProperties['paddingInline']Horizontal padding of large button
paddingInlineSMCSSProperties['paddingInline']Horizontal padding of small button
paddingBlockCSSProperties['paddingBlock']Vertical padding of button
paddingBlockLGCSSProperties['paddingBlock']Vertical padding of large button
paddingBlockSMCSSProperties['paddingBlock']Vertical padding of small button
onlyIconSizenumber | stringIcon size of button which only contains icon
onlyIconSizeLGnumber | stringIcon size of large button which only contains icon
onlyIconSizeSMnumber | stringIcon size of small button which only contains icon
linkHoverBgstringBackground color of link button when hover
textHoverBgstringBackground color of text button when hover
contentFontSizenumberFont size of button content
contentFontSizeLGnumberFont size of large button content
contentFontSizeSMnumberFont size of small button content
contentLineHeightnumberLine height of button content
contentLineHeightLGnumberLine height of large button content
contentLineHeightSMnumberLine height of small button content
defaultBgDisabledstringSee native declaration and inherited types
dashedBgDisabledstringSee 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.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

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.tsx
  • vendor/components/button/ButtonGroup.tsx
  • vendor/components/button/DefaultLoadingIcon.tsx
  • vendor/components/button/IconWrapper.tsx
  • vendor/components/button/buttonHelpers.tsx
  • vendor/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.