Skip to content
portalbits
Home Docs GitHub(opens in a new tab)

Guides

Get startedFoundationsMotion

Components

All components

Buttons

ButtonIconButton

Inputs

InputSelectTextareaSlider

Selection

CheckboxToggleToggleGroupSwitchRadioGroup

Identity

AvatarBadge

Overlays

DialogPopoverTooltipDropdownMenuAlertDialog

Disclosure

TabsAccordion

Cards

AppCardArticleCardFeatureCard

Content

CarouselSectionHeaderEmptyStateAlertProgressSeparatorRowListRow

Chrome

PortalShellSidebarNavMobileNavTopBarAuthFrameColorSelectorFloatingNav

Avatar

A face, initials, or a fallback when the image is missing.

Orbit Studio OS
Variations

Source

<script lang="ts">
  import 'portal-bits/styles.css';
  import 'portal-bits/tokens.css';
  import type { Snippet } from 'svelte';

  let { children }: { children: Snippet } = $props();
</script>

{@render children()}
<script lang="ts">
  import AvatarExample from './AvatarExample.svelte';
</script>

<AvatarExample size={40} media={"image"} />
<script lang="ts">
  import { Avatar } from 'portal-bits';
  let { size = 40, media = 'image' }: { size?: 32 | 40 | 56; media?: 'image' | 'broken' | 'none' } =
    $props();

  // A synthetic poster as inline SVG data. Pass your own image URL as `src` instead.
  const poster = `data:image/svg+xml,${encodeURIComponent(
    '<svg xmlns="http://www.w3.org/2000/svg" width="160" height="160"><rect width="160" height="160" fill="#c5d4f6"/><circle cx="80" cy="80" r="44" fill="none" stroke="#263864" stroke-width="4"/></svg>',
  )}`;
  const sources = {
    image: poster,
    // A path your app does not serve, so the fallback initials appear.
    broken: '/missing-avatar.png',
    none: undefined,
  };
</script>

{#key media}
  <Avatar alt="Orbit Studio" src={sources[media]} {size} />
{/key}

API reference

These tables list the props and snippets that Avatar declares. Attributes passed through to an element or primitive are listed under Forwarded attributes, not here.

Props

NameTypeDefaultRequiredBindingDescription
srcstringNoneNoOne-wayThe image URL. When it is missing or fails, the fallback shows.
altstringNoneYesOne-wayThe accessible name. Also the source of the default initials.
fallbackstringNoneNoOne-wayText for the fallback. Without it, the first letters of the first two words of `alt`.
sizenumber40NoOne-wayWidth and height in pixels.
decorativebooleanfalseNoOne-wayRemoves the avatar from the accessibility tree. Use it when nearby text names the same thing.

Forwarded attributes

None. Avatar forwards no attributes.

The primitive underneath is a Bits UI peer dependency. Its own options are documented in the Bits UI Avatar documentation. Only the props listed on this page are part of the Avatar contract. No data attributes are documented as stable.

Limits

  • The component forwards no attributes, so it takes no `class`. Size it with `size`.
  • Initials come from `alt` unless you supply `fallback`. Names that begin with a symbol give odd initials.

Related

  • Badge
  • AppCard
Previous RadioGroup Next Badge

On this page

  • Preview
  • Source
  • API reference
  • Props
  • Forwarded attributes
  • Limits