Components

Card component

The kit:card component is a versatile container used to group together information or actions in a user interface. It can be used to display content, images, buttons or links, while offering advanced customization to suit various styles and contexts.

card.svelte
Mountain hike
A breathtaking trail through alpine meadows and rocky peaks.
2 hours ago
Forest trail
Dense canopy, mossy rocks, and the sound of a distant waterfall.
Yesterday
<script lang="ts">
	import { Heart, Share2 } from 'lucide-svelte';
</script>

<div
	style="display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem;"
>
	<kit:card>
		<kit:card-media>
			<kit:aspect-ratio ratio="16/9">
				<img src="https://picsum.photos/seed/card1/400/225" alt="" />
			</kit:aspect-ratio>
		</kit:card-media>
		<kit:card-title>Mountain hike</kit:card-title>
		<kit:card-content>A breathtaking trail through alpine meadows and rocky peaks.</kit:card-content
		>
		<kit:card-actions>
			<span>2 hours ago</span>
			<kit:spacer />
			<kit:btn icon variant="text" density="compact">
				<kit:icon size="sm"><Heart /></kit:icon>
			</kit:btn>
			<kit:btn icon variant="text" density="compact">
				<kit:icon size="sm"><Share2 /></kit:icon>
			</kit:btn>
		</kit:card-actions>
	</kit:card>

	<kit:card variant="outline">
		<kit:card-media>
			<kit:aspect-ratio ratio="16/9">
				<img src="https://picsum.photos/seed/card2/400/225" alt="" />
			</kit:aspect-ratio>
		</kit:card-media>
		<kit:card-title>Forest trail</kit:card-title>
		<kit:card-content
			>Dense canopy, mossy rocks, and the sound of a distant waterfall.</kit:card-content
		>
		<kit:card-actions>
			<span>Yesterday</span>
			<kit:spacer />
			<kit:btn icon variant="text" density="compact">
				<kit:icon size="sm"><Heart /></kit:icon>
			</kit:btn>
			<kit:btn icon variant="text" density="compact">
				<kit:icon size="sm"><Share2 /></kit:icon>
			</kit:btn>
		</kit:card-actions>
	</kit:card>
</div>

kit:card is a layout container, it adds no heading or structure on its own. Use the following subcomponents to structure your card content:

componentsdescription
kit:card-mediaWraps media (image, video). Its radius follows the card radius.
kit:card-titleBold title. font-weight: 600, tight line-height.
kit:card-contentMain text content.
kit:card-actionsFlex bar for action buttons.
kit:card-containerMain container for the card content.
card.svelte
<script lang="ts">
	import { BookOpen } from 'lucide-svelte';
</script>

<kit:card style="max-width: 320px;">
	<kit:card-media>
		<kit:aspect-ratio ratio="16/9">
			<img src="https://picsum.photos/seed/card3/400/225" alt="" />
		</kit:aspect-ratio>
	</kit:card-media>

	<kit:card-title>Getting started</kit:card-title>

	<kit:card-content>
		Learn how to install Lapikit and set up the preprocessor in your Svelte project.
	</kit:card-content>

	<kit:card-actions>
		<span>5 min read</span>
		<kit:spacer />
		<kit:btn density="compact" size="sm">
			{#snippet prepend()}
				<kit:icon size="sm"><BookOpen /></kit:icon>
			{/snippet}
			Read
		</kit:btn>
	</kit:card-actions>
</kit:card>

Examples of card

Variants

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

  • filled - surface background (--kit-color-surface-1), or the color with a contrasted text.

  • tonal - light tint of the color, text in the color.

  • outline - transparent background with a border, text in the color.

  • surface - very light tint of the color with a soft border.

  • text - no background or border, text in the color.

  • plain - like text, but hover and pressed only change the text color, never the background.

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

card.svelte
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem;">
	{#each ['filled', 'tonal', 'outline', 'surface', 'text', 'plain'] as variant (variant)}
		<kit:card {variant}>
			<kit:card-title>{variant}</kit:card-title>
			<kit:card-content>Variant <code>{variant}</code>.</kit:card-content>
		</kit:card>
	{/each}
</div>

Density

density adjusts the internal padding (from 6px to 14px) and the gap between the subcomponents (from 0px to 8px).

  • density: 'dense' | 'compact' | 'default' | 'comfortable' | 'spacious' = 'default'
card.svelte
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; align-items: start;">
	{#each ['dense', 'compact', 'default', 'comfortable', 'spacious'] as density (density)}
		<kit:card variant="outline" {density}>
			<kit:card-title>{density}</kit:card-title>
			<kit:card-content>Padding and gap adjust with density.</kit:card-content>
		</kit:card>
	{/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 card is active.

  • color: string | { base?: string; active?: string } = undefined

kit:card-title and kit:card-content also accept a color (a string) to change only their text color.

card.svelte
<script lang="ts">
	let selected = $state(false);
</script>

<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem;">
	<kit:card color="accent">
		<kit:card-title>Palette</kit:card-title>
		<kit:card-content>A color of the palette, the text color follows.</kit:card-content>
	</kit:card>

	<kit:card variant="tonal" color="#e11d48">
		<kit:card-title>Custom</kit:card-title>
		<kit:card-content>Any CSS color works too.</kit:card-content>
	</kit:card>

	<kit:card
		variant="outline"
		color={{ base: 'accent', active: 'success' }}
		active={selected}
		onclick={() => (selected = !selected)}
	>
		<kit:card-title color="success">Active color</kit:card-title>
		<kit:card-content>Click to toggle the active state.</kit:card-content>
	</kit:card>
</div>

Interactive

An interactive card changes its background on hover and pressed, and shows a ripple on click.

  • interactive: boolean | undefined = undefined

  • undefined - detected: interactive when the card renders as <a> or <button>, or has an onclick, onpointerdown or onkeydown handler.

  • true - forced, even on a plain <div>, without changing the element.

  • false - no visual feedback, the card stays clickable.

To add a shadow on hover, use the multi-state elevation.

  • href: string | undefined = undefined
  • active: boolean = false
  • disabled: boolean = false
  • noRipple: boolean = false

When disabled is true on an <a> card, href is removed and tabindex="-1" is set.

card.svelte
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem;">
	<kit:card variant="outline" href="/docs">
		<kit:card-title>As a link</kit:card-title>
		<kit:card-content
			>Detected via <code>href</code> — renders as <code>&lt;a&gt;</code>.</kit:card-content
		>
	</kit:card>

	<kit:card variant="outline" interactive>
		<kit:card-title>Forced</kit:card-title>
		<kit:card-content
			>Hover, pressed and ripple via <code>interactive</code> — stays a
			<code>&lt;div&gt;</code>.</kit:card-content
		>
	</kit:card>

	<kit:card variant="outline" interactive={false} onclick={() => alert('clicked')}>
		<kit:card-title>No feedback</kit:card-title>
		<kit:card-content
			>Still clickable, but <code>interactive=&#123;false&#125;</code> removes the visual feedback.</kit:card-content
		>
	</kit:card>
</div>

Elevation

The Elevation property allows you to apply a box shadow effect to the Card component. This property lets you add this effect to the component—either by default or when the component is in the hover or active states.

  • elevation: '0' | '1' | '2' | '3' | '4' | '5' = 'undefined'
  • elevation (multi-state): {base: value, hover: value, active: value}
card.svelte
<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem;">
	<kit:card elevation="3">
		<kit:card-title>Elevation</kit:card-title>
		<kit:card-content> Elevation effect on component card </kit:card-content>
	</kit:card>

	<kit:card elevation={{ base: 1, hover: 4 }}>
		<kit:card-title>Elevation hover</kit:card-title>
		<kit:card-content> Effect elevation basic and hover </kit:card-content>
	</kit:card>
</div>

Without preprocess Lapikit

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

import { Card } from 'lapikit/components';

API Reference

kit:card

propstypedescriptiondefault
ref $bindableHTMLElementBindable reference to the rendered DOM element.null
isenum'div''article''section''aside''a''button'HTML element to render. Overridden by href.'div'
classstring | array | objectClasses of the card, with the rules of Svelte (clsx).
stylestringInline style of the card.
s-classstring | array | objectClasses of the card, merged with class.
s-styleobjectInline style as an object of property / value pairs.
variantenum'filled''tonal''outline''surface''text''plain'Visual style.'filled'
typeenum'button''submit''reset'Defined html type to card.
densityenum'dense''compact''default''comfortable''spacious'Internal padding and gap.'default'
roundedenum0'xs''sm''md''lg''xl'Border radius.'md'
elevationElevationStateenum'0''1''2''3''4''5'Add shadow effect.
hrefstringRenders as <a>. Enables interactive mode.
interactiveboolean | undefinedundefined detects, true forces, false disables the visual feedback.undefined
activebooleanApplies the pressed background.false
disabledbooleanDims and disables interaction.false
noRipplebooleanDisables the ripple animation on click.
childrenSnippetCard content.
colorstring | { base?: string; active?: string }Card color, its use depends on the variant.

kit:card-container

propstypedescriptiondefault
ref $bindableHTMLElementBindable reference to the rendered DOM element.null
isenum'div''span'HTML element to render'div'
classstring | array | objectClasses of the card container, with the rules of Svelte (clsx).
stylestringInline style of the card container.
s-classstring | array | objectClasses of the card container, merged with class.
s-styleobjectInline style as an object of property / value pairs.

kit:card-title

propstypedescriptiondefault
ref $bindableHTMLElementBindable reference to the rendered DOM element.null
isenum'div''p''span''h1''h2''h3''h4''h5''h6'HTML element to render'div'
classstring | array | objectClasses of the card title, with the rules of Svelte (clsx).
stylestringInline style of the card title.
s-classstring | array | objectClasses of the card title, merged with class.
s-styleobjectInline style as an object of property / value pairs.
colorstringText color (--kit-card-title-color).

kit:card-content

propstypedescriptiondefault
ref $bindableHTMLElementBindable reference to the rendered DOM element.null
isenum'div''p''span''h1''h2''h3''h4''h5''h6'HTML element to render'div'
classstring | array | objectClasses of the card content, with the rules of Svelte (clsx).
stylestringInline style of the card content.
s-classstring | array | objectClasses of the card content, merged with class.
s-styleobjectInline style as an object of property / value pairs.
colorstringText color (--kit-card-content-color).

kit:card-media

propstypedescriptiondefault
ref $bindableHTMLElementBindable reference to the rendered DOM element.null
isenum'div''span'HTML element to render'div'
classstring | array | objectClasses of the card media, with the rules of Svelte (clsx).
stylestringInline style of the card media.
s-classstring | array | objectClasses of the card media, merged with class.
s-styleobjectInline style as an object of property / value pairs.

kit:card-actions

propstypedescriptiondefault
ref $bindableHTMLElementBindable reference to the rendered DOM element.null
isenum'div''span'HTML element to render'div'
classstring | array | objectClasses of the card actions, with the rules of Svelte (clsx).
stylestringInline style of the card actions.
s-classstring | array | objectClasses of the card actions, merged with class.
s-styleobjectInline style as an object of property / value pairs.

class: and style: directives also work on every card component with the Lapikit preprocessor, see Class and Style.

CSS variables

variabledescription
--kit-card-paddingInternal padding, set by density.
--kit-card-gapGap between the subcomponents, set by density.
--kit-card-radiusBorder radius, set by rounded.
--kit-outline-weightBorder thickness of the outline and surface variants (global variable).

For better structure, combine your Cards with Avatars and clear Buttons.