PeakUI

Avatar

Shows a profile image with a fallback

Usage

import {Avatar} from "@peakui/react";

Anatomy

import {Avatar} from "@peakui/react";

export default () => (
  <Avatar>
    <Avatar.Image />
    <Avatar.Fallback />
  </Avatar>
);

Examples

Sizes

Colors

color sets the fallback text color.

Variants

soft adds a tinted fallback background.

Fallback Content

Avatar.Fallback shows while the image loads, fails, or is absent.

Accessible Name

A fallback-only avatar has no accessible name; role="img" with aria-label gives it one.

Customization

Tailwind CSS

Global CSS

Set --avatar-size whenever you resize an avatar: AvatarGroup's clip mask is cut from it.

@layer components {
  .avatar--lg {
    --avatar-size: 4rem;
    @apply size-16;
  }

  .avatar__fallback {
    @apply bg-accent text-accent-foreground;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The Avatar component uses these CSS classes (view source styles):

Base & Element Classes

  • .avatar - Base container with the default size (size-10)
  • .avatar__image - Image, stretched over the container
  • .avatar__fallback - Centered fallback content

Size Classes

  • .avatar--sm - Small size (size-8)
  • .avatar--md - Medium size, the default
  • .avatar--lg - Large size (size-12)

Variant Classes

  • .avatar--soft - Soft variant with a tinted fallback

Color Classes

  • .avatar__fallback--default
  • .avatar__fallback--accent
  • .avatar__fallback--success
  • .avatar__fallback--warning
  • .avatar__fallback--danger

Slots

  • [data-slot="avatar"]
  • [data-slot="avatar-image"]
  • [data-slot="avatar-fallback"]

CSS Variables

VariablePurpose
--avatar-sizeDiameter, set by the size classes (2rem, 2.5rem, 3rem); read by the AvatarGroup clip mask

API Reference

Avatar

PropTypeDefaultDescription
size'sm' | 'md' | 'lg''md'Size of the avatar
color'default' | 'accent' | 'success' | 'warning' | 'danger''default'Color of the fallback
variant'default' | 'soft''default'Visual style
classNamestring-Additional classes
...restEvery <span> attribute is accepted

Avatar.Image

PropTypeDefaultDescription
srcstring-Image address; the image renders once it has loaded
altstring-Alternative text
srcSetstring-Responsive image sources
sizesstring-Responsive image sizes
crossOrigin'anonymous' | 'use-credentials'-CORS setting of the request
referrerPolicyHTMLAttributeReferrerPolicy-Referrer policy of the request
renderDOMRenderFunction<'img', undefined>-Replaces the rendered <img>, such as with a framework image component; pass src so loading is still tracked
onLoadingStatusChange(status: 'idle' | 'loading' | 'loaded' | 'error') => void-Called as the loading status changes
classNamestring-Additional classes
...restEvery <img> attribute is accepted

Avatar.Fallback

PropTypeDefaultDescription
delayMsnumber-Delay before the fallback renders, so a fast image never flashes it
color'default' | 'accent' | 'success' | 'warning' | 'danger'-Overrides the color of the Avatar
classNamestring-Additional classes
...restEvery <span> attribute is accepted

On this page