Components

Alert component

The kit:alert component displays a contextual message to the user. It supports multiple tones, visual variants, and optional snippets for custom prepend, append, and close content. It is ideal for providing feedback, warnings, or important information in a way that stands out from the rest of the interface.

alert.svelte
Your session will expire in 10 minutes. Save your work.
Changes saved successfully.
<script lang="ts">
	import { CircleCheck, Info, TriangleAlert, CircleX } from 'lucide-svelte';
</script>

<div style="display: flex; flex-direction: column; gap: 0.75rem;">
	<kit:alert tone="info">
		{#snippet prepend()}
			<kit:icon><Info /></kit:icon>
		{/snippet}
		Your session will expire in 10 minutes. Save your work.
	</kit:alert>

	<kit:alert tone="success">
		{#snippet prepend()}
			<kit:icon><CircleCheck /></kit:icon>
		{/snippet}
		Changes saved successfully.
	</kit:alert>

	<kit:alert tone="warning">
		{#snippet prepend()}
			<kit:icon><TriangleAlert /></kit:icon>
		{/snippet}
		This action cannot be undone.
	</kit:alert>

	<kit:alert tone="error">
		{#snippet prepend()}
			<kit:icon><CircleX /></kit:icon>
		{/snippet}
		Failed to connect to the server. Please try again.
	</kit:alert>
</div>

kit:alert renders as a <div> by default. It has no internal logic beyond visibility: the open prop controls whether it is rendered, and closable adds a close button that sets open to false.

The role follows the tone: role="alert" for warning and error (the screen reader announces the message right away), role="status" for the other tones (announced politely). Pass role to override it.

Examples of alert

Tones

For greater expressiveness, an alert can be marked by a status: info, success, warning, error. Each tone applies its color of the palette (--kit-color-info…) and the matching role, to convey the right signal to the user. Add an icon with the prepend snippet.

  • tone: 'default' | 'info' | 'success' | 'warning' | 'error' = 'default'
alert.svelte
<div style="display: flex; flex-direction: column; gap: 0.75rem;">
	<kit:alert>Default tone — neutral feedback or general information.</kit:alert>
	<kit:alert tone="info">Info tone — informational messages and tips.</kit:alert>
	<kit:alert tone="success">Success tone — operation completed successfully.</kit:alert>
	<kit:alert tone="warning">Warning tone — potential issue that needs attention.</kit:alert>
	<kit:alert tone="error">Error tone — something went wrong, action required.</kit:alert>
</div>

Variants

The kit:alert can adopt different visual styles via the props variant:

  • filled (default): solid background, the tone color with a contrasted text (--kit-color-surface-2 without tone).
  • tonal: light tint of the tone color, text in the color.
  • outline: transparent background with a border.
  • surface: very light tint of the tone color with a soft border.
  • text: transparent background, text in the color.

These variants can be adapted to different visual contexts or levels of importance.

  • variant: 'filled' | 'tonal' | 'outline' | 'surface' | 'text' = 'filled'

The border thickness of outline and surface is set by the global variable --kit-outline-weight (1px by default).

alert.svelte
<div style="display: flex; flex-direction: column; gap: 0.75rem;">
	{#each ['filled', 'tonal', 'outline', 'surface', 'text'] as variant (variant)}
		<kit:alert tone="info" {variant}
			>{variant} — the info tone with the {variant} variant.</kit:alert
		>
	{/each}
</div>

Density

Props density adjusts the padding and the minimal height of the alert, from -4px (dense) to +4px (spacious). Ideal for adapting alerts to different levels of hierarchy or UI density.

  • density: 'dense' | 'compact' | 'default' | 'comfortable' | 'spacious' = 'default'
alert.svelte
<div style="display: flex; flex-direction: column; gap: 0.75rem;">
	{#each ['dense', 'compact', 'default', 'comfortable', 'spacious'] as density (density)}
		<kit:alert tone="info" variant="tonal" {density}
			>{density} — padding adjusts with density.</kit:alert
		>
	{/each}
</div>

Colors and multiline

color accepts a color of the palette or any CSS color. Without color, the tone gives the color; with color, the color is overridden but the tone keeps its role.

multiline aligns the snippets on the first line instead of the center, for messages on several lines.

  • color: string | false | { base?: string | false; active?: string | false } = undefined
  • multiline: boolean = false
alert.svelte
<div style="display: flex; flex-direction: column; gap: 0.75rem;">
	<kit:alert variant="tonal" color="accent">A color of the palette, without tone.</kit:alert>
	<kit:alert variant="surface" color="#7c3aed">Any CSS color works too.</kit:alert>
	<kit:alert tone="error" variant="tonal" color="warning">
		The tone stays error (role="alert"), the color is overridden.
	</kit:alert>
	<kit:alert tone="info" variant="surface" multiline>
		With multiline, the snippets are aligned on the first line.<br />
		Useful for messages on several lines.
	</kit:alert>
</div>

closable

Add closable to display a close button. The open prop is bindable so you can react to the dismissal externally.

  • open: boolean = true
  • closable: boolean = false
alert.svelte
<script lang="ts">
	let open = $state(true);
</script>

<div style="display: flex; flex-direction: column; gap: 0.75rem;">
	<kit:alert tone="warning" closable bind:open>
		Dismiss this alert by clicking the close button.
	</kit:alert>

	{#if !open}
		<kit:btn onclick={() => (open = true)}>Restore alert</kit:btn>
	{/if}
</div>

prepend and append snippets

Use prepend to add an icon or element before the content, and append to add one after for example a link or action button.

  • prepend: Snippet | undefined = undefined
  • append: Snippet | undefined = undefined
alert.svelte
<script lang="ts">
	import { ShieldCheck, ExternalLink } from 'lucide-svelte';
</script>

<kit:alert tone="success" variant="tonal">
	{#snippet prepend()}
		<kit:icon><ShieldCheck /></kit:icon>
	{/snippet}

	Your account is verified and secure.

	{#snippet append()}
		<kit:btn variant="link" color="success">
			Details
			{#snippet append()}
				<kit:icon size="sm"><ExternalLink /></kit:icon>
			{/snippet}
		</kit:btn>
	{/snippet}
</kit:alert>

close snippet

Use the close snippet to replace the default close icon with a custom element. The close button keeps its aria-label="Close".

  • close: Snippet | undefined = undefined
alert.svelte
<script lang="ts">
	import { X } from 'lucide-svelte';
</script>

<kit:alert tone="info" closable>
	{#snippet close()}
		<kit:icon size="sm"><X /></kit:icon>
	{/snippet}
	Custom close button with an icon from lucide-svelte.
</kit:alert>

Without preprocess Lapikit

If you aren’t using the Lapikit preprocessor in svelte.config.js, import the component directly:

import { Alert } from 'lapikit/components';

API Reference

kit:alert

propstypedescriptiondefault
ref $bindableHTMLElementBindable reference to the rendered DOM element.null
isenum'div''section''aside''article'HTML element to render.'div'
classstring | array | objectClasses of the alert, with the rules of Svelte (clsx).
stylestringInline style of the alert.
s-classstring | array | objectClasses of the alert, merged with class.
s-styleobjectInline style as an object of property / value pairs.
open $bindablebooleanControls visibility. Bindable.true
closablebooleanAdds a close button that sets open to false.false
closeLabelstringAccessible name of the close button.'Close'
variantenum'filled''tonal''outline''surface''text'Visual style of the alert.'filled'
densityenum'dense''compact''default''comfortable''spacious'Padding and minimal height.'default'
toneenum'default''info''success''warning''error'Semantic tone: default color and role.'default'
roundedenum0'xs''sm''md''lg''xl''full'Border radius.'md'
colorstring | false | { base?, active? }Alert color, overrides the color of the tone.
sizeenum'xs''sm''md''lg''xl'Sizing height, font and gap for alert.'md'
prependSnippetContent rendered before the main text.
appendSnippetContent rendered after the main text.
closeSnippetCustom content inside the close button.
childrenSnippetMain alert content.
multilinebooleanAligns the snippets on the first line.false
elevationElevationStateenum'0''1''2''3''4''5'Add shadow effect.

class: and style: directives also work on kit:alert with the Lapikit preprocessor, see Class and Style.

To enhance your kit:alert, think of Icon for legibility, or Button for integrated actions.