Button component
The kit:btn component is a central component of Lapikit. It allows you to create buttons that are adaptable, accessible and easily customized, either via props or CSS variables.
It automatically manages variants, states (active, loading, etc.), accessibility, colors, sizes, and integrates with icons or additional content (prepend, append, load).
<script lang="ts">
import { Download, Mail } from 'lucide-svelte';
</script>
<div style="display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;">
<kit:btn color="accent">Default</kit:btn>
<kit:btn variant="filled" color="accent">Filled</kit:btn>
<kit:btn variant="outline" color="accent">Outline</kit:btn>
<kit:btn variant="text" color="accent">Text</kit:btn>
<kit:btn variant="filled" color="accent">
{#snippet prepend()}
<kit:icon><Download /></kit:icon>
{/snippet}
Download
</kit:btn>
<kit:btn variant="outline" color="accent">
{#snippet append()}
<kit:icon><Mail /></kit:icon>
{/snippet}
Contact
</kit:btn>
</div>
Examples of button
Variants
Variants control the overall style of the button. They enable adaptation to different interface contexts, while maintaining visual consistency.
filled (default): solid button, generally used for main actions. Surface background (
--kit-color-surface-2), or thecolorwith a contrasted text.tonal: light tint of the color, text in the color. A softer main action.
outline: transparent background with a border, often used for secondary actions.
surface: very light tint of the color with a soft border.
text: discreet button with no background or border, perfect for actions in a text flow.
plain: like
text, but hover and pressed only change the text color, never the background.link: styled as a hyperlink (underlined, no height or padding), ideal for navigation or less prominent actions.
variant:
'filled' | 'tonal' | 'outline' | 'surface' | 'text' | 'plain' | 'link'='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.75rem; flex-wrap: wrap;">
{#each ['filled', 'tonal', 'outline', 'surface', 'text', 'plain', 'link'] as variant (variant)}
<kit:btn {variant} color="accent">{variant}</kit:btn>
{/each}
</div>
size
The size prop adjusts the button’s height, padding, font size and the gap between the icon and the text. It allows you to create buttons that fit different contexts, from compact icon buttons to large call-to-action buttons.
- size:
'xs' | 'sm' | 'md' | 'lg' | 'xl'='md'
| size | height | font size |
|---|---|---|
xs | 1.5rem (24px) | 0.75rem (12px) |
sm | 2rem (32px) | --kit-font-xs (13px) |
md | 2.5rem (40px) | --kit-font-sm (14px) |
lg | 3rem (48px) | --kit-font-lg (16px) |
xl | 3.5rem (56px) | --kit-font-xl (17px) |
The sizes are in rem: the button 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.75rem; flex-wrap: wrap;">
{#each ['xs', 'sm', 'md', 'lg', 'xl'] as size (size)}
<kit:btn {size}>{size}</kit:btn>
{/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.75rem; flex-wrap: wrap;">
{#each ['dense', 'compact', 'default', 'comfortable', 'spacious'] as density (density)}
<kit:btn variant="outline" {density}>{density}</kit:btn>
{/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 button 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.75rem; flex-wrap: wrap;">
<kit:btn color="accent">Palette</kit:btn>
<kit:btn variant="tonal" color="#e11d48">Custom</kit:btn>
<kit:btn
variant="outline"
color={{ base: 'accent', active: 'success' }}
active={selected}
onclick={() => (selected = !selected)}
>
{selected ? 'Selected' : 'Select'}
</kit:btn>
<kit:btn variant="tonal" color={selected && 'success'}>Follows the selection</kit:btn>
</div>
icon
Add icon to render a square button width equals height. Useful for icon-only actions.
- icon:
boolean=false
<script lang="ts">
import { Search, Bell, Settings, Plus } from 'lucide-svelte';
</script>
<div style="display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;">
<kit:btn icon>
<kit:icon><Search /></kit:icon>
</kit:btn>
<kit:btn icon variant="outline">
<kit:icon><Bell /></kit:icon>
</kit:btn>
<kit:btn icon variant="text">
<kit:icon><Settings /></kit:icon>
</kit:btn>
<kit:btn icon size="lg">
<kit:icon><Plus /></kit:icon>
</kit:btn>
</div>
prepend and append snippets
Use prepend and append to place icons or elements on either side of the label.
- prepend:
Snippet | undefined=undefined - append:
Snippet | undefined=undefined
<script lang="ts">
import { Upload, ChevronDown, ArrowRight } from 'lucide-svelte';
</script>
<div style="display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;">
<kit:btn>
{#snippet prepend()}
<kit:icon><Upload /></kit:icon>
{/snippet}
Upload
</kit:btn>
<kit:btn variant="outline">
Options
{#snippet append()}
<kit:icon><ChevronDown /></kit:icon>
{/snippet}
</kit:btn>
<kit:btn variant="text">
Continue
{#snippet append()}
<kit:icon><ArrowRight /></kit:icon>
{/snippet}
</kit:btn>
</div>
States
The kit:btn component can reflect several visual or functional states, useful for informing the user or managing interaction. These states can be combined in certain cases (e.g. loading + success), but some, such as disabled, take precedence over all.
Here are the main states available:
- disabled:
boolean=false - loading:
boolean=false - active:
boolean=false
The button changes its background on hover and pressed, and shows a ripple on click (noRipple removes it). A disabled button is dimmed with --kit-disabled-opacity. While loading, aria-busy is set.
<script lang="ts">
let loading = $state(false);
function simulate() {
loading = true;
setTimeout(() => (loading = false), 2000);
}
</script>
<div style="display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;">
<kit:btn disabled>Disabled</kit:btn>
<kit:btn variant="outline" disabled>Disabled</kit:btn>
<kit:btn active>Active</kit:btn>
<kit:btn {loading} onclick={simulate}>
{loading ? 'Loading…' : 'Click me'}
</kit:btn>
</div>
Use the load snippet to replace the default ... spinner with custom content.
- load:
Snippet | undefined=undefined
block and wide
block makes the button stretch to its container’s full width. wide caps it at 16rem and is intended to be centered.
- block:
boolean=false - wide:
boolean=false
<div style="display: flex; flex-direction: column; gap: 0.75rem;">
<kit:btn block>Block — full width</kit:btn>
<div style="display: flex; justify-content: center;">
<kit:btn wide>Wide — capped at 16rem</kit:btn>
</div>
</div>
As a link
Pass href to render the button as an <a> element. The disabled prop removes href and takes the link out of the keyboard navigation (tabindex="-1").
- href:
string | undefined=undefined
<script lang="ts">
import { ExternalLink } from 'lucide-svelte';
</script>
<div style="display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;">
<kit:btn href="/docs" variant="filled">Go to docs</kit:btn>
<kit:btn href="/docs" variant="outline">
Documentation
{#snippet append()}
<kit:icon size="sm"><ExternalLink /></kit:icon>
{/snippet}
</kit:btn>
<kit:btn href="/docs" variant="link">Read more</kit:btn>
</div>
As an input
Add input (or is="input") to render a native <input> styled as a button, inside a wrapper. A checkbox or a radio is wrapped in a <label>: the whole button toggles the input, and it takes the active style while checked. The other types (button, submit, reset) are wrapped in a <div>.
- 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 button works in a form like a native input.
<script lang="ts">
let bold = $state(false);
let align = $state('left');
</script>
<div style="display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;">
<kit:btn
input
type="checkbox"
label="Bold"
variant="outline"
checked={bold}
onchange={() => (bold = !bold)}
/>
{#each ['left', 'center', 'right'] as value (value)}
<kit:btn
input
type="radio"
name="align"
{value}
label={value}
variant="tonal"
color="accent"
checked={align === value}
onchange={() => (align = value)}
/>
{/each}
<form onsubmit={(event) => event.preventDefault()}>
<kit:btn input type="submit" value="Send" color="accent" />
</form>
</div>
<p>Bold: {bold}, align: {align}</p>
Without preprocess Lapikit
If you aren’t using the Lapikit preprocessor in svelte.config.js, import the component directly:
import { Btn } from 'lapikit/components';API Reference
kit:btn
| props | type | description | default |
|---|---|---|---|
| ref $bindable | HTMLElement | Bindable reference to the rendered DOM element. | null |
| is | enum'button''a''input' | HTML element to render. Overridden by href; 'input' is the same as input. | 'button' |
| class | string | array | object | Classes of the button, with the rules of Svelte (clsx). | |
| style | string | Inline style of the button. | |
| s-class | string | array | object | Classes of the button, merged with class. | |
| s-style | object | Inline style as an object of property / value pairs. | |
| variant | enum'filled''tonal''outline''surface''text''plain''link' | 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' |
| rounded | enum0'xs''sm''md''lg''xl''full' | Border radius. | 'sm' |
| href | string | Renders as <a>. Cleared when disabled. | |
| type | enum'button''submit''reset''checkbox''radio' | Type of the button or of the input. | 'button' |
| 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. | |
| disabled | boolean | Prevents interaction, dims the button. | false |
| loading | boolean | Shows a spinner, hides content, sets aria-busy. | |
| active | boolean | Applies the pressed background. | false |
| icon | boolean | Makes width equal height for icon-only buttons. | |
| block | boolean | Stretches to full container width. | |
| wide | boolean | Caps width at 16rem. | |
| 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 | Button label. | |
| color | string | false | { base?, active? } | Button 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:btn with the Lapikit preprocessor, see Class and Style.
kit:btn become more effective with Tooltips, a Toolbar or Popover interactions.
