Avatar
An avatar component that displays a user's image with a fallback for text initials or alternative image.
Import
import Avatar from "$lib/components/Avatar.svelte"; Image Avatar
JD
<Avatar src="/icons/Book.svg" alt="User avatar" fallback="JD" class_name="size-16 rounded-full border border-border p-4" />
Text Fallback
JD
<Avatar
fallback="JD"
class_name="size-16 rounded-full"
fallback_class="bg-blue-500 text-white rounded-full"
/>Image Fallback
<Avatar
fallbackType="image"
fallback="/icons/Circle.svg"
alt="Fallback avatar"
class_name="size-16"
padding="p-2"
/>Properties
Name
Type
Description
src
Type
string | undefined
Default: undefined
URL of the avatar image.
alt
Type
string
Default: ""
Alt text for the avatar image.
fallback
Type
string
Default: ""
Text to show when the image fails to load.
class_name
Type
string
Default: ""
Classes to apply to the avatar root (e.g., "size-16 rounded-full").
fallback_class
Type
string
Default: ""
Classes to apply to the fallback element (e.g., "bg-blue-500 text-white rounded-full").