# 徽章 (/zh/components/badge)

<!-- agent-signals: reading_time_min: 4 · est_tokens: 2635 · updated: 2026-07-30 -->
Related: [折叠面板](/zh/components/accordions.md), [横幅](/zh/components/banner.md), [标注框](/zh/components/callouts.md), [卡片](/zh/components/cards.md), [代码分组](/zh/components/code-groups.md), [颜色](/zh/components/color.md)

使用徽章显示状态指示器、标签或 metadata。将徽章内嵌于文本中，或作为独立元素使用。

<div id="basic-badge">
  ## 基本徽章 [#基本徽章]
</div>

<Badge>
  徽章
</Badge>

```mdx
<Badge>徽章</Badge>
```

<div id="colors">
  ## 颜色 [#颜色]
</div>

徽章支持多种颜色变体，用于表达不同含义。

<Badge color="gray">
  徽章
</Badge>

<Badge color="blue">
  徽章
</Badge>

<Badge color="green">
  徽章
</Badge>

<Badge color="yellow">
  徽章
</Badge>

<Badge color="orange">
  徽章
</Badge>

<Badge color="red">
  徽章
</Badge>

<Badge color="purple">
  徽章
</Badge>

<Badge color="white">
  徽章
</Badge>

<Badge color="surface">
  徽章
</Badge>

<Badge color="white-destructive">
  徽章
</Badge>

<Badge color="surface-destructive">
  徽章
</Badge>

```mdx
<徽章 color="gray">徽章</徽章>
<徽章 color="blue">徽章</徽章>
<徽章 color="green">徽章</徽章>
<徽章 color="yellow">徽章</徽章>
<徽章 color="orange">徽章</徽章>
<徽章 color="red">徽章</徽章>
<徽章 color="purple">徽章</徽章>
<徽章 color="white">徽章</徽章>
<徽章 color="surface">徽章</徽章>
<徽章 color="white-destructive">徽章</徽章>
<徽章 color="surface-destructive">徽章</徽章>
```

<div id="sizes">
  ## 尺寸 [#尺寸]
</div>

徽章提供四种尺寸，以匹配你的内容层级。

<Badge size="xs">
  徽章
</Badge>

<Badge size="sm">
  徽章
</Badge>

<Badge size="md">
  徽章
</Badge>

<Badge size="lg">
  徽章
</Badge>

```mdx
<徽章 size="xs">徽章</徽章>
<徽章 size="sm">徽章</徽章>
<徽章 size="md">徽章</徽章>
<徽章 size="lg">徽章</徽章>
```

<div id="shapes">
  ## 形状 [#形状]
</div>

可选择圆角或胶囊形徽章。

<Badge shape="rounded">
  徽章
</Badge>

<Badge shape="pill">
  徽章
</Badge>

```mdx
<徽章 shape="rounded">徽章</徽章>
<徽章 shape="pill">徽章</徽章>
```

<div id="icons">
  ## 图标 [#图标]
</div>

为徽章添加图标，以提供更多上下文信息。

<Badge icon="<svg xmlns=&#x22;http://www.w3.org/2000/svg&#x22; viewBox=&#x22;0 0 24 24&#x22; fill=&#x22;none&#x22;><path d=&#x22;M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22Z&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/><path d=&#x22;M8 12.5L10 14.5L15.5 9.5&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/></svg>" color="green">
  徽章
</Badge>

<Badge icon="<svg xmlns=&#x22;http://www.w3.org/2000/svg&#x22; viewBox=&#x22;0 0 24 24&#x22; fill=&#x22;none&#x22;><circle cx=&#x22;12&#x22; cy=&#x22;12&#x22; r=&#x22;10&#x22; stroke=&#x22;currentColor&#x22; stroke-width=&#x22;1.5&#x22;/><path d=&#x22;M12 8V12L14 14&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/></svg>" color="orange">
  徽章
</Badge>

<Badge icon="<svg xmlns=&#x22;http://www.w3.org/2000/svg&#x22; viewBox=&#x22;0 0 24 24&#x22; fill=&#x22;none&#x22;><path d=&#x22;M12 21C16.9706 21 21 16.9706 21 12C21 7.02944 16.9706 3 12 3C7.02944 3 3 7.02944 3 12C3 16.9706 7.02944 21 12 21Z&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/><path d=&#x22;M6 6L18 18&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/></svg>" color="red">
  徽章
</Badge>

```mdx
<徽章 icon="circle-check" color="green">徽章</徽章>
<徽章 icon="clock" color="orange">徽章</徽章>
<徽章 icon="ban" color="red">徽章</徽章>
```

<div id="stroke-variant">
  ## 线框样式 [#线框样式]
</div>

使用线框样式，以获得更为低调的外观。

<Badge color="blue">
  标记
</Badge>

<Badge color="green">
  标记
</Badge>

<Badge color="orange">
  标记
</Badge>

<Badge color="red">
  标记
</Badge>

```mdx
<徽章 stroke color="blue">徽章</徽章>
<徽章 stroke color="green">徽章</徽章>
<徽章 stroke color="orange">徽章</徽章>
<徽章 stroke color="red">徽章</徽章>
```

<div id="disabled-state">
  ## 禁用状态 [#禁用状态]
</div>

将徽章设置为禁用，以表示处于非活动或不可用状态。

<Badge icon="<svg xmlns=&#x22;http://www.w3.org/2000/svg&#x22; viewBox=&#x22;0 0 24 24&#x22; fill=&#x22;none&#x22;><path d=&#x22;M22 12C22 17.5228 17.5228 22 12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12Z&#x22; stroke=&#x22;currentColor&#x22; stroke-width=&#x22;1.5&#x22;/><path d=&#x22;M12 13C13.1046 13 14 12.1046 14 11C14 9.89543 13.1046 9 12 9C10.8954 9 10 9.89543 10 11C10 12.1046 10.8954 13 12 13ZM12 13L12 16&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/></svg>" color="gray">
  徽章
</Badge>

<Badge icon="<svg xmlns=&#x22;http://www.w3.org/2000/svg&#x22; viewBox=&#x22;0 0 24 24&#x22; fill=&#x22;none&#x22;><path d=&#x22;M22 12C22 17.5228 17.5228 22 12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12Z&#x22; stroke=&#x22;currentColor&#x22; stroke-width=&#x22;1.5&#x22;/><path d=&#x22;M12 13C13.1046 13 14 12.1046 14 11C14 9.89543 13.1046 9 12 9C10.8954 9 10 9.89543 10 11C10 12.1046 10.8954 13 12 13ZM12 13L12 16&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/></svg>" color="blue">
  徽章
</Badge>

```mdx
<徽章 disabled icon="lock" color="gray">徽章</徽章>
<徽章 disabled icon="lock" color="blue">徽章</徽章>
```

<div id="inline-usage">
  ## 内联用法 [#内联用法]
</div>

徽章可以自然地嵌入文本内容中。比如，此功能需要 <Badge color="orange" size="sm">Premium</Badge> 订阅，或者此 API 端点返回 <Badge color="green" size="sm">JSON</Badge> 格式。

```mdx
此功能需要<Badge color="orange" size="sm">高级版</Badge>订阅。
```

<div id="combined-properties">
  ## 组合属性 [#组合属性]
</div>

组合多个属性来自定义徽章样式。

<Badge icon="<svg xmlns=&#x22;http://www.w3.org/2000/svg&#x22; viewBox=&#x22;0 0 24 24&#x22; fill=&#x22;none&#x22;><path d=&#x22;M13.7276 3.44418L15.4874 6.99288C15.7274 7.48687 16.3673 7.9607 16.9073 8.05143L20.0969 8.58575C22.1367 8.92853 22.6167 10.4206 21.1468 11.8925L18.6671 14.3927C18.2471 14.8161 18.0172 15.6327 18.1471 16.2175L18.8571 19.3125C19.417 21.7623 18.1271 22.71 15.9774 21.4296L12.9877 19.6452C12.4478 19.3226 11.5579 19.3226 11.0079 19.6452L8.01827 21.4296C5.8785 22.71 4.57865 21.7522 5.13859 19.3125L5.84851 16.2175C5.97849 15.6327 5.74852 14.8161 5.32856 14.3927L2.84884 11.8925C1.389 10.4206 1.85895 8.92853 3.89872 8.58575L7.08837 8.05143C7.61831 7.9607 8.25824 7.48687 8.49821 6.99288L10.258 3.44418C11.2179 1.51861 12.7777 1.51861 13.7276 3.44418Z&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/></svg>" color="blue" size="lg" shape="pill">
  高级
</Badge>

<Badge icon="<svg xmlns=&#x22;http://www.w3.org/2000/svg&#x22; viewBox=&#x22;0 0 24 24&#x22; fill=&#x22;none&#x22;><path d=&#x22;M5 13.2592L7.58583 15.9568C8.2525 16.6523 8.58583 17.0001 9.00004 17.0001C9.41425 17.0001 9.74759 16.6523 10.4143 15.9568L19 7.00006&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/></svg>" color="green" size="sm">
  已验证
</Badge>

<Badge icon="<svg xmlns=&#x22;http://www.w3.org/2000/svg&#x22; viewBox=&#x22;0 0 24 24&#x22; fill=&#x22;none&#x22;><path d=&#x22;M14.3942 3.00083L14.1481 2.79115C12.9103 1.73628 11.0897 1.73628 9.85189 2.79115L9.60584 3.00083C8.96518 3.54679 8.16862 3.87674 7.32956 3.9437L7.00731 3.96941C5.38613 4.09878 4.09878 5.38613 3.96941 7.00731L3.9437 7.32956C3.87674 8.16862 3.54679 8.96518 3.00083 9.60584L2.79115 9.85189C1.73628 11.0897 1.73628 12.9103 2.79115 14.1481L3.00083 14.3942C3.54679 15.0348 3.87674 15.8314 3.9437 16.6704L3.96941 16.9927C4.09878 18.6139 5.38613 19.9012 7.00731 20.0306L7.32956 20.0563C8.16862 20.1233 8.96518 20.4532 9.60584 20.9992L9.85188 21.2089C11.0897 22.2637 12.9103 22.2637 14.1481 21.2089L14.3942 20.9992C15.0348 20.4532 15.8314 20.1233 16.6704 20.0563L16.9927 20.0306C18.6139 19.9012 19.9012 18.6139 20.0306 16.9927L20.0563 16.6704C20.1233 15.8314 20.4532 15.0348 20.9992 14.3942L21.2089 14.1481C22.2637 12.9103 22.2637 11.0897 21.2089 9.85188L20.9992 9.60584C20.4532 8.96518 20.1233 8.16862 20.0563 7.32956L20.0306 7.00731C19.9012 5.38613 18.6139 4.09878 16.9927 3.96941L16.6704 3.9437C15.8314 3.87674 15.0348 3.54679 14.3942 3.00083Z&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/><path d=&#x22;M12 8V12&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/><path d=&#x22;M12.125 15.75H12M12.25 15.75C12.25 15.8881 12.1381 16 12 16C11.8619 16 11.75 15.8881 11.75 15.75C11.75 15.6119 11.8619 15.5 12 15.5C12.1381 15.5 12.25 15.6119 12.25 15.75Z&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/></svg>" color="orange" shape="rounded">
  测试版
</Badge>

```mdx
<Badge icon="star" color="blue" size="lg" shape="pill">高级版</Badge>
<Badge icon="check" stroke color="green" size="sm">已验证</Badge>
<Badge icon="badge-alert" color="orange" shape="rounded">测试版</Badge>
```

<div id="properties">
  ## 属性 [#属性]
</div>

<ResponseField name="color" type="string" default="gray">
  徽章的颜色变体。

  选项：`gray`、`blue`、`green`、`yellow`、`orange`、`red`、
  `purple`、`white`、`surface`、`white-destructive`、`surface-destructive`。
</ResponseField>

<ResponseField name="size" type="string" default="md">
  徽章的尺寸。

  选项：`xs`、`sm`、`md`、`lg`。
</ResponseField>

<ResponseField name="shape" type="string" default="rounded">
  徽章的形状。

  选项：`rounded`、`pill`。
</ResponseField>

<ResponseField name="icon" type="string">
  要显示的图标。

  可选值：

  * [Font Awesome](https://fontawesome.com/icons) 图标名称 (如果你在 `docs.json` 中将 `icons.library` [属性](/zh/organize/settings#param-icons) 设置为 `fontawesome`)
  * [Lucide](https://lucide.dev/icons) 图标名称 (如果你在 `docs.json` 中将 `icons.library` [属性](/zh/organize/settings#param-icons) 设置为 `lucide`)
  * [Tabler](https://tabler.io/icons) 图标名称 (如果你在 `docs.json` 中将 `icons.library` [属性](/zh/organize/settings#param-icons) 设置为 `tabler`)
  * 指向外部托管图标的 URL
  * 项目中图标文件的路径
  * 用花括号包裹的 SVG 代码

  对于自定义 SVG 图标：

  1. 使用 [SVGR 转换器](https://react-svgr.com/playground/) 转换你的 SVG。
  2. 将 SVG 代码粘贴到 SVG 输入框。
  3. 从 JSX 输出框中复制完整的 `<svg>...</svg>` 元素。
  4. 用花括号包裹可用于 JSX 的 SVG 代码：`icon={<svg ...> ... </svg>}`。
  5. 根据需要调整 `height` 和 `width`。
</ResponseField>

<ResponseField name="iconType" type="string">
  [Font Awesome](https://fontawesome.com/icons) 的图标样式。仅在使用 Font Awesome 图标时生效。

  可选值：`regular`、`solid`、`light`、`thin`、`sharp-solid`、`duotone`、`brands`。
</ResponseField>

<ResponseField name="stroke" type="boolean" default="false">
  以描边而非实心背景的样式显示徽章。
</ResponseField>

<ResponseField name="disabled" type="boolean" default="false">
  以禁用状态显示徽章，降低不透明度。
</ResponseField>

<ResponseField name="className" type="string">
  应用于徽章的其他 CSS 类名。
</ResponseField>
