JGuang

Tag

Tag · Ant Design

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

Tag

Used for marking and categorization.

When To Use

  • It can be used to tag by dimension or property.

  • When categorizing.

Examples

  • Basic · basic

  • Colorful Tag · colorful

  • Add & Remove Dynamically · control

  • Checkable · checkable

  • Animate · animation

  • Icon · icon

  • Status Tag · status

  • Draggable Tag · draggable

  • Custom semantic dom styling · style-class

API

Common props ref:Common props

Tag

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
closeIconCustom close icon. 5.7.0: close button will be hidden when setting to null or falseReactNodefalse4.4.05.14.0
colorColor of the Tagstringdefault when variant="solid"solid default color: 6.4.0×
disabledWhether the tag is disabledbooleanfalse6.0.0×
hrefThe address to jump when clicking, when this property is specified, the tag component will be rendered as an <a> tagstring-6.0.0×
iconSet the icon of tagReactNode-×
onCloseCallback executed when tag is closed (can be prevented by e.preventDefault())(e: React.MouseEvent<HTMLElement, MouseEvent>) => void-×
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
targetSame as target attribute of a, works when href is specifiedstring-6.0.0×
variantVariant of the tag'filled' | 'solid' | 'outlined''filled'6.0.06.0.0
borderedWhether has border style, please use variant="filled" insteadbooleantrue-×

Tag.CheckableTag

PropertyDescriptionTypeDefaultVersion
checkedChecked status of Tagbooleanfalse
iconSet the icon of tagReactNode-5.27.0
onChangeCallback executed when Tag is checked/unchecked(checked) => void-

Tag.CheckableTagGroup

PropertyDescriptionTypeDefaultVersion
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string>-
defaultValueInitial valuestring | number | Array<string | number> | null-
disabledDisable check/uncheckboolean-
multipleMultiple select modeboolean-
optionsOption list. Object options support per-item className and style.Array<{ className?: string; label: ReactNode; style?: CSSProperties; value: string | number } | string | number>-className and style: 6.4.0
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties>-
valueValue of checked tag(s)string | number | Array<string | number> | null-
onChangeCallback when Tag is checked/unchecked(value: string | number | Array<string | number> | null) => void-

Semantic DOM

Tag

Semantic nodeNative descriptionVersion
rootRoot element with inline-block display, auto height, padding, font size, line height, nowrap, background color, border, border radius, opacity, transition animations, text alignment, relative positioning and other basic tag styles6.0.0
iconIcon element with font size, color, cursor style, transition animations and other icon display styles6.0.0
contentContent element with text content color, font styles and other content area styles6.0.0
closeClose element with close button layout, cursor styles, transition animations and other interaction styles6.4.0

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

Tag.CheckableTagGroup

Semantic nodeNative descriptionVersion
rootRoot element with tag group container styles and layout—
itemTag item element with inline-block display, height, padding, font size, line height, background color, border, border radius, opacity, transition animation, checkable state and other styles—

Semantic description source: vendor/components/tag/demo/_semantic_group.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
defaultBgstringDefault background color
defaultColorstringDefault text color
solidTextColorstringDefault text color for solid tag.

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

import type React from 'react';

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

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

import { FastColor } from '@ant-design/fast-color';

import { AggregationColor } from '../../color-picker/color';

import { isBright } from '../../color-picker/components/ColorPresets';

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

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

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

export interface ComponentToken {
  /**
   * @desc 默认背景色
   * @descEN Default background color
   */
  defaultBg: string;
  /**
   * @desc 默认文字颜色
   * @descEN Default text color
   */
  defaultColor: string;

  /**
   * @desc 默认实心标签的文本色
   * @descEN Default text color for solid tag.
   */
  solidTextColor: string;
}

export interface TagToken extends FullToken<'Tag'> {
  tagFontSize: number;
  tagLineHeight: React.CSSProperties['lineHeight'];
  tagIconSize: number | string;
  tagPaddingHorizontal: number;
  tagBorderlessBg: 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/tag/CheckableTag.tsx
  • vendor/components/tag/CheckableTagGroup.tsx
  • vendor/components/tag/index.tsx
  • vendor/components/tag/style/index.ts
  • vendor/components/tag/style/statusCmp.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.