Components

Avatar component

The kit:avatar component is used to display images, icons or initials representing a person or object. It is often used in user interfaces to identify users, profiles or entities. Thanks to its many customization options, the kit:avatar component adapts easily to different styles and contexts.

avatar.svelte
Simone
BO
BY
Laurent
<div style="display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;">
	<kit:avatar>
		<img src="https://picsum.photos/seed/avatar1/80/80" alt="Simone" />
	</kit:avatar>

	<kit:avatar label="BO" />
	<kit:avatar label="BY" />

	<kit:avatar>
		<img src="https://picsum.photos/seed/avatar2/80/80" alt="Laurent" />
	</kit:avatar>
</div>

kit:avatar has two rendering modes:

  • Label mode - when label is set, the text is displayed uppercase and centered, its font size follows size.
  • Image mode - when children is provided instead, the content fills the avatar: a direct child <img> covers it.

size and density set the diameter in both modes. color sets the background, the text follows its on- color or a contrasted color.

Examples of avatar

label

Pass a string to label to display initials or short text. The value is trimmed and uppercased automatically.

  • label: string | undefined = undefined
avatar.svelte
<div style="display: flex; align-items: center; gap: 0.75rem;">
	<kit:avatar label="A" />
	<kit:avatar label="AB" />
	<kit:avatar label="CD" />
	<kit:avatar label="Nycolaide" />
</div>

Image

Without label, pass an <img> (or any element) as children. The image fills the circle via object-fit: cover.

avatar.svelte
<div style="display: flex; align-items: center; gap: 0.75rem;">
	{#each ['avatar1', 'avatar2', 'avatar3', 'avatar4'] as seed (seed)}
		<kit:avatar>
			<img src="https://picsum.photos/seed/{seed}/80/80" alt="" />
		</kit:avatar>
	{/each}
</div>

size

Controls the diameter and font size in label mode.

  • size: 'xs' | 'sm' | 'md' | 'lg' | 'xl' = 'md'
avatar.svelte
<div style="display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;">
	{#each ['xs', 'sm', 'md', 'lg', 'xl'] as size (size)}
		<div style="display: flex; flex-direction: column; align-items: center; gap: 0.375rem;">
			<kit:avatar label="AB" {size} />
			<span style="font-size: 0.75rem; opacity: 0.6;">{size}</span>
		</div>
	{/each}
</div>

density

Adjusts the diameter on top of size, from -4px (dense) to +4px (spacious).

  • density: 'dense' | 'compact' | 'default' | 'comfortable' | 'spacious' = 'default'
avatar.svelte
<div style="display: flex; align-items: center; gap: 0.75rem;">
	{#each ['dense', 'compact', 'default', 'comfortable', 'spacious'] as density (density)}
		<div style="display: flex; flex-direction: column; align-items: center; gap: 0.375rem;">
			<kit:avatar label="AB" {density} />
			<span style="font-size: 0.75rem; opacity: 0.6;">{density}</span>
		</div>
	{/each}
</div>

Without preprocess Lapikit

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

import { Avatar } from 'lapikit/components';

API Reference

kit:avatar

propstypedescriptiondefault
ref $bindableHTMLElementBindable reference to the rendered DOM element.null
classstring | array | objectClasses of the avatar, with the rules of Svelte (clsx).
stylestringInline style of the avatar.
s-classstring | array | objectClasses of the avatar, merged with class.
s-styleobjectInline style as an object of property / value pairs.
labelstringText displayed inside the avatar (uppercased).
sizeenum'xs''sm''md''lg''xl'Diameter (2rem to 4rem) and font size of the label.'md'
densityenum'dense''compact''default''comfortable''spacious'Diameter from -4px to +4px on top of size.'default'
roundedenum0'xs''sm''md''lg''xl''full'Border radius.'full'
childrenSnippetContent when label is not set (typically an <img>).
elevationElevationStateenum'0''1''2''3''4''5'Add shadow effect.
colorstring | false | { base?, active? }Background color, the text follows its on- color or a contrasted color.

Associate kit:avatar with user Cards or Chips to display roles or status.