Components

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).

button.svelte
<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 the color with 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).

button.svelte
<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'
sizeheightfont size
xs1.5rem (24px)0.75rem (12px)
sm2rem (32px)--kit-font-xs (13px)
md2.5rem (40px)--kit-font-sm (14px)
lg3rem (48px)--kit-font-lg (16px)
xl3.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).

button.svelte
<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'
button.svelte
<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
button.svelte
<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
button.svelte
<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
button.svelte
<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.

button.svelte
<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
button.svelte
<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>

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
button.svelte
<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 (value when 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.

button.svelte
<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

propstypedescriptiondefault
ref $bindableHTMLElementBindable reference to the rendered DOM element.null
isenum'button''a''input'HTML element to render. Overridden by href; 'input' is the same as input.'button'
classstring | array | objectClasses of the button, with the rules of Svelte (clsx).
stylestringInline style of the button.
s-classstring | array | objectClasses of the button, merged with class.
s-styleobjectInline style as an object of property / value pairs.
variantenum'filled''tonal''outline''surface''text''plain''link'Visual style.'filled'
sizeenum'xs''sm''md''lg''xl'Height, padding, font size and gap.'md'
densityenum'dense''compact''default''comfortable''spacious'Height and horizontal padding.'default'
roundedenum0'xs''sm''md''lg''xl''full'Border radius.'sm'
hrefstringRenders as <a>. Cleared when disabled.
typeenum'button''submit''reset''checkbox''radio'Type of the button or of the input.'button'
inputbooleanRenders an <input> in a wrapper (a <label> for a checkbox or a radio).
valuestring | number | booleanValue of the input.
checkedbooleanChecked state of a checkbox or a radio input.
labelstringText of the input, value when empty.
disabledbooleanPrevents interaction, dims the button.false
loadingbooleanShows a spinner, hides content, sets aria-busy.
activebooleanApplies the pressed background.false
iconbooleanMakes width equal height for icon-only buttons.
blockbooleanStretches to full container width.
widebooleanCaps width at 16rem.
noRipplebooleanDisables the ripple animation on click.
prependSnippetContent before the label.
appendSnippetContent after the label.
loadSnippetCustom spinner content shown while loading.
childrenSnippetButton label.
colorstring | false | { base?, active? }Button color, its use depends on the variant.
elevationElevationStateenum'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.