Keyframery

Avatar

Photos fade up out of a blur once loaded, and stacked avatars spring apart on hover.

See it as an AI agent does.

Resize preview. Focus the handle and use the left or right arrow keys. Hold Shift for larger steps.— px
Customize1 controls
Animation speed1×

Installation

npx shadcn@latest add @keyframery/avatar

This adds components/keyframery/avatar.tsx and its primitive to your project, and installs UI SDK. The motion tokens are added to your global CSS the first time you install a component.

Usage

import { Avatar, AvatarFallback, AvatarImage } from "@/components/keyframery/avatar"

export default function Usage() {
  return (
    <Avatar>
      <AvatarImage src="/avatars/ruth.jpg" alt="Ruth Ellis" />
      <AvatarFallback>RE</AvatarFallback>
    </Avatar>
  )
}

Anatomy

How the parts fit together:

Avatar
├── AvatarImage
└── AvatarFallback

Examples

Sizes

sm, md and lg. The initials show while the photo loads, or if it never does.

Fallback

Without a photo, or when it fails to load, the fallback shows. delay waits before showing it, so fast photos don't flash initials first.

Group

AvatarGroup overlaps them, and AvatarGroupCount says how many more there are. Hover one to lift it.

Motion

MoveWhat you see
FadeThe photo clears out of a blur once it has loaded.
SpringIn a group, the avatar you point at rises and its neighbours make room.

Timing and springiness follow the motion style you set. To change how fast this avatar moves, pass speed:

<Avatar speed="fast">
  …
</Avatar>

"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.

Theming

Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.

VariableWhat it changesDefault
--avatar-sizeDisc size by variant1.5rem / 2rem / 2.5rem (sm / md / lg)
--avatar-radiusDisc cornerscalc(infinity * 1px)
--avatar-faceFallback and count surface--muted
--avatar-inkInitials and count text--muted-foreground
--avatar-ringGroup separator ring--background (group)
--avatar-overlapNegative group spacing-0.25rem

API reference

Every part takes className and children. Parts from UI SDK also take render, to draw your own element, and a function of their state for className and style. Props not listed here are in the UI SDK avatar reference.

Avatar

Renders a <div>, and takes its props too.

Prop

Type

AvatarFallback

Renders a <span>, and takes its props too.

Prop

Type

AvatarGroupCount

Renders a <span>, and takes its props too.

Prop

Type

Other parts

These take the props of the element they render, and nothing else:

  • AvatarImage: a <img>
  • AvatarGroup: a <div>

Accessibility

Keyboard, focus and screen-reader behaviour come from UI SDK and are not changed. More in Accessibility.

Swap the import

Already using UI SDK's avatar with your own styles? Keep your markup and change one line. The primitive adds motion and nothing else.

// Before
import { … } from "@ui-sdk/react/avatar"

// After: same parts, same props, now animated
import { … } from "@/components/keyframery/primitives/avatar"

Questions

How does the animated Avatar for UI SDK move?

Fade: The photo clears out of a blur once it has loaded. Spring: In a group, the avatar you point at rises and its neighbours make room.

Do I need Motion or Framer Motion for the animated Avatar?

No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.

Can I keep my own styling and only take the motion?

Yes. Import from @/components/keyframery/primitives/avatar instead. It has the same parts and props as @ui-sdk/react/avatar and adds motion only.

What happens to the Avatar when someone turns on reduced motion?

Nothing moves. State changes happen at once, or with a short fade.

All components

On this page