# Carbon Components Svelte
A complete [Svelte](https://github.com/sveltejs/svelte) component library that implements the [IBM Carbon Design System](https://www.carbondesignsystem.com/). Ship accessible, consistent, production-ready interfaces.
- **90+ components** -- from inputs to data tables
- **5 built-in themes** -- two light, three dark
- **Fully typed TypeScript API** -- props, events, and slots
- **WCAG 2.1 AA** -- keyboard and screen-reader ready
## Quick start
Install the library, pick a theme, and render your first component. Three steps to a running app, plus customization options below.
### 1. Install the package
```sh
# npm
npm i carbon-components-svelte
# pnpm
pnpm add carbon-components-svelte
# Yarn
yarn add carbon-components-svelte
# Bun
bun add carbon-components-svelte
```
### 2. Apply a theme stylesheet
Import one precompiled Carbon theme. The Carbon Design System supports five themes (2 light, 3 dark): White, Gray 10, Gray 80, Gray 90, Gray 100.
Import this once at the top-level, like `index.js` or `src/+layout.svelte`.
```javascript
// White theme
import "carbon-components-svelte/css/white.css";
// Gray 10 theme
import "carbon-components-svelte/css/g10.css";
// Gray 80 theme
import "carbon-components-svelte/css/g80.css";
// Gray 90 theme
import "carbon-components-svelte/css/g90.css";
// Gray 100 theme
import "carbon-components-svelte/css/g100.css";
// All themes (for dynamic theming)
import "carbon-components-svelte/css/all.css";
```
### 3. Import a component
```svelte
```
Explore the full [component index](/component-index).
## Dynamic theming
To switch themes at runtime, import the combined `all.css` stylesheet instead of a single theme. It bundles all five themes and toggles between them through a `theme` attribute on the HTML element.
Import the stylesheet once, at the top-level entry point of your app:
```javascript
import "carbon-components-svelte/css/all.css";
```
Then set the theme reactively in Svelte:
```svelte
```
Or statically in your HTML:
```html
```
Or use the [Theme component](/components/Theme) to manage the theme reactively.
## Faster builds, smaller bundles
The fast path is enough to build. [carbon-preprocess-svelte](https://github.com/carbon-design-system/carbon-preprocess-svelte) trims build times and bundle size with two drop-in tools for faster HMR in development and leaner CSS when you ship.
Add carbon-preprocess-svelte as a dev dependency:
```sh
# npm
npm i -D carbon-preprocess-svelte
# pnpm
pnpm add -D carbon-preprocess-svelte
# Yarn
yarn add -D carbon-preprocess-svelte
# Bun
bun add -D carbon-preprocess-svelte
```
### optimizeImports
Rewrites barrel imports to direct source paths, dramatically cutting cold build and HMR times.
### optimizeCss
Tree-shakes unused Carbon CSS at build time, often removing hundreds of kilobytes from production bundles.
### Configure your bundler
Add `optimizeImports` to your Svelte preprocessor and `optimizeCss` to your bundler plugins.
**Vite:**
```javascript
// vite.config.js
import { svelte, vitePreprocess } from "@sveltejs/vite-plugin-svelte";
import { optimizeCss, optimizeImports } from "carbon-preprocess-svelte";
export default {
plugins: [
svelte({
preprocess: [vitePreprocess(), optimizeImports()],
}),
optimizeCss(),
],
};
```
**SvelteKit:**
```javascript
// svelte.config.js
import adapter from "@sveltejs/adapter-static";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
import { optimizeImports } from "carbon-preprocess-svelte";
const config = {
preprocess: [vitePreprocess(), optimizeImports()],
kit: { adapter: adapter() },
};
export default config;
```
```javascript
// vite.config.js
import { sveltekit } from "@sveltejs/kit/vite";
import { optimizeCss } from "carbon-preprocess-svelte";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [sveltekit(), optimizeCss()],
});
```
**Rollup:**
```javascript
// rollup.config.js
import svelte from "rollup-plugin-svelte";
import { optimizeCss, optimizeImports } from "carbon-preprocess-svelte";
const production = !process.env.ROLLUP_WATCH;
export default {
plugins: [
svelte({
preprocess: [optimizeImports()],
}),
production && optimizeCss(),
],
};
```
**Webpack:**
```javascript
// webpack.config.mjs
import { OptimizeCssPlugin, optimizeImports } from "carbon-preprocess-svelte";
export default {
module: {
rules: [
{
test: /\.svelte$/,
use: {
loader: "svelte-loader",
options: {
preprocess: [optimizeImports()],
},
},
},
],
},
plugins: [new OptimizeCssPlugin()],
};
```
## Icons and pictograms
The icon and pictogram sets ship as separate packages of individual Svelte components. Both are professionally designed, original iconography crafted to complement the scale and grid of Carbon components. Each is optional, so install only what you need.
### Icons
2,700+ icons designed for product UI, in four sizes (16, 20, 24, and 32 pixels), set with a single prop.
```sh
# npm
npm i carbon-icons-svelte
# pnpm
pnpm add carbon-icons-svelte
# Yarn
yarn add carbon-icons-svelte
# Bun
bun add carbon-icons-svelte
```
```svelte
```
### Pictograms
1,500+ illustrative pictograms for empty states, onboarding, hero sections, and feature callouts. Larger than icons, 64px by default.
```sh
# npm
npm i carbon-pictograms-svelte
# pnpm
pnpm add carbon-pictograms-svelte
# Yarn
yarn add carbon-pictograms-svelte
# Bun
bun add carbon-pictograms-svelte
```
```svelte
```
## Documentation for LLMs
Documentation is available in LLM-friendly plain text for use with coding assistants, plus a standalone Markdown document for every component. Append `.md` to any component's URL to read it.
- **[llms.txt](/llms.txt)** -- A component index where each entry links to its per-component Markdown doc, sized for model context windows.
- **[llms-full.txt](/llms-full.txt)** -- The full component documentation in a single plain-text file.
## Collection
The Carbon Svelte collection includes packages for icons, pictograms, and data visualization:
- **Carbon Components Svelte** -- 90+ components -- [GitHub](https://github.com/carbon-design-system/carbon-components-svelte)
- **Carbon Icons Svelte** -- 2,700+ icons -- [GitHub](https://github.com/carbon-design-system/carbon-icons-svelte)
- **Carbon Pictograms Svelte** -- 1,500+ pictograms -- [GitHub](https://github.com/carbon-design-system/carbon-pictograms-svelte)
- **Carbon Charts Svelte** -- 25+ charts, powered by d3 -- [GitHub](https://github.com/carbon-design-system/carbon-charts/tree/master/packages/svelte)
- **Carbon Preprocess Svelte** -- Collection of Carbon Svelte preprocessors -- [GitHub](https://github.com/carbon-design-system/carbon-preprocess-svelte)
## Accordion
### Basic
Use the accordion and accordion item components to compose a collapsible list of items.
By default, the chevron icon is on the right side of the accordion item.
```svelte
Natural Language Classifier uses advanced natural language processing and
machine learning techniques to create custom classification models. Users
train their data and the service predicts the appropriate category for the
inputted text.
Analyze text to extract meta-data from content such as concepts, entities,
emotion, relations, sentiment and more.
Translate text, documents, and websites from one language to another.
Create industry or region-specific translations via the service's
customization capability.
```
### Left-aligned chevron
Align the chevron icon to the left side of the accordion item by setting `align` to `"start"`.
```svelte
Natural Language Classifier uses advanced natural language processing and
machine learning techniques to create custom classification models. Users
train their data and the service predicts the appropriate category for the
inputted text.
Analyze text to extract meta-data from content such as concepts, entities,
emotion, relations, sentiment and more.
Translate text, documents, and websites from one language to another.
Create industry or region-specific translations via the service's
customization capability.
```
### Flush
Set `flush` to remove the accordion's gutter, aligning it flush with the edges of its container. This works well in full-bleed layouts and side panels. `flush` has no effect when `align` is `"start"`.
```svelte
Natural Language Classifier uses advanced natural language processing and
machine learning techniques to create custom classification models. Users
train their data and the service predicts the appropriate category for the
inputted text.
Analyze text to extract meta-data from content such as concepts, entities,
emotion, relations, sentiment and more.
Translate text, documents, and websites from one language to another.
Create industry or region-specific translations via the service's
customization capability.
```
### Custom title slot
Customize the title content with the title slot instead of the title prop for more complex layouts with multiple elements.
```svelte
Natural Language Classifier
AI / Machine Learning
Natural Language Classifier uses advanced natural language processing and
machine learning techniques to create custom classification models. Users
train their data and the service predicts the appropriate category for the
inputted text.
Natural Language Understanding
AI / Machine Learning
Analyze text to extract meta-data from content such as concepts, entities,
emotion, relations, sentiment and more.
Language Translator
AI / Machine Learning
Translate text, documents, and websites from one language to another.
Create industry or region-specific translations via the service's
customization capability.
```
### First item open
Set `open` on an item to have it expanded by default when the accordion is first rendered.
```svelte
Natural Language Classifier uses advanced natural language processing and
machine learning techniques to create custom classification models. Users
train their data and the service predicts the appropriate category for the
inputted text.
Analyze text to extract meta-data from content such as concepts, entities,
emotion, relations, sentiment and more.
Translate text, documents, and websites from one language to another.
Create industry or region-specific translations via the service's
customization capability.
```
### Single-open
Set `type` to `"single"` so that opening an item automatically closes any other open item. This is useful for FAQs, step-by-step wizards, or settings panels where only one section should be expanded at a time. The default is `"multiple"`, which allows any number of items to be open simultaneously.
```svelte
Natural Language Classifier uses advanced natural language processing and
machine learning techniques to create custom classification models. Users
train their data and the service predicts the appropriate category for the
inputted text.
Analyze text to extract meta-data from content such as concepts, entities,
emotion, relations, sentiment and more.
Translate text, documents, and websites from one language to another.
Create industry or region-specific translations via the service's
customization capability.
```
### Nested
Put an `Accordion` inside an `AccordionItem` to compose nested clusters. Nested items keep their own open state, independent of the parent.
```svelte
Uses advanced natural language processing and machine learning
techniques to create custom classification models. Users train
their data and the service predicts the appropriate category.
Regionus-south
Analyzes text to extract meta-data from content such as concepts,
entities, emotion, relations, sentiment and more.
Regioneu-de
```
### Programmatic example
Programmatically control the accordion items with the `bind:open` directive, expanding and collapsing items based on user interactions or application state.
```svelte
{#each items as item}
{item.description}
{/each}
```
### Sizes
Set `size` to control row height. The default is `md`.
#### Extra-large
Display the accordion in an extra-large size by setting `size` to `"xl"`.
```svelte
Natural Language Classifier uses advanced natural language processing and
machine learning techniques to create custom classification models. Users
train their data and the service predicts the appropriate category for the
inputted text.
Analyze text to extract meta-data from content such as concepts, entities,
emotion, relations, sentiment and more.
Translate text, documents, and websites from one language to another.
Create industry or region-specific translations via the service's
customization capability.
```
#### Small
Set `size` to `"sm"` for a smaller accordion in compact layouts or when space is limited.
```svelte
Natural Language Classifier uses advanced natural language processing and
machine learning techniques to create custom classification models. Users
train their data and the service predicts the appropriate category for the
inputted text.
Analyze text to extract meta-data from content such as concepts, entities,
emotion, relations, sentiment and more.
Translate text, documents, and websites from one language to another.
Create industry or region-specific translations via the service's
customization capability.
```
### Disabled
Disable the whole accordion or individual items.
#### All
Set `disabled` on the accordion to disable all items at once. Users can no longer expand or collapse any item.
```svelte
Natural Language Classifier uses advanced natural language processing and
machine learning techniques to create custom classification models. Users
train their data and the service predicts the appropriate category for the
inputted text.
Analyze text to extract meta-data from content such as concepts, entities,
emotion, relations, sentiment and more.
Translate text, documents, and websites from one language to another.
Create industry or region-specific translations via the service's
customization capability.
```
#### Batch
Programmatically toggle the disabled state of all accordion items. In this example, disabling all items also collapses them.
```svelte
{#each items as item}
{item.description}
{/each}
```
#### Item
Disable an individual item by setting `disabled` on a specific accordion item for finer control over which items are interactive.
```svelte
Natural Language Classifier uses advanced natural language processing and
machine learning techniques to create custom classification models. Users
train their data and the service predicts the appropriate category for the
inputted text.
Analyze text to extract meta-data from content such as concepts, entities,
emotion, relations, sentiment and more.
Translate text, documents, and websites from one language to another.
Create industry or region-specific translations via the service's
customization capability.
```
### Skeleton
Set `skeleton` to show a loading placeholder while content loads.
```svelte
```
#### Left-aligned chevron
Combine skeleton state with left-aligned chevron by enabling `skeleton` and setting `align` to `"start"`.
```svelte
```
#### Custom count
By default, the skeleton state displays 4 items. Set `count` to specify the number of skeleton items to display.
```svelte
```
#### Closed
By default, the first skeleton item is open. Set `open={false}` to render the skeleton collapsed.
```svelte
```
#### Extra-large
Set `size` to `"xl"` for an extra-large skeleton.
```svelte
```
#### Small
Set `size` to `"sm"` for a small skeleton.
```svelte
```
#### Flush
Set `flush` to remove the skeleton's gutter, matching the flush variant.
```svelte
```
### Lazy loading
Set `lazy` on an accordion item to defer mounting its panel content until the item first opens. Use it for panels with heavy content, such as API-fetched data or charts, so they mount only when needed. The content stays mounted after the item collapses.
```svelte
Natural Language Classifier uses advanced natural language processing and
machine learning techniques to create custom classification models. Users
train their data and the service predicts the appropriate category for the
inputted text.
Analyze text to extract meta-data from content such as concepts, entities,
emotion, relations, sentiment and more.
Translate text, documents, and websites from one language to another.
Create industry or region-specific translations via the service's
customization capability.
```
---
### Component API
#### `Accordion` props
| Prop | Type | Description | Default |
| --- | --- | --- | --- |
| `align` | `"start" \| "end"` | Specify alignment of accordion item chevron icon. | `"end"` |
| `size` | `"sm" \| "xl"` | Specify the size of the accordion. | _undefined_ |
| `flush` | `boolean` | Set to `true` to remove the gutter around the accordion, aligning it flush with its container. Has no effect when `align` is `"start"`. | `false` |
| `disabled` | `boolean` | Set to `true` to disable the accordion | `false` |
| `skeleton` | `boolean` | Set to `true` to display the skeleton state | `false` |
| `type` | `"single" \| "multiple"` | Specify the expansion behavior of the accordion. Set to `"single"` so that opening an item closes all other items. | `"multiple"` |
#### `Accordion` slots
| Slot | Detail |
| --------- | ----------------------- |
| `default` | `Record` |
#### `Accordion` forwarded events
| Event |
| --------------- |
| `on:click` |
| `on:mouseenter` |
| `on:mouseleave` |
| `on:mouseover` |
#### `Accordion` $$restProps
`Accordion` spreads `$$restProps` to the `AccordionSkeleton` component.
#### `AccordionItem` props
| Prop | Type | Description | Default |
| --- | --- | --- | --- |
| `open` (Reactive) | `boolean` | Set to `true` to open the first accordion item. | `false` |
| `disabled` (Reactive) | `boolean` | Set to `true` to disable the accordion item. | `false` |
| `ref` (Reactive) | `null \| HTMLButtonElement` | Obtain a reference to the heading button HTML element. | `null` |
| `title` | `string` | Specify the title of the accordion item heading. Alternatively, use the "title" slot. | `"title"` |
| `ariaLabel` | `string` | Specify a custom label for the accordion button. This is important for accessibility when the accordion has no visible title. | _undefined_ |
| `lazy` | `boolean` | Set to `true` to defer mounting the panel content until the item is first opened. Once mounted, the content stays mounted for subsequent collapses. | `false` |
#### `AccordionItem` slots
| Slot | Detail |
| --------- | ----------------------- |
| `default` | `Record` |
| `title` | `Record` |
#### `AccordionItem` forwarded events
| Event |
| ----------------- |
| `on:animationend` |
| `on:click` |
| `on:keydown` |
| `on:mouseenter` |
| `on:mouseleave` |
| `on:mouseover` |
#### `AccordionItem` $$restProps
`AccordionItem` spreads `$$restProps` to the `li` element.
#### `AccordionSkeleton` props
| Prop | Type | Description | Default |
| --- | --- | --- | --- |
| `count` | `number` | Specify the number of accordion items to render | `4` |
| `align` | `"start" \| "end"` | Specify alignment of accordion item chevron icon. | `"end"` |
| `size` | `"sm" \| "xl"` | Specify the size of the accordion. | _undefined_ |
| `flush` | `boolean` | Set to `true` to remove the gutter around the accordion, aligning it flush with its container. Has no effect when `align` is `"start"`. | `false` |
| `open` | `boolean` | Set to `false` to close the first accordion item | `true` |
#### `AccordionSkeleton` forwarded events
| Event |
| --------------- |
| `on:click` |
| `on:mouseenter` |
| `on:mouseleave` |
| `on:mouseover` |
#### `AccordionSkeleton` $$restProps
`AccordionSkeleton` spreads `$$restProps` to the `ul` element.
## AspectRatio
### Basic
Display a 2:1 aspect ratio container by default.
```svelte
2x1
```
### Ratios
Supported aspect ratios include `2x1`, `2x3`, `16x9`, `4x3`, `1x1`, `3x4`, `3x2`, `9x16`, and `1x2`.
#### 2x3
Display content with a 2:3 aspect ratio.
```svelte
2x3
```
#### 16x9
Display content with a 16:9 aspect ratio.
```svelte
16x9
```
#### 4x3
Display content with a 4:3 aspect ratio.
```svelte
4x3
```
#### 1x1
Display content with a 1:1 (square) aspect ratio.
```svelte
1x1
```
#### 3x4
Display content with a 3:4 aspect ratio.
```svelte
3x4
```
#### 3x2
Display content with a 3:2 aspect ratio.
```svelte
3x2
```
#### 9x16
Display content with a 9:16 aspect ratio.
```svelte
9x16
```
#### 1x2
Display content with a 1:2 aspect ratio.
```svelte
1x2
```
### Tile (16x9)
Wrap a tile or other content in an aspect ratio container to maintain proportions.
```svelte
Content
```
---
### Component API
#### `AspectRatio` props
| Prop | Type | Description | Default |
| --- | --- | --- | --- |
| `ratio` | `"2x1" \| "2x3" \| "16x9" \| "4x3" \| "1x1" \| "3x4" \| "3x2" \| "9x16" \| "1x2"` | Specify the aspect ratio. | `"2x1"` |
#### `AspectRatio` slots
| Slot | Detail |
| --------- | ----------------------- |
| `default` | `Record` |
#### `AspectRatio` $$restProps
`AspectRatio` spreads `$$restProps` to the `div` element.
## BadgeIndicator
### Basic
Omit count to render an empty dot that signals presence without a number.
```svelte
```
### Count
Set count to a number. Values greater than 999 display as 999+.
```svelte
```
### Formatted count
Pass a string to count to override the built-in numeric display. String values bypass the 999+ cap.
```svelte
```
### In UI Shell
Use the [UI Shell](/components/UIShell) for header notifications and other utility indicators.
```svelte
Dashboard
```
---
### Component API
#### `BadgeIndicator` props
| Prop | Type | Description | Default |
| --- | --- | --- | --- |
| `ref` (Reactive) | `null \| HTMLDivElement` | Obtain a reference to the HTML element. | `null` |
| `count` | `number \| string` | Specify the badge count. Omit or set to `0` to render an empty dot. A numeric count greater than `999` displays as "999+". Pass a string to override the displayed value (e.g. `"1.2k"`). | _undefined_ |
#### `BadgeIndicator` $$restProps
`BadgeIndicator` spreads `$$restProps` to the `div` element.
#### `Button` props
| Prop | Type | Description | Default |
| --- | --- | --- | --- |
| `ref` (Reactive) | `null \| HTMLAnchorElement \| HTMLButtonElement` | Obtain a reference to the HTML element. | `null` |
| `kind` | `"primary" \| "secondary" \| "tertiary" \| "ghost" \| "danger" \| "danger-tertiary" \| "danger-ghost"` | Specify the kind of button. | `"primary"` |
| `size` | `"default" \| "field" \| "small" \| "lg" \| "xl"` | Specify the size of button. When the `badge` slot is used, size is set to `lg` per Carbon design guidelines. | `"default"` |
| `expressive` | `boolean` | Set to `true` to use Carbon's expressive typesetting | `false` |
| `isSelected` | `boolean` | Set to `true` to enable the selected state for an icon-only, ghost button. | `false` |
| `icon` | `Icon` | Specify the icon to render. Alternatively, use the named slot "icon". | _undefined_ |
| `iconDescription` | `string` | Specify the ARIA label for the button icon. On an icon-only button, this also drives Carbon's tooltip. If omitted, the icon-only button renders without a tooltip; supply your own `aria-label` or `aria-labelledby` for accessibility in that case. | _undefined_ |
| `tooltipAlignment` | `"start" \| "center" \| "end"` | Set the alignment of the tooltip relative to the icon. Only applies to icon-only buttons. | `"center"` |
| `tooltipPosition` | `"top" \| "right" \| "bottom" \| "left"` | Set the position of the tooltip relative to the icon. | `"bottom"` |
| `hideTooltip` | `boolean` | Set to `true` to hide the tooltip while maintaining accessibility. Only applies to icon-only buttons. When `true`, the tooltip is visually hidden but the `iconDescription` remains accessible to screen readers. | `false` |
| `as` | `boolean` | Set to `true` to render a custom HTML element. Props are destructured as `props` in the default slot. | `false` |
| `skeleton` | `boolean` | Set to `true` to display the skeleton state | `false` |
| `disabled` | `boolean` | Set to `true` to disable the button | `false` |
| `href` | `string` | Set the `href` to use an anchor link. | _undefined_ |
| `tabindex` | `number \| string \| undefined` | Specify the tabindex | `"0"` |
| `type` | `string` | Specify the `type` attribute for the button element | `"button"` |
| `portalTooltip` | `boolean \| undefined` | Set to `true` to render the icon-only tooltip in a portal, preventing it from being clipped by `overflow: hidden` containers and enabling auto-flipping when the preferred direction lacks space. By default, the tooltip is portalled when inside a `Modal`. | _undefined_ |
#### `Button` slots
| Slot | Detail |
| --- | --- |
| `default` | `{ props: { role: "button"; type?: string; tabindex: any; disabled: boolean; href?: string; class: string; [key: string]: any; }; }` |
| `badge` | `Record` |
| `icon` | `{ style: undefined \| string; }` |
#### `Button` forwarded events
| Event |
| --------------- |
| `on:blur` |
| `on:click` |
| `on:focus` |
| `on:mousedown` |
| `on:mouseenter` |
| `on:mouseleave` |
| `on:mouseover` |
#### `Button` $$restProps
`Button` spreads `$$restProps` to the `button | a | div` element.
#### `HeaderGlobalAction` props
| Prop | Type | Description | Default |
| --- | --- | --- | --- |
| `ref` (Reactive) | `HTMLButtonElement` | Obtain a reference to the HTML button element. | `null` |
| `isActive` | `boolean` | Set to `true` to use the active variant | `false` |
| `icon` | `Icon` | Specify the icon to render. | _undefined_ |
#### `HeaderGlobalAction` slots
| Slot | Detail |
| ------- | ----------------------- |
| `badge` | `Record` |
#### `HeaderGlobalAction` forwarded events
| Event |
| ---------- |
| `on:click` |
#### `HeaderGlobalAction` $$restProps
`HeaderGlobalAction` spreads `$$restProps` to the `Button` component.
## Box
### Basic
The default component renders a `
` with no modifiers.
```svelte
Content inside a box.
```
### Tokens
Apply Carbon fill, inset, and border tokens.
#### Fill
Set `fill` to a Carbon background token. Tokens use v11 names and resolve through the active theme.
| Token | Description |
| ------------ | -------------------------- |
| `background` | Default page background |
| `layer-01` | First layer surface |
| `layer-02` | Second layer surface |
| `layer-03` | Third layer surface |
| `field` | Form field background |
| `inverse` | Inverse surface background |
```svelte
backgroundlayer-01layer-02layer-03
```
Nested fills stack Carbon layer surfaces. Contrast depends on the active theme: on white, layer-02 matches the page background, so pair a darker outer fill with border to show depth.
```svelte
layer-03 inside layer-01.
```
#### Inset
Set inset and margin props using the shared layout scale 1-13 (same values as [Stack](/components/Stack) gap). Pass a string for any CSS length.
| Scale | Size |
| ----- | -------------- |
| 1 | 0.125rem (2px) |
| 2 | 0.25rem (4px) |
| 3 | 0.5rem (8px) |
| 4 | 0.75rem (12px) |
| 5 | 1rem (16px) |
| 6 | 1.5rem (24px) |
| 7 | 2rem (32px) |
| 8 | 2.5rem (40px) |
| 9 | 3rem (48px) |
| 10 | 4rem (64px) |
| 11 | 5rem (80px) |
| 12 | 6rem (96px) |
| 13 | 10rem (160px) |
```svelte
Scale padding (5)Custom padding (`2rem`)Axis paddingVertical margin
```
#### Border
Set `border` to a Carbon border token. Each utility applies `1px solid`.
| Token | Description |
| ------------- | -------------------------- |
| `subtle` | Subtle divider border |
| `strong` | Strong divider border |
| `interactive` | Interactive element border |
| `disabled` | Disabled element border |
```svelte
subtlestronginteractive
```
### Width
Set width, maxWidth, or minWidth to any CSS length. Numbers are treated as pixels. Use `fullWidth` to span the container (`width: 100%`).
```svelte
Max width in rem (`20rem`).
Max width in pixels (`480`).
```
```svelte
Full width up to a custom max width.
```
### Composition
```svelte
API keys
API keys authenticate programmatic access to your workspace. Store secrets
in IBM Cloud Secrets Manager and rotate them on a schedule your security
team defines.
```
### Utility classes
Apply Box utilities directly when you do not need the component. Classes use the `bx--` prefix.
| Class | Description |
| ---------------------------- | ----------------------------- |
| `bx--box-fill-background` | Default page background |
| `bx--box-fill-layer-01` | First layer surface |
| `bx--box-fill-layer-02` | Second layer surface |
| `bx--box-fill-layer-03` | Third layer surface |
| `bx--box-fill-field` | Form field background |
| `bx--box-fill-inverse` | Inverse surface background |
| `bx--box-border-subtle` | Subtle 1px border |
| `bx--box-border-strong` | Strong 1px border |
| `bx--box-border-interactive` | Interactive 1px border |
| `bx--box-border-disabled` | Disabled 1px border |
| `bx--box-p-{1-13}` | Padding on all sides |
| `bx--box-px-{1-13}` | Horizontal padding |
| `bx--box-py-{1-13}` | Vertical padding |
| `bx--box-m-{1-13}` | Margin on all sides |
| `bx--box-mx-{1-13}` | Horizontal margin |
| `bx--box-my-{1-13}` | Vertical margin |
| `bx--box-full-width` | Span the full container width |
```svelte
Styled with utility classes
```
---
### Component API
#### `Box` props
| Prop | Type | Description | Default |
| --- | --- | --- | --- |
| `fill` | `"background" \| "layer-01" \| "layer-02" \| "layer-03" \| "field" \| "inverse"` | Set the background fill using a Carbon theme token. | _undefined_ |
| `padding` | `SpacingValue \| undefined` | Set padding on all sides. Numbers `1`-`13` use the shared layout scale; strings accept any CSS length. | _undefined_ |
| `paddingX` | `SpacingValue \| undefined` | Set horizontal padding. Numbers `1`-`13` use the shared layout scale; strings accept any CSS length. | _undefined_ |
| `paddingY` | `SpacingValue \| undefined` | Set vertical padding. Numbers `1`-`13` use the shared layout scale; strings accept any CSS length. | _undefined_ |
| `margin` | `SpacingValue \| undefined` | Set margin on all sides. Numbers `1`-`13` use the shared layout scale; strings accept any CSS length. | _undefined_ |
| `marginX` | `SpacingValue \| undefined` | Set horizontal margin. Numbers `1`-`13` use the shared layout scale; strings accept any CSS length. | _undefined_ |
| `marginY` | `SpacingValue \| undefined` | Set vertical margin. Numbers `1`-`13` use the shared layout scale; strings accept any CSS length. | _undefined_ |
| `border` | `"subtle" \| "strong" \| "interactive" \| "disabled"` | Set the border using a Carbon border token. | _undefined_ |
| `width` | `number \| string \| undefined` | Set the width. Numbers are treated as pixels; strings accept any CSS length. | _undefined_ |
| `maxWidth` | `number \| string \| undefined` | Set the max width. Numbers are treated as pixels; strings accept any CSS length. | _undefined_ |
| `minWidth` | `number \| string \| undefined` | Set the min width. Numbers are treated as pixels; strings accept any CSS length. | _undefined_ |
| `fullWidth` | `boolean` | Set to `true` to span the full width of the container | `false` |
| `tag` | `keyof HTMLElementTagNameMap` | Specify the tag name. | `"div"` |
#### `Box` typedefs
```ts
type SpacingScale = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13;
type SpacingValue = SpacingScale | string;
```
#### `Box` slots
| Slot | Detail |
| --------- | ----------------------- |
| `default` | `Record` |
#### `Box` $$restProps
`Box` spreads `$$restProps` to the `any` element.
## Breadcrumb
### Basic
Display a hierarchical navigation trail with slashes between items. Mark the current page with `isCurrentPage`.
```svelte
DashboardAnnual reports2019
```
### No trailing slash
Remove the trailing slash from the last item with `noTrailingSlash`.
```svelte
HomeProfile
```
### Overflow menu
Add an overflow menu to handle long breadcrumb trails. Use overflow menu item components for menu options.
```svelte
HomeAPI documentation
Usage
```
### Small
Use `size="sm"` for a compact breadcrumb. This pairs with an overflow menu when space is tight.
```svelte
HomeAPI
Usage
```
### Breadcrumb trail
Build a full breadcrumb trail with multiple items and a current page indicator.
```svelte
{#each items as item, i}
{item.text}
{/each}
```
### Custom link element
Omit href and use `let:props` to render a custom link element (for example, a router link). Spread props onto the element to apply the Carbon link class and forward aria-current when isCurrentPage is set.
```svelte
DashboardAnnual reports2019
```
### Skeleton
Display a loading state with `skeleton`. Use `count` to specify the number of items.
```svelte
```
#### Small
Use `skeleton` with `size="sm"` for a compact loading state.
```svelte
```
---
### Component API
#### `Breadcrumb` props
| Prop | Type | Description | Default |
| --- | --- | --- | --- |
| `noTrailingSlash` | `boolean` | Set to `true` to hide the breadcrumb trailing slash | `false` |
| `skeleton` | `boolean` | Set to `true` to display skeleton state | `false` |
| `labelText` | `string` | Specify the ARIA label for the nav | `"Breadcrumb"` |
| `size` | `"sm" \| "md"` | Specify the size of the breadcrumb. | `"md"` |
#### `Breadcrumb` slots
| Slot | Detail |
| --------- | ----------------------- |
| `default` | `Record` |
#### `Breadcrumb` forwarded events
| Event |
| --------------- |
| `on:click` |
| `on:mouseenter` |
| `on:mouseleave` |
| `on:mouseover` |
#### `Breadcrumb` $$restProps
`Breadcrumb` spreads `$$restProps` to the `BreadcrumbSkeleton` component.
#### `BreadcrumbItem` props
| Prop | Type | Description | Default |
| --- | --- | --- | --- |
| `href` | `string` | Set the `href` to use an anchor link. | _undefined_ |
| `isCurrentPage` | `boolean` | Set to `true` if the breadcrumb item represents the current page | `false` |
#### `BreadcrumbItem` slots
| Slot | Detail |
| --- | --- |
| `default` | `{ props?: { "aria-current"?: string; class: "bx--link"; }; }` |
#### `BreadcrumbItem` forwarded events
| Event |
| --------------- |
| `on:click` |
| `on:mouseenter` |
| `on:mouseleave` |
| `on:mouseover` |
#### `BreadcrumbItem` $$restProps
`BreadcrumbItem` spreads `$$restProps` to the `li` element.
#### `BreadcrumbSkeleton` props
| Prop | Type | Description | Default |
| --- | --- | --- | --- |
| `noTrailingSlash` | `boolean` | Set to `true` to hide the breadcrumb trailing slash | `false` |
| `count` | `number` | Specify the number of breadcrumb items to render | `3` |
| `size` | `"sm" \| "md"` | Specify the size of the breadcrumb. | `"md"` |
#### `BreadcrumbSkeleton` forwarded events
| Event |
| --------------- |
| `on:click` |
| `on:mouseenter` |
| `on:mouseleave` |
| `on:mouseover` |
#### `BreadcrumbSkeleton` $$restProps
`BreadcrumbSkeleton` spreads `$$restProps` to the `div` element.
## Breakpoint
### Breakpoints
The Carbon Design System [grid implementation](https://carbondesignsystem.com/guidelines/2x-grid/implementation#responsive-options) defines five responsive breakpoints. This utility component uses the [Window.matchMedia API](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia) to declaratively determine the current Carbon breakpoint size.
| Breakpoint | Width range |
| ----------- | ------------------- |
| **Small** | Less than 672px |
| **Medium** | 672px - 1056px |
| **Large** | 1056px - 1312px |
| **X-Large** | 1312px - 1584px |
| **Max** | Greater than 1584px |
### Basic
Bind to `size` to determine the current breakpoint. Possible values include `"sm"`, `"md"`, `"lg"`, `"xlg"`, and `"max"`.
The on:change event fires when the size is initially determined and when a breakpoint change occurs (for example, when the browser is resized).
```svelte
(events = [...events, e.detail])} />
Resize the width of your browser.
Breakpoint size
{size}
on:change
{JSON.stringify(events, null, 2)}
```
### Store and breakpoint values
Use `breakpointObserver` as an alternative to the component to get the current size as a Svelte store. The store provides two additional functions that create derived stores returning a boolean indicating whether the size is smaller or larger than a certain breakpoint.
Access the breakpoints dictionary to map from BreakpointSize to BreakpointValue.
```svelte
Current breakpoint size: {$size}
Current breakpoint value: {breakpoints[$size]}px
Smaller than medium: {$smaller}
Larger than medium: {$larger}
```
### use:hideAtBreakpoint
Use the `hideAtBreakpoint` action to hide an element outside a breakpoint range, without wrapping it in `Breakpoint`. Set `above`, `below`, or both. Resize the browser to see the elements toggle.
```svelte
Hidden at md and up
Hidden below lg
```
---
### Component API
#### `Breakpoint` props
| Prop | Type | Description | Default |
| --- | --- | --- | --- |
| `size` (Reactive) | `BreakpointSize` | Determine the current Carbon grid breakpoint size. | _undefined_ |
| `sizes` (Reactive) | `Record` | Carbon grid sizes as an object. | `{ sm: false, md: false, lg: false, xlg: false, max: false, }` |
#### `Breakpoint` typedefs
```ts
type BreakpointSize = "sm" | "md" | "lg" | "xlg" | "max";
type BreakpointValue = 320 | 672 | 1056 | 1312 | 1584;
```
#### `Breakpoint` slots
| Slot | Detail |
| --- | --- |
| `default` | `{ size: BreakpointSize; sizes: Record< BreakpointSize, boolean >; }` |
#### `Breakpoint` dispatched events
| Event | Detail |
| --- | --- |
| `on:change` | `{ size: BreakpointSize; breakpointValue: BreakpointValue; }` |
## Button
### Kinds
Set the `kind` prop to match the importance of the action.
#### Primary
The default button style is primary. Use it for the main action on a page.
```svelte
```
#### Secondary
Set `kind="secondary"` for secondary actions.
```svelte
```
#### Tertiary
Set `kind="tertiary"` for tertiary actions.
```svelte
```
#### Ghost
Set `kind="ghost"` for ghost-style buttons.
```svelte
```
#### Danger
Set `kind="danger"` for destructive actions.
```svelte
```
#### Danger tertiary
Set `kind="danger-tertiary"` for less prominent destructive actions.
```svelte
```
#### Danger tertiary (icon-only)
Create an icon-only danger tertiary button by omitting the label text and providing an icon description for accessibility.
```svelte
```
#### Danger ghost
Set `kind="danger-ghost"` for ghost-style destructive actions.
```svelte
```
### Icons
Add an icon, or render an icon-only button with a tooltip.
#### With icon
Add an icon to the button using the `icon` prop.
```svelte
```
#### Icon-only
Omit the label and provide an `iconDescription` for accessibility. This text is used as the button's tooltip and screen reader label.
```svelte
```
#### Icon-only without iconDescription
If you omit `iconDescription`, the button renders without Carbon's tooltip instead of an empty one. Supply your own `aria-label` (or `aria-labelledby`) so the button stays accessible.
```svelte
```
#### Icon-only link
Set `href` to create an icon-only link button.
```svelte
```
#### Custom tooltip position
Control the tooltip position and alignment with `tooltipPosition` and `tooltipAlignment`.
```svelte
```
#### Portalled tooltip
Set `portalTooltip` to `true` to render the icon-only tooltip in a portal. This prevents the tooltip from being clipped by `overflow: hidden` containers and auto-flips when the preferred direction lacks viewport space.
By default, the tooltip is portalled only when the button is inside a Modal. Set `portalTooltip={false}` to always use the inline (non-portalled) tooltip.
```svelte
```
#### Hidden tooltip
Set `hideTooltip` to `true` to visually hide the tooltip while maintaining accessibility for screen readers. Use this when tooltips cause layout issues, interfere with interactions, or when multiple icon buttons are densely packed, as in a toolbar. The `iconDescription` remains accessible to screen readers.
```svelte
```
#### Selected (ghost)
Set `isSelected` to `true` to enable the selected state for an icon-only, ghost button.
```svelte