Chip
A compact pill for filters that toggle, tags that can be removed, small actions and statuses.
Usage
A Chip is a tonal pill a small control tall. What it is depends on what you give it: plain, it
is a label; with selected, a toggle; with onclick, a button; with href, a link.
1 of 4 transaction types shown.
EUR GBP JPY USD
Settled Pending Declined Scheduled
Filters
Bind selected and the chip becomes a toggle button that flips it when pressed. A selected
chip is filled and shows a check, so the state does not rely on colour alone.
<script>
import { Chip } from 'sveltier';
let card = $state(true);
let transfer = $state(false);
</script>
<Chip bind:selected={card}>Card</Chip>
<Chip bind:selected={transfer}>Transfer</Chip>Removable tags
closable adds a close button that calls onclose. Name it for what it
removes with closeLabel. A chip that is itself a button or a link cannot also be
closable, since one control would sit inside another; put the action in a Button next to it.
<script>
import { Chip } from 'sveltier';
let currencies = $state(['EUR', 'GBP', 'USD']);
</script>
{#each currencies as currency (currency)}
<Chip
closable
closeLabel="Remove {currency}"
onclose={() => (currencies = currencies.filter((c) => c !== currency))}
>
{currency}
</Chip>
{/each}Accessibility
- A filter chip is a
<button>witharia-pressed, pressed with Enter or Space. - The close button is its own button in the tab order, named by
closeLabel. - A plain chip is text, not a control: it is read but not focused.
API
| Name | Type | Default | Description |
|---|---|---|---|
variant | 'elevated' | 'flat' | 'tonal' | 'outlined' | 'text' | 'plain' | 'tonal' | Visual weight. A selected chip is flat. |
size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'sm' | Height and text size. |
density | 'compact' | 'default' | 'comfortable' | 'default' | Multiplies the height and padding, never the text. |
color | Color | 'neutral' | The colour the variant is painted with. |
rounded | boolean | 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'full' | true | Corner rounding. true keeps the pill. |
disabled | boolean | false | A disabled chip cannot be pressed; a disabled link loses its href. |
selected | boolean | – | Makes the chip a toggle button (aria-pressed) that flips it when pressed: a filter.
Bindable. Shows a check while selected. |
closable | boolean | false | Adds a button that removes the chip by calling onclose. Only for chips that are not
themselves buttons or links. |
closeLabel | string | – | The name of the close button, such as Remove Euro. Defaults to the locale's close. |
onclose | () => void | – | Called by the close button. |
prepend | Snippet | – | Content before the label, usually an icon or an avatar. |
append | Snippet | – | Content after the label. |
children | Snippet | – | The label. |
class | ClassValue | null | – | Classes added after the component's own: a string, an array or an object. |
ref | HTMLSpanElement | HTMLButtonElement | HTMLAnchorElement | null | – | The root element, bindable with bind:ref. |