Skip to content
omaris

Data Display

Avatar

Avatar — image, initials, or icon, in that order of preference.

import { Avatar } from 'omaris'
Learn

Examples

Fallbacks

Image, then initials, then an icon — in that order of preference, so a missing photo degrades instead of leaving a hole.

Omer Chetin Amina Yusuf RH
<script lang="ts">	import { Avatar } from 'omaris';</script>​<Avatar name="Omer Chetin" /><Avatar name="Amina Yusuf" colorize /><Avatar initials="RH" colorize /><Avatar>	<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">		<circle cx="12" cy="8" r="3.5" />		<path d="M4.5 20a7.5 7.5 0 0 1 15 0" stroke-linecap="round" />	</svg></Avatar>

Sizes shapes status

xs and sm for a table cell or a chip, lg and xl for a profile header; square for an organisation, a status dot for presence.

Hevi Salih Hevi Salih Hevi Salih Hevi Salih Hevi Salih Karwan Ali Dilan Karim Rania Hadi
<script lang="ts">	import { Avatar } from 'omaris';</script>​<Avatar size="xs" name="Hevi Salih" colorize /><Avatar size="sm" name="Hevi Salih" colorize /><Avatar size="md" name="Hevi Salih" colorize /><Avatar size="lg" name="Hevi Salih" colorize /><Avatar size="xl" name="Hevi Salih" colorize /><Avatar shape="square" name="Karwan Ali" colorize /><Avatar name="Dilan Karim" colorize status="online" /><Avatar name="Rania Hadi" colorize status="busy" />

Group

Give the group the same size as the avatars, or the overlap will not match.

Amina Yusuf Dilan Karim Hevi Salih Karwan Ali
Amina Yusuf Dilan Karim Hevi Salih
<script lang="ts">	import { Avatar, AvatarGroup } from 'omaris';</script>​<AvatarGroup overflow={12}>	<Avatar name="Amina Yusuf" colorize />	<Avatar name="Dilan Karim" colorize />	<Avatar name="Hevi Salih" colorize />	<Avatar name="Karwan Ali" colorize /></AvatarGroup>​<AvatarGroup size="sm">	<Avatar size="sm" name="Amina Yusuf" colorize />	<Avatar size="sm" name="Dilan Karim" colorize />	<Avatar size="sm" name="Hevi Salih" colorize /></AvatarGroup>

When to use it

Use it for

  • A person in a table row, a comment, an assignee on a card. src when there is a photo, name for initials when there is not, an icon in children when there is neither. The initials show until the image has decoded.
  • A team, an organisation, a product. shape="square" is the rounded square for things that are not people.
  • Presence. status="online", away, busy or offline puts a dot on the edge of the shape, at every size, without clipping it.
  • The people on a thread or a project, stacked. AvatarGroup with overflow for the trailing "+n".

Not for

  • A picture that is content, not identity, like a product photo → an <img>, or Image Viewer when it opens full screen.
  • A count or a status word beside a name → Badge. The presence dot is the only state an avatar carries.
  • Choosing a person from a list → Combobox with an Avatar in each row and the picked one as a Chip.
  • A decorative icon in a tinted circle on an empty screen → Empty, which draws that circle itself.

Do

  • Pass name even when src is set. It shows while the photo loads and stays if the URL 404s, so a broken image never leaves a hole.
  • Turn on colorize everywhere or nowhere. The hue comes from the name, so the same person is the same colour on every screen only if every avatar opts in.
  • Give AvatarGroup the same size as the avatars inside it. The overlap is per size and a mismatch shows at once.
  • Use xs and sm in a table cell or a chip, md in a list row, lg and xl in a profile header.

Don't

  • Add overflow-hidden on the root to round a photo. The media slot already clips, and the presence dot sits outside the root.
  • Write initials by hand unless the derived pair is wrong, like a mononym or a company name. "Ada L." already becomes "AL".
  • Stack more than about five in a group. That is what overflow is for.

Quick reference

size Avatar
  • sm
  • md (default)
  • lg
  • xl
shape Avatar
  • circle (default)
  • square
status Avatar
  • none (default)
  • online
  • away
  • busy
  • offline
size AvatarGroup
  • xs
  • sm
  • md (default)
  • lg
  • xl

API

Avatar

Avatar — image, initials, or icon, in that order of preference.

The image is only shown once it has actually decoded, so a broken or slow URL falls back to the initials instead of flashing a blank hole. Initials get a deterministic tint derived from the name, so the same person is the same color everywhere in the app.

import { Avatar } from 'omaris'

Parts

Every element this renders is reachable from outside. Pass Tailwind for one part as classes={{ part: '…' }}; class covers the root and is merged last, so it always wins.

root
Sizing, shape and the fallback colours live here — and nothing clips. The presence dot is a child of this box and is meant to sit proud of a circle's edge; overflow-hidden here is what used to shave a slice off it.
media
The clipping layer. Only the picture and the initials are cut to the shape, so the dot outside it survives.
image
No description in the source yet.
status
The ring that marks a live/away state, MD3 presence style.

Props

size

Defaults to 'md'

AvatarSize
sm
md
lg
xl
shape

Defaults to 'circle'

AvatarShape
circle
square
MD3's rounded square, for org and product avatars.
status

Defaults to 'none'

AvatarStatus

Presence dot in the bottom corner.

none
online
away
busy
offline
src
string
alt
string
name
string

Full name. Initials and the fallback tint are derived from it.

initials
string

Override the derived initials.

colorize

Defaults to false

boolean

Paint the initials fallback with the name-derived tint.

class
string
classes
AvatarClasses

Per-part Tailwind overrides. class still covers the root.

children
Snippet

Shown when there's no image and no name — an icon, usually.

AvatarGroup

A stack of overlapping avatars — the people on a thread, the members of a team.

Give it the same size as the avatars inside it, or the overlap will not match. overflow adds the trailing "+n" for the ones that did not fit.

import { AvatarGroup } from 'omaris'

Props

size

Defaults to 'md'

AvatarSize

Overlap amount. Must match the avatars' own size to look right.

xs
sm
md
lg
xl
overflow
number

Renders a "+n" chip after the children.

class
string
classes
ClassesOf<typeof avatarGroupVariants>

Tailwind per part.

children
Snippet