Components

Icon component

The kit:icon component is a sizing and accessibility wrapper for icons. It supports three rendering modes: SVG component via children, image via src, or CSS icon font via name.

icon.svelte
<script lang="ts">
	import { Star, Bell, Search, CircleCheck, TriangleAlert, Settings } from 'lucide-svelte';
</script>

<div style="display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;">
	<kit:icon><Star /></kit:icon>
	<kit:icon><Bell /></kit:icon>
	<kit:icon><Search /></kit:icon>
	<kit:icon><CircleCheck /></kit:icon>
	<kit:icon><TriangleAlert /></kit:icon>
	<kit:icon><Settings /></kit:icon>
</div>

kit:icon renders as an <i> by default. It sets a consistent font-size equal to the current size token, which becomes the width and height of the inner SVG or image. Child SVG components (e.g. lucide-svelte) inherit this size automatically.

All icons are decorative by default (aria-hidden="true"). Set decorative={false} with a label or alt to expose them to assistive technologies.

Examples of icon

size

When no size is set, the icon follows the size of the component around it: inside a kit:btn, a kit:chip or a kit:textfield, it takes the matching size. Elsewhere, it is md.

  • size: 'default' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' = 'default'
sizeicon size
xs0.75rem (12px)
sm0.875rem (14px)
md1rem (16px)
lg1.125rem (18px)
xl1.25rem (20px)

The sizes are in rem: the icon grows with the font size set in the browser, like the text around it. Override them with the --kit-icon-size-* variables.

icon.svelte
<script lang="ts">
	import { Star } from 'lucide-svelte';
</script>

<div style="display: flex; align-items: center; gap: 1rem;">
	{#each ['xs', 'sm', 'md', 'lg', 'xl'] as size (size)}
		<div style="display: flex; flex-direction: column; align-items: center; gap: 0.375rem;">
			<kit:icon {size}><Star /></kit:icon>
			<span style="font-size: 0.75rem; opacity: 0.6;">{size}</span>
		</div>
	{/each}
</div>

color

Pass a color of the palette (success, error…) or any CSS color (#f00, oklch(...)) to color. It sets --kit-icon-color, used by the icon and by the mask mode. Without color, the icon takes the color of the text around it.

  • color: string | false = undefined
icon.svelte
<script lang="ts">
	import { Heart, Star, Flame } from 'lucide-svelte';
</script>

<div style="display: flex; align-items: center; gap: 1rem;">
	<kit:icon color="oklch(0.65 0.22 25)"><Heart /></kit:icon>
	<kit:icon color="oklch(0.78 0.18 85)"><Star /></kit:icon>
	<kit:icon color="oklch(0.70 0.20 45)"><Flame /></kit:icon>
</div>

src image icons

Pass an image URL to src. For SVG sources, colorMode="mask" applies currentColor via CSS mask useful for single-color icons that need to follow the theme.

  • src: string = ''
  • colorMode: 'auto' | 'mask' | 'filter' | 'none' = 'auto'
  • imgFilter: string = ''
icon.svelte
<div style="display: flex; align-items: center; gap: 1rem;">
	<kit:icon src="https://svelte.dev/favicon.png" size="xl" alt="Svelte" decorative={false} />
	<kit:icon
		src="https://svelte.dev/favicon.png"
		size="xl"
		color="currentColor"
		colorMode="mask"
		alt="Svelte masked"
		decorative={false}
	/>
</div>

Accessibility

By default icons are hidden from assistive technologies (decorative={true}, aria-hidden="true"). Set decorative={false} and provide label (or alt for image icons) when the icon carries meaning on its own.

  • decorative: boolean = true
  • label: string | undefined = undefined
  • alt: string | undefined = undefined

Without preprocess Lapikit

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

import { Icon } from 'lapikit/components';

API Reference

kit:icon

propstypedescriptiondefault
ref $bindableHTMLElementBindable reference to the rendered DOM element.null
isenum'i''span'HTML element to render.'i'
classstring | array | objectClasses of the icon, with the rules of Svelte (clsx).
stylestringInline style of the icon.
s-classstring | array | objectClasses of the icon, merged with class.
s-styleobjectInline style as an object of property / value pairs.
sizeenum'default''xs''sm''md''lg''xl'Icon size. 'default' follows the parent component, else md.'default'
srcstringImage URL. Used instead of children.
namestringCSS class name for icon fonts.
iconstringAlias treated as src if it contains /, else name.
colorstring | falseA color of the palette or any CSS color (--kit-icon-color).
colorModeenum'auto''mask''filter''none'How color is applied to image icons.'auto'
imgFilterstringCSS filter value used in filter mode.
decorativebooleanHides from assistive tech when true.true
labelstringAccessible label when decorative={false}.
altstringAlt text for image icons.''
loadingenum'eager''lazy'Image loading strategy.'eager'
decodingenum'sync''async''auto'Image decoding hint.'async'
childrenSnippetSVG icon component (e.g. from lucide-svelte).

Add kit:icon to your Buttons, Cards or Chips to visually guide your users.