skip section navigation

Card

Card groups related content on one surface. start with a passive card when the contents include their own controls. the reading list can keep a note and a save action together without making the entire surface a button.

The balcony garden

A note for the weekend plan.

usage

svelte
<script>
	import { Card, Input, Field, FieldLabel } from '@ciabi/loafkit-ui';
	let note = $state('Check the balcony garden before Saturday.');
	let saved = $state('');
</script>

<Card title="The balcony garden" description="A note for the weekend plan.">
	<Field>
		<FieldLabel htmlFor="card-note">Weekend note</FieldLabel>
		<Input id="card-note" multiline bind:value={note} />
	</Field>
	<button type="button" onclick={() => saved = note}>save note</button>
	{#if saved}<p role="status">saved: {saved}</p>{/if}
</Card>

composition

  • Card
    • children(optional)

compare surface emphasis

Garden notes

check which herbs can stay outside overnight.

svelte
<script lang="ts">
import { Card, Selector } from '@ciabi/loafkit-ui';
let cardSurface = $state<'flat' | 'bordered' | 'elevated' | 'ghost'>('bordered');
</script>

<Selector label="note surface" selected={cardSurface} onValueChange={value => cardSurface = value as typeof cardSurface}
	options={['flat', 'bordered', 'elevated', 'ghost'].map(value => ({ value, label: value }))} />
<Card variant={cardSurface} title="Garden notes"><p>check which herbs can stay outside overnight.</p></Card>

choose an action or a destination

selected: none

Learn about collections

open the Card guide

svelte
<script lang="ts">
import { Card } from '@ciabi/loafkit-ui';
let chosenCard = $state('none');
</script>

<Card title="Weekend reading" onclick={() => chosenCard = 'weekend reading'}><p>choose this collection</p></Card>
<p role="status">selected: {chosenCard}</p>
<Card title="Learn about collections" href="/docs/components/card/"><p>open the Card guide</p></Card>

onclick wins if both it and href are supplied. do not nest buttons or links inside these interactive cards. for several actions, use a passive Card like the first example. href with displayUrl and title also creates an internal URLButton, which can nest links; use a passive Card with a separate URLButton instead.

API reference

Card

Component
variant
Default: 'flat'

the surface emphasis.

onclick

makes the whole card a button; takes precedence over href.

children

custom content inside the component.

href

makes the whole card a destination link when onclick is absent.

displayUrl

short address for the internal URLButton when href and title are supplied.

title

the card heading, also used to name an interactive card.

description

supporting text below the heading.

imageSrc

image for the internal URLButton.

bannerSrc

image across the top of the card.

subtitle

small secondary text below the heading.

padded
Default: true

adds the built-in content padding.

class
Default: ''

extra classes on the component root.

style

inline styles on the component root.