Skip to content
Klarhimmel UI

Avatar

ML
npx shadcn add @klarhimmel/avatar

Examples

  • Image

  • Sizes

  • Fallback

DetailsAbout, usage, props and more

A person or team as a photo, or as initials on a colour picked from the name.

When to use

  • Use for

    Next to a name in lists, comments, headers and assignee pickers.

  • Not for

    Logos and product images. Use Media.

  • Pairs with

    Badge, Card, a name in text.

Preview

Photo, photo, a photo that failed to load (initials), and a square for a team.

avatar.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { Avatar } from '@/components/klarhimmel/ui/avatar';

export default function Example() {
  return (
    <Theme theme="brand">
      <Avatar name="Maja Lindqvist" src="/people/maja.jpg" />
    </Theme>
  );
}

Import

Import

import { Avatar } from '@/components/klarhimmel/ui/avatar';
Files
avatar.tsx, in components/klarhimmel/ui/. With it: theme, utils.
Render in
Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

Props

PropTypeDefaultDescription
namestringrequiredWhose face this is. Becomes the accessible name and the initials.
sizekeyof typeof sizes'md'24, 32, 40 and 56 px.
squareboolean-A rounded square, for teams and organisations.
srcstring-A photo. Falls back to initials if it is missing or fails to load.
srcSetstring-A photo. Falls back to initials if it fails to load.
decorativeboolean-Hide it from assistive tech when the name is written next to it.
classNamestring-Extra classes, merged after the component's own.

Accessibility

KeyDoes
TabSkips it: an avatar is not interactive
Screen readerReads the name. With decorative set, it reads nothing

Not interactive. Wrap it in a link or button yourself if it should be.

Accessibility