---
title: Chip 标签
description: 用于显示标签、状态与分类的小型信息徽章
component: chip
group: 组件
---
## 用法
```vue
```
## 组件结构
> 纯文本子节点会自动包裹在 `` 中。
```vue
Label text
```
显式使用部件或组合内容时不会重复包装:
```vue
标签
```
## 示例
### 变体
### 状态类型
### 带图标
## 自定义样式
### Tailwind CSS
### 全局 CSS
可使用 `@layer components` 指令自定义 Chip 组件类。
```css
@layer components {
.hv-chip {
@apply rounded-full text-xs;
}
.hv-chip__label {
@apply font-medium;
}
.hv-chip--accent {
@apply border-accent/20;
}
.hv-chip--accent .hv-chip__label {
@apply text-accent;
}
}
```
## 样式参考
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
### CSS 类
Chip 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/chip.css)):
#### 基础类 [!toc]
- `.hv-chip` - 基础标签容器样式
- `.hv-chip__label` - 标签文本 slot 样式
#### 颜色类 [!toc]
- `.hv-chip--accent` - 强调色变体
- `.hv-chip--danger` - 危险色变体
- `.hv-chip--default` - 默认色变体
- `.hv-chip--success` - 成功色变体
- `.hv-chip--warning` - 警告色变体
#### 变体类 [!toc]
- `.hv-chip--primary` - 填充背景的主变体
- `.hv-chip--secondary` - 带边框的次变体
- `.hv-chip--tertiary` - 透明背景的三级变体
- `.hv-chip--soft` - 浅色背景的 soft 变体
#### 尺寸类 [!toc]
- `.hv-chip--sm` - 小尺寸
- `.hv-chip--md` - 中尺寸(默认)
- `.hv-chip--lg` - 大尺寸
#### 复合变体类 [!toc]
Chip 支持组合变体与颜色类(如 `.hv-chip--secondary.hv-chip--accent`)。以下组合有默认样式:
**Primary Variants:**
- `.hv-chip--primary.hv-chip--accent` - 填充背景的 primary accent 组合
- `.hv-chip--primary.hv-chip--success` - 填充背景的 primary success 组合
- `.hv-chip--primary.hv-chip--warning` - 填充背景的 primary warning 组合
- `.hv-chip--primary.hv-chip--danger` - 填充背景的 primary danger 组合
**Soft Variants:**
- `.hv-chip--accent.hv-chip--soft` - 浅色背景的 soft accent 组合
- `.hv-chip--success.hv-chip--soft` - 浅色背景的 soft success 组合
- `.hv-chip--warning.hv-chip--soft` - 浅色背景的 soft warning 组合
- `.hv-chip--danger.hv-chip--soft` - 浅色背景的 soft danger 组合
**Note:** 可使用 CSS 中的 `@layer components` 指令为任意变体-颜色组合(如 `.hv-chip--secondary.hv-chip--accent`、`.hv-chip--tertiary.hv-chip--success`)应用自定义样式。
## API 参考
### Chip
| Prop | 类型 | 默认值 | 描述 |
| --------- | ------------------------------------------------------------- | ------------- | --------------------------------------------------- |
| `color` | `'default' \| 'accent' \| 'success' \| 'warning' \| 'danger'` | `'default'` | 标签颜色变体 |
| `variant` | `'primary' \| 'secondary' \| 'tertiary' \| 'soft'` | `'secondary'` | 视觉样式变体 |
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | 标签尺寸 |
| 默认插槽 | `Component` | - | 标签内显示的内容;纯文本/数字自动包装为 `ChipLabel` |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
### ChipLabel
| Prop | 类型 | 默认值 | 描述 |
| -------- | --------------------------- | ------ | ----------------------------- |
| 默认插槽 | `Component` | - | 标签文本内容 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
`class` 遵循 Vue 的 class 绑定,可接收字符串、数组和对象,并与组件或 slot 基础类合并;不要使用 React 的 `className`。
纯文本或数字默认插槽会在渲染时包装为 `ChipLabel`;显式 `ChipLabel` 或图标等组合内容不会重复包装。文本与组合内容之间动态切换时会按当前插槽重新判断。
## 相关组件
[Avatar 头像](./avatar) · [CloseButton 关闭按钮](./close-button) · [Separator 分隔符](./separator)