Data Display

Avatar

Display user profile images with automatic initials fallback. Supports 9 sizes, border radius variants, chip indicators, icon fallback, and style overrides.

Playground

Experiment with different props in real-time.

JD

Basic Usage

Pass a src and alt to display a user avatar.

JD
<script lang="ts">
  import { Avatar } from 'sv5ui';
</script>

<Avatar src="https://i.pravatar.cc/300?u=1" alt="John Doe" />

Sizes

9 sizes from 3xs (16px) to 3xl (48px).

U
U
U
U
U
U
U
U
U
<Avatar size="3xs" src="https://i.pravatar.cc/300?u=1" alt="User" />
<Avatar size="2xs" src="https://i.pravatar.cc/300?u=2" alt="User" />
<Avatar size="xs" src="https://i.pravatar.cc/300?u=3" alt="User" />
<Avatar size="sm" src="https://i.pravatar.cc/300?u=4" alt="User" />
<Avatar size="md" src="https://i.pravatar.cc/300?u=5" alt="User" />
<Avatar size="lg" src="https://i.pravatar.cc/300?u=6" alt="User" />
<Avatar size="xl" src="https://i.pravatar.cc/300?u=7" alt="User" />
<Avatar size="2xl" src="https://i.pravatar.cc/300?u=8" alt="User" />
<Avatar size="3xl" src="https://i.pravatar.cc/300?u=9" alt="User" />

Rounded

Control border radius with the rounded prop.

U
full
U
lg
U
md
U
sm
U
none
<Avatar rounded="full" src="https://i.pravatar.cc/300?u=1" alt="User" />
<Avatar rounded="lg" src="https://i.pravatar.cc/300?u=2" alt="User" />
<Avatar rounded="md" src="https://i.pravatar.cc/300?u=3" alt="User" />
<Avatar rounded="sm" src="https://i.pravatar.cc/300?u=4" alt="User" />
<Avatar rounded="none" src="https://i.pravatar.cc/300?u=5" alt="User" />

With Initials

When no src is provided, initials are automatically generated from the alt prop.

JD
AS
B
<!-- Auto-generated from alt prop -->
<Avatar alt="John Doe" />
<Avatar alt="Alice Smith" />
<Avatar alt="Bob" />

Custom Fallback Text

Use the text prop to display custom fallback text instead of auto-generated initials.

AB
OK
?
<!-- Custom text overrides auto-generated initials -->
<Avatar text="AB" />
<Avatar text="OK" />
<Avatar text="?" />

Icon Fallback

Use the icon prop for an Iconify icon fallback.

<Avatar icon="lucide:user" />
<Avatar icon="lucide:building" size="lg" />
<Avatar icon="lucide:bot" size="xl" />

Chip Indicator

Add a status chip with chip. Pass true for default or an object to customize.

U
U
U
U
<!-- Simple chip (default green) -->
<Avatar src="https://i.pravatar.cc/300?u=1" alt="User" chip />

<!-- Custom chip color -->
<Avatar src="https://i.pravatar.cc/300?u=2" alt="User" chip={{ color: 'error' }} />
<Avatar src="https://i.pravatar.cc/300?u=3" alt="User" chip={{ color: 'warning' }} />
<Avatar src="https://i.pravatar.cc/300?u=4" alt="User" chip={{ color: 'info' }} />

Styled Examples

Customize appearance with the ui prop.

S
CF
<Avatar
  src="https://i.pravatar.cc/300?u=11"
  alt="Styled"
  ui={{
    root: 'ring-2 ring-primary ring-offset-2 ring-offset-surface',
  }}
/>
<Avatar
  alt="Custom Fallback"
  ui={{
    fallback: 'bg-primary text-on-primary',
  }}
/>

Custom Children

Use the children snippet to render fully custom content inside the avatar.

<Avatar size="lg">
  <Icon name="lucide:user" class="size-5" />
</Avatar>

<Avatar size="lg" ui={{ root: 'bg-primary text-on-primary' }}>
  <Icon name="lucide:star" class="size-5" />
</Avatar>

<Avatar size="lg" ui={{ root: 'bg-success text-on-success' }}>
  <Icon name="lucide:check" class="size-5" />
</Avatar>

UI Slots

Use the ui prop to override classes on internal elements.

SlotDescription
rootRoot avatar container — controls size and shape
imageImage element — controls object-fit and rendering
fallbackFallback element — shown when image is unavailable
iconIcon element for icon fallback

Snippets

SnippetDescription
childrenCustom content inside the avatar — overrides image, text, and icon
fallbackCustom fallback content rendered when image is unavailable

Props

PropTypeDefault
size'3xs' | '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl''md'
srcstring-
altstring-
textstring-
iconstring-
rounded'full' | 'lg' | 'md' | 'sm' | 'none''full'
chipboolean | AvatarChipProps-
loading'lazy' | 'eager''eager'
delayMsnumber0
refHTMLDivElement-
classstring-
uiRecord<Slot, Class>-