---
title: Button 按钮
description: 按钮组件——六种变体、三种尺寸、链接或原生按钮。
---

`button()` 构建按钮：`variant` 切换 Solid / Subtle / Surface /
Outline / Ghost / Plain，`size` 切换 sm / md / lg。传入 `href` 时渲染
`<a>`，否则渲染原生 `<button type="button">`。

## 变体

```ts
button({ label: 'Solid', variant: 'solid' });
button({ label: 'Subtle', variant: 'subtle' });
button({ label: 'Surface', variant: 'surface' });
button({ label: 'Outline', variant: 'outline' });
button({ label: 'Ghost', variant: 'ghost' });
button({ label: 'Plain', variant: 'plain' });
```

## 尺寸

```ts
button({ label: '小号', size: 'sm', variant: 'outline' });
button({ label: '中号', size: 'md', variant: 'outline' });
button({ label: '大号', size: 'lg', variant: 'outline' });
```

## 图标

图标渲染在文本前；任意内联 SVG 字符串均可。

```ts
button({
  label: '联系我们',
  variant: 'solid',
  icon: '<svg …>…</svg>', // 任意内联 SVG 字符串
});
```

## 作为链接

传入 `href` 时按钮渲染为 `<a>`；`external` 在新标签页打开。

```ts
button({ label: '开始使用', href: '/guides/example/', variant: 'solid' });
```

## 颜色

`color` 从 Kit 语义色令牌选取色板
（primary / info / success / warning / error / idea）。solid 以该颜色为底、
白色文字。

```ts
button({ label: 'Info', variant: 'solid', color: 'info' });
button({ label: 'Success', variant: 'solid', color: 'success' });
button({ label: 'Warning', variant: 'solid', color: 'warning' });
button({ label: 'Error', variant: 'solid', color: 'error' });
button({ label: 'Idea', variant: 'solid', color: 'idea' });
```

outline 沿用同一色板：

```ts
button({ label: 'Info', variant: 'outline', color: 'info' });
```

## 参数

<PropsTable
  labels={{ prop: '参数', type: '类型', default: '默认值' }}
  type={{
    label: { type: 'string', required: true, description: '按钮文本。' },
    href: { type: 'string', description: '目标地址——渲染 <code>&lt;a&gt;</code> 而非 <code>&lt;button&gt;</code>。' },
    variant: { type: "'solid' | 'subtle' | 'surface' | 'outline' | 'ghost' | 'plain'", default: "'solid'", description: '视觉风格。' },
    size: { type: "'sm' | 'md' | 'lg'", default: "'md'", description: '高度与内边距（2rem / 2.5rem / 3rem）。' },
    color: { type: "'primary' | 'info' | 'success' | 'warning' | 'error' | 'idea'", default: "'primary'", description: '色板，来自 Kit 语义色令牌。' },
    icon: { type: 'string', default: "''", description: '置于文本前的原始 SVG 字符串。' },
    external: { type: 'boolean', default: 'false', description: '配合 <code>href</code>：在新标签页打开链接。' },
    attrs: { type: 'Record<string, string>', description: '附加 HTML 属性（如 <code>data-cpd-drawer-trigger</code>）。' },
  }}
/>

## 注意

- 浅色 hover 压暗、深色 hover 提亮（`color-mix`）；
  focus 显示 2px ring（`--cpd-ring`）；disabled 半透明。
- 圆角 `0.375rem`；字重 600；`line-height: 1`。
