Chip component
The kit:chip component displays small interactive labels, perfect for representing status, categories, filters or actions. Compact, stylable and highly flexible, it can be clicked, disabled, loaded, closed or enriched with snippets.
It supports different variants, states, densities and sizes, to suit all UI contexts. It can be used alone, in groups, or as the basis for a tag or filter system.
<script lang="ts">
const filters = ['All', 'Design', 'Engineering', 'Product', 'Marketing'];
let active = $state('All');
</script>
<div style="display: flex; gap: 0.5rem; flex-wrap: wrap;">
{#each filters as f (f)}
<kit:chip
is="button"
variant={active === f ? 'filled' : 'outline'}
onclick={() => (active = f)}
>
{f}
</kit:chip>
{/each}
</div>
kit:chip renders as a <div> by default. It becomes interactive automatically when onclick is attached, href is set, or is="button". It is a pill by default (rounded="full").
Examples of chip
Variants
Variants adapt the overall appearance of the chip to graphic needs.
filled (default): surface background (
--kit-color-surface-2), or thecolorwith a contrasted text.tonal: light tint of the color, text in the color.
outline: transparent background with a border.
surface: very light tint of the color with a soft border.
text: transparent background, text in the color.
plain: like
text, but hover and pressed only change the text color, never the background.variant:
'filled' | 'tonal' | 'outline' | 'surface' | 'text' | 'plain'='filled'
The border thickness of outline and surface is set by the global variable --kit-outline-weight (1px by default).
<div style="display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;">
{#each ['filled', 'tonal', 'outline', 'surface', 'text', 'plain'] as variant (variant)}
<kit:chip {variant} color="accent">{variant}</kit:chip>
{/each}
</div>
size
With size, adjust the chip’s height, padding, font size and the gap between the icon and the text. From compact tags to larger status indicators, this prop allows you to create chips that fit perfectly into different contexts.
- size:
'xs' | 'sm' | 'md' | 'lg' | 'xl'='md'
| size | height | font size |
|---|---|---|
xs | 1.25rem (20px) | 0.6875rem (11px) |
sm | 1.5rem (24px) | 0.75rem (12px) |
md | 2rem (32px) | --kit-font-xs (13px) |
lg | 2.25rem (36px) | --kit-font-sm (14px) |
xl | 2.5rem (40px) | --kit-font-md (15px) |
The sizes are in rem: the chip grows with the font size set in the browser. The values in px are for the default size (16px).
<div style="display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;">
{#each ['xs', 'sm', 'md', 'lg', 'xl'] as size (size)}
<kit:chip variant="outline" {size}>{size}</kit:chip>
{/each}
</div>
Density
density adjusts the height and the horizontal padding, from -4px (dense) to +4px (spacious), without changing the font size.
- density:
'dense' | 'compact' | 'default' | 'comfortable' | 'spacious'='default'
<div style="display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;">
{#each ['dense', 'compact', 'default', 'comfortable', 'spacious'] as density (density)}
<kit:chip variant="outline" {density}>{density}</kit:chip>
{/each}
</div>
Colors
color accepts a color of the palette (accent, success…) or any CSS color. With a palette color, the text color follows its on- color; otherwise a contrasted color is computed.
Pass an object to use another color when the chip is active, or false for no color, handy with a condition: color={isActive && 'accent'}.
- color:
string | false | { base?: string | false; active?: string | false }=undefined
<script lang="ts">
let selected = $state(false);
</script>
<div style="display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;">
<kit:chip color="success">Palette</kit:chip>
<kit:chip variant="tonal" color="#e11d48">Custom</kit:chip>
<kit:chip
variant="outline"
color={{ base: 'accent', active: 'success' }}
active={selected}
onclick={() => (selected = !selected)}
>
{selected ? 'Selected' : 'Select'}
</kit:chip>
<kit:chip variant="tonal" color={selected && 'success'}>Follows the selection</kit:chip>
</div>
Interactive
An interactive chip changes its background on hover and pressed, and shows a ripple on click.
interactive:
boolean | undefined=undefinedundefined- detected: interactive when the chip renders as<a>or<button>, is an input, or has anonclick,onkeydownoronkeyuphandler.true- forced, without changing the element.false- no visual feedback, the chip stays clickable.
<div style="display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;">
<kit:chip variant="outline">Static</kit:chip>
<kit:chip variant="outline" onclick={() => alert('clicked')}>With onclick</kit:chip>
<kit:chip variant="outline" href="/docs">As a link</kit:chip>
<kit:chip variant="outline" interactive={false} onclick={() => alert('clicked')}>
No feedback
</kit:chip>
</div>
prepend and append snippets
Use prepend for an icon before the label, and append for an action typically a remove button.
- prepend:
Snippet | undefined=undefined - append:
Snippet | undefined=undefined
<script lang="ts">
import { Tag, X, CircleCheck } from 'lucide-svelte';
let tags = $state(['Svelte', 'TypeScript', 'CSS']);
function remove(tag: string) {
tags = tags.filter((t) => t !== tag);
}
</script>
<div style="display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;">
<kit:chip variant="outline">
{#snippet prepend()}
<kit:icon size="sm"><Tag /></kit:icon>
{/snippet}
Label
</kit:chip>
<kit:chip variant="filled">
{#snippet prepend()}
<kit:icon size="sm"><CircleCheck /></kit:icon>
{/snippet}
Verified
</kit:chip>
{#each tags as tag (tag)}
<kit:chip variant="outline">
{tag}
{#snippet append()}
<kit:btn icon variant="text" density="compact" size="xs" onclick={() => remove(tag)}>
<kit:icon size="sm"><X /></kit:icon>
</kit:btn>
{/snippet}
</kit:chip>
{/each}
</div>
States
disabled dims (--kit-disabled-opacity) and blocks interaction. readonly blocks interaction without the dim. active applies the active color, useful for toggled filter chips. While loading, aria-busy is set.
- active:
boolean=false - disabled:
boolean=false - readonly:
boolean=false
<div style="display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;">
<kit:chip variant="outline" active>Active</kit:chip>
<kit:chip variant="outline" disabled>Disabled</kit:chip>
<kit:chip variant="outline" readonly>Readonly</kit:chip>
<kit:chip variant="filled" disabled>Disabled filled</kit:chip>
</div>
labelStyle
labelStyle applies uppercase, bold, and slight letter-spacing suited for category or status badges.
- labelStyle:
boolean=false
<div style="display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;">
<kit:chip variant="filled" labelStyle>New</kit:chip>
<kit:chip variant="outline" labelStyle>Beta</kit:chip>
<kit:chip variant="outline" labelStyle>Deprecated</kit:chip>
<kit:chip variant="filled" labelStyle size="sm">Pro</kit:chip>
</div>
As an input
Add input (or is="input") to render a native <input> styled as a chip, inside a wrapper. A checkbox or a radio is wrapped in a <label>: the whole chip toggles the input, and it takes the active style while checked. Perfect for filters.
- input:
boolean=false - type:
'button' | 'submit' | 'reset' | 'checkbox' | 'radio'='button' - label:
string | undefined=undefined, the text of a checkbox or a radio (valuewhen empty) - value:
string | number | boolean | undefined=undefined - checked:
boolean | undefined=undefined
The other attributes (name, onchange…) go on the <input>, so the chip works in a form like a native input.
<script lang="ts">
const options = ['Design', 'Engineering', 'Product'];
let filters = $state<string[]>(['Design']);
let sort = $state('recent');
function toggle(option: string) {
filters = filters.includes(option)
? filters.filter((value) => value !== option)
: [...filters, option];
}
</script>
<div style="display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;">
{#each options as option (option)}
<kit:chip
input
type="checkbox"
label={option}
variant="outline"
checked={filters.includes(option)}
onchange={() => toggle(option)}
/>
{/each}
{#each ['recent', 'popular'] as value (value)}
<kit:chip
input
type="radio"
name="sort"
{value}
label={value}
variant="tonal"
color="accent"
checked={sort === value}
onchange={() => (sort = value)}
/>
{/each}
</div>
<p>Filters: {filters.join(', ') || 'none'}, sort: {sort}</p>
Without preprocess Lapikit
If you aren’t using the Lapikit preprocessor in svelte.config.js, import the component directly:
import { Chip } from 'lapikit/components';API Reference
kit:chip
| props | type | description | default |
|---|---|---|---|
| ref $bindable | HTMLElement | Bindable reference to the rendered DOM element. | null |
| is | enum'div''a''button''input' | HTML element. Overridden by href or event handlers; 'input' is the same as input. | 'div' |
| class | string | array | object | Classes of the chip, with the rules of Svelte (clsx). | |
| style | string | Inline style of the chip. | |
| s-class | string | array | object | Classes of the chip, merged with class. | |
| s-style | object | Inline style as an object of property / value pairs. | |
| variant | enum'filled''tonal''outline''surface''text''plain' | Visual style. | 'filled' |
| size | enum'xs''sm''md''lg''xl' | Height, padding, font size and gap. | 'md' |
| density | enum'dense''compact''default''comfortable''spacious' | Height and horizontal padding. | 'default' |
| interactive | boolean | undefined | undefined detects, true forces, false disables the visual feedback. | undefined |
| href | string | Renders as <a>. Cleared when disabled or readonly, the link leaves the keyboard navigation. | |
| type | enum'button''submit''reset''checkbox''radio' | Type of the button or of the input. | |
| input | boolean | Renders an <input> in a wrapper (a <label> for a checkbox or a radio). | |
| value | string | number | boolean | Value of the input. | |
| checked | boolean | Checked state of a checkbox or a radio input. | |
| label | string | Text of the input, value when empty. | |
| rounded | enum0'xs''sm''md''lg''xl''full' | Border radius. | 'full' |
| active | boolean | Applies the active color. | false |
| disabled | boolean | Dims and blocks all interaction. | false |
| readonly | boolean | Blocks interaction without disabled styling. | false |
| labelStyle | boolean | Uppercase, bold, letter-spacing for badges and categories. | false |
| loading | boolean | Shows a spinner, hides content, sets aria-busy. | |
| noRipple | boolean | Disables the ripple animation on click. | |
| prepend | Snippet | Content before the label. | |
| append | Snippet | Content after the label. | |
| load | Snippet | Custom spinner content shown while loading. | |
| children | Snippet | Chip label. | |
| color | string | false | { base?, active? } | Chip color, its use depends on the variant. | |
| elevation | ElevationStateenum'0''1''2''3''4''5' | Add shadow effect. |
class: and style: directives also work on kit:chip with the Lapikit preprocessor, see Class and Style.
kit:chip are often used in a Toolbar or as a complement in a Card to structure information and List.
