JGuang

Badge

Badge · Ant Design

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

Badge

Small numerical value or status descriptor for UI elements.

When To Use

Badge normally appears in proximity to notifications or user avatars with eye-catching appeal, typically displaying unread messages count.

Examples

  • Basic · basic
  • Standalone · no-wrapper
  • Overflow Count · overflow
  • Red badge · dot
  • Dynamic · change
  • Clickable · link
  • Offset · offset
  • Size · size
  • Status · status
  • Colorful Badge · colorful
  • Ribbon · ribbon
  • Custom semantic dom styling · style-class

API

Common props ref:Common props

Badge

PropertyDescriptionTypeDefaultVersionGlobal Config
colorCustomize Badge dot colorstring-×
countNumber to show in badgeReactNode-×
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-5.7.0
dotWhether to display a red dot instead of countbooleanfalse×
offsetSet offset of the badge dot[number, number]-×
overflowCountMax count to shownumber99×
showZeroWhether to show badge when count is zerobooleanfalse×
sizeIf count is set, size sets the size of badgemedium | small--×
statusSet Badge as a status dotsuccess | processing | default | error | warning-×
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-5.7.0
textIf status is set, text sets the display text of the status dotReactNode-×
titleText to show when hovering over the badge. Set to null or false to remove the native tooltipstring | null | false-6.5.0×

Badge.Ribbon

PropertyDescriptionTypeDefaultVersionGlobal Config
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-6.0.0
colorCustomize Ribbon colorstring-×
placementThe placement of the Ribbon, start and end follow text direction (RTL or LTR)start | endend×
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-6.0.0
textContent inside the RibbonReactNode-×

Semantic DOM

Badge

Semantic nodeNative descriptionVersion
rootRoot element with relative positioning, inline-block display, and fit-content width for basic layout5.7.0
indicatorIndicator element with positioning, z-index, dimensions, colors, fonts, text alignment, background, border-radius, box-shadow, and transition animations for complete badge styling5.7.0

Semantic description source: vendor/components/badge/demo/_semantic.tsx

Badge.Ribbon

Semantic nodeNative descriptionVersion
rootRoot element, set relative positioning and wrapper container styles6.0.0
indicatorIndicator element, set absolute positioning, padding, background color, border radius and ribbon styles6.0.0
contentContent element, set text color and ribbon content display styles6.0.0

Semantic description source: vendor/components/badge/demo/_semantic_ribbon.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
indicatorZIndexnumber | stringz-index of badge
indicatorHeightnumber | stringHeight of badge
indicatorHeightSMnumber | stringHeight of small badge
dotSizenumberSize of dot badge
textFontSizenumberFont size of badge text
textFontSizeSMnumberFont size of small badge text
textFontWeightnumber | stringFont weight of badge text
statusSizenumberSize of status badge
paddingInlinenumber | stringInline padding of multiple words badge

Declaration source: vendor/components/badge/style/index.ts

import type { CSSObject } from '@ant-design/cssinjs';

import { Keyframes, unit } from '@ant-design/cssinjs';

import { resetComponent } from '../../style';

import type { FullToken, GenerateStyle, GenStyleFn, GetDefaultToken } from '../../theme/internal';

import { genPresetColor, genStyleHooks, mergeToken } from '../../theme/internal';

/** Component only token. Which will handle additional calculation of alias token */
export interface ComponentToken {
  // Component token here
  /**
   * @desc 徽标 z-index
   * @descEN z-index of badge
   */
  indicatorZIndex: number | string;
  /**
   * @desc 徽标高度
   * @descEN Height of badge
   */
  indicatorHeight: number | string;
  /**
   * @desc 小号徽标高度
   * @descEN Height of small badge
   */
  indicatorHeightSM: number | string;
  /**
   * @desc 点状徽标尺寸
   * @descEN Size of dot badge
   */
  dotSize: number;
  /**
   * @desc 徽标文本尺寸
   * @descEN Font size of badge text
   */
  textFontSize: number;
  /**
   * @desc 小号徽标文本尺寸
   * @descEN Font size of small badge text
   */
  textFontSizeSM: number;
  /**
   * @desc 徽标文本粗细
   * @descEN Font weight of badge text
   */
  textFontWeight: number | string;
  /**
   * @desc 状态徽标尺寸
   * @descEN Size of status badge
   */
  statusSize: number;
  /**
   * @desc 多字符徽标水平内边距
   * @descEN Inline padding of multiple words badge
   */
  paddingInline: number | string;
}

/**
 * @desc Badge 组件的 Token
 * @descEN Token for Badge component
 */
export interface BadgeToken extends FullToken<'Badge'> {
  /**
   * @desc 徽标字体高度
   * @descEN Font height of badge
   */
  badgeFontHeight: number;
  /**
   * @desc 徽标文本颜色
   * @descEN Text color of badge
   */
  badgeTextColor: string;
  /**
   * @desc 徽标颜色
   * @descEN Color of badge
   */
  badgeColor: string;
  /**
   * @desc 徽标悬停颜色
   * @descEN Hover color of badge
   */
  badgeColorHover: string;
  /**
   * @desc 徽标阴影尺寸
   * @descEN Shadow size of badge
   */
  badgeShadowSize: number;
  /**
   * @desc 徽标阴影颜色
   * @descEN Shadow color of badge
   */
  badgeShadowColor: string;
  /**
   * @desc 徽标处理持续时间
   * @descEN Processing duration of badge
   */
  badgeProcessingDuration: string;
  /**
   * @desc 徽标丝带偏移量
   * @descEN Ribbon offset of badge
   */
  badgeRibbonOffset: number;
  /**
   * @desc 徽标丝带角变换
   * @descEN Ribbon corner transform of badge
   */
  badgeRibbonCornerTransform: string;
  /**
   * @desc 徽标丝带角滤镜
   * @descEN Ribbon corner filter of badge
   */
  badgeRibbonCornerFilter: string;
}

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/badge/Badge.tsx
  • vendor/components/badge/Ribbon.tsx
  • vendor/components/badge/ScrollNumber.tsx
  • vendor/components/badge/SingleNumber.tsx
  • vendor/components/badge/index.tsx
  • vendor/components/badge/style/index.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.