Components

Avatar

An image element with a reliable fallback for representing a user or entity.

Preview

CN
AK
UI

Installation

Install directly from the hosted registry with the shadcn-svelte CLI.

Terminal
npx shadcn-svelte@latest add https://ui.akcodeworks.com/r/avatar.json

Usage

Place Image and Fallback inside Root. Always provide descriptive alt text for meaningful images.

API reference

PropTypeDefault
delayMsnumber0
loadingStatusloading | loaded | errorloading
srcstringrequired
altstringrequired

Source

These files are included in the registry item and copied into the consuming project.

avatar.svelte
<script lang="ts">	import { Avatar as AvatarPrimitive } from 'bits-ui';	import { cw } from '$lib/utils';	let {		ref = $bindable(null),		class: className,		...restProps	}: AvatarPrimitive.RootProps = $props();</script><AvatarPrimitive.Root	bind:ref	data-slot="avatar"	class={cw('relative flex size-10 shrink-0 overflow-hidden rounded-full', className)}	{...restProps}/>
avatar-image.svelte
<script lang="ts">	import { Avatar as AvatarPrimitive } from 'bits-ui';	import { cw } from '$lib/utils';	let {		ref = $bindable(null),		class: className,		...restProps	}: AvatarPrimitive.ImageProps = $props();</script><AvatarPrimitive.Image	bind:ref	data-slot="avatar-image"	class={cw('aspect-square size-full object-cover', className)}	{...restProps}/>
avatar-fallback.svelte
<script lang="ts">	import { Avatar as AvatarPrimitive } from 'bits-ui';	import { cw } from '$lib/utils';	let {		ref = $bindable(null),		class: className,		...restProps	}: AvatarPrimitive.FallbackProps = $props();</script><AvatarPrimitive.Fallback	bind:ref	data-slot="avatar-fallback"	class={cw(		'flex size-full items-center justify-center rounded-full bg-muted text-sm font-medium',		className	)}	{...restProps}/>
index.ts
import Root from './avatar.svelte';import Image from './avatar-image.svelte';import Fallback from './avatar-fallback.svelte';export { Root, Image, Fallback };export { Root as Avatar, Image as AvatarImage, Fallback as AvatarFallback };