Avatar

A graphical representation of a user or entity, typically displaying an image or initials as a fallback.

Anatomy

<script>
  import { Avatar } from "@saas-ui/svelte/components/avatar";
</script>

<!-- Avatar with image -->
<Avatar src="https://example.com/avatar.jpg" name="John Doe" />

<!-- Avatar with fallback initials -->
<Avatar name="John Doe" />

<!-- Avatar group -->
<Avatar.Group>
  <Avatar src="user1.jpg" name="User 1" />
  <Avatar src="user2.jpg" name="User 2" />
  <Avatar src="user3.jpg" name="User 3" />
</Avatar.Group>

Examples

Basic Accessibility

Basic avatar displaying an image with default styling.

Colours Accessibility

Use the colour prop to change the colour scheme. Supports all standard colour palettes.

Fallback Accessibility

Avatar with fallback initials or icon when no image is provided or fails to load.

Group Accessibility

Use Avatar.Group to display multiple avatars together in a stacked layout.

Shape Accessibility

Use the shape prop to change the shape of the avatar. Available shapes: square, rounded, full.

Sizes Accessibility

Use the size prop to change the size of the avatar. Available sizes: 2xs, xs, sm, md, lg, xl, 2xl.

Stacking Accessibility

Use the stacking prop with first-on-top or last-on-top to control avatar stacking order.

Variants Accessibility

Use the variant prop to change the visual style. Available variants: solid, subtle, outline.

With Ring Accessibility

Use the ring prop to show a ring around the avatar, useful for indicating status or selection.

Props

Avatar

The main avatar component.

Prop Type Default Description
src string - The image source of the avatar.
name string - The name of the person in the avatar. Used for the alt text and fallback initials.
size "2xs" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "full" "md" The size of the avatar.
variant "solid" | "subtle" | "outline" "solid" The visual style of the avatar.
shape "square" | "rounded" | "full" "full" The shape of the avatar.
colour ColourName "gray" The colour palette of the avatar.
ring boolean false Whether to show a ring around the avatar using the colour palette.
fallback string | Snippet - Custom fallback content. Can be a string (like "+3") or a Snippet.
class string - Additional CSS classes to apply.
style string - Inline styles to apply via the style attribute.
children Snippet - Any children to render (rarely used directly, usually fallback).

Avatar.Group

A container for grouping multiple avatars together in a stacked layout.

Prop Type Default Description
size "2xs" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "full" "md" The size of the avatars in the group.
stacking "first-on-top" | "last-on-top" "last-on-top" The stacking order of the avatars.
spaceX "1" | "2" | "3" | "4" - The spacing between avatars.
borderless boolean false Whether the avatars should have a border.
class string - Additional CSS classes.
style string - Inline styles.
children Snippet - The avatars to render in the group.