Avatar

A person's picture, with initials when there is none — alone, in a group, with a status badge. In the look of the app's style.

Data DisplayExperimental

Usage

import { Component, ViewEncapsulation } from '@angular/core';import {  ScAvatar,  ScAvatarFallback,  ScAvatarImage,} from '@semantic-components/ui';
@Component({  selector: 'app-avatar-usage-demo',  imports: [ScAvatar, ScAvatarFallback, ScAvatarImage],  template: `    <span scAvatar>      <img scAvatarImage src="https://github.com/shadcn.png" alt="@shadcn" />      <span scAvatarFallback>CN</span>    </span>  `,  host: { class: 'flex w-full justify-center' },  encapsulation: ViewEncapsulation.None,})export class AvatarUsageDemo {}

Anatomy

Every part is a directive on your element. The image and the fallback fill the avatar, the image on top.

import {  ScAvatar, ScAvatarImage, ScAvatarFallback, ScAvatarBadge,  ScAvatarGroup, ScAvatarGroupCount,} from '@semantic-components/ui';
<div scAvatarGroup>  <span scAvatar size="lg">    <img scAvatarImage src="…" alt="…" />    <span scAvatarFallback>…</span>    <span scAvatarBadge></span>  </span>  <div scAvatarGroupCount>+3</div></div>

Loading

  • The image is rendered at once and loads in place, so loading="lazy" and NgOptimizedImage work. Until it has loaded, and if it fails, it is invisible (data-loading, data-error) and the fallback shows through.
  • Hidden with visibility, not display: none: an element with no box never enters the viewport, and a lazy image would never load.
  • Rendered on the server, an image that loads before the app wakes up is seen as loaded — its load event has gone by then.
  • Loading, the image is not read: the fallback names the avatar. Give the image an alt for when it shows.

Examples

Basic

Jordan LeeJL
import { Component, ViewEncapsulation } from '@angular/core';import {  ScAvatar,  ScAvatarFallback,  ScAvatarImage,} from '@semantic-components/ui';
/** An image over its fallback; loaded lazily, it still shows (it is hidden by visibility, not display, while it loads). */@Component({  selector: 'app-basic-avatar-demo',

Fallback

@jdoeJDAB
import { Component, ViewEncapsulation } from '@angular/core';import {  ScAvatar,  ScAvatarFallback,  ScAvatarImage,} from '@semantic-components/ui';
/** The fallback while the image loads, when it fails, or with no image. */@Component({  selector: 'app-fallback-avatar-demo',

Badge

@shadcnCN
import { Component, ViewEncapsulation } from '@angular/core';import {  ScAvatar,  ScAvatarBadge,  ScAvatarFallback,  ScAvatarImage,} from '@semantic-components/ui';
/** A badge in the corner: a status, in your color. */@Component({

Badge with Icon

@pranathipPP
import { Component, ViewEncapsulation } from '@angular/core';import {  ScAvatar,  ScAvatarBadge,  ScAvatarFallback,  ScAvatarImage,} from '@semantic-components/ui';import { SiPlusIcon } from '@semantic-icons/lucide-icons';
@Component({

Avatar Group

@shadcnCN@maxleiterLR@evilrabbitER
import { Component, ViewEncapsulation } from '@angular/core';import {  ScAvatar,  ScAvatarFallback,  ScAvatarGroup,  ScAvatarImage,} from '@semantic-components/ui';
/** Overlapping, each ringed by the background. */@Component({

Avatar Group Count

@shadcnCN@maxleiterLR@evilrabbitER
+3
import { Component, ViewEncapsulation } from '@angular/core';import {  ScAvatar,  ScAvatarFallback,  ScAvatarGroup,  ScAvatarGroupCount,  ScAvatarImage,} from '@semantic-components/ui';
/** How many more, after the avatars shown. */

Avatar Group with Icon

@shadcnCN@maxleiterLR@evilrabbitER
import { Component, ViewEncapsulation } from '@angular/core';import {  ScAvatar,  ScAvatarFallback,  ScAvatarGroup,  ScAvatarGroupCount,  ScAvatarImage,} from '@semantic-components/ui';import { SiPlusIcon } from '@semantic-icons/lucide-icons';

Sizes

@shadcnCN@shadcnCN@shadcnCN
import { Component, ViewEncapsulation } from '@angular/core';import {  ScAvatar,  ScAvatarFallback,  ScAvatarImage,} from '@semantic-components/ui';
/** size: sm, default, lg. */@Component({  selector: 'app-sizes-avatar-demo',

Dropdown

import { Component, ViewEncapsulation } from '@angular/core';import {  ScAvatar,  ScAvatarFallback,  ScAvatarImage,  ScButton,  ScMenu,  ScMenuContent,  ScMenuItem,  ScMenuPortal,

RTL

@shadcnش
@shadcnش@maxleiterم
+٣
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import {  ScAvatar,  ScAvatarBadge,  ScAvatarFallback,  ScAvatarGroup,  ScAvatarGroupCount,  ScAvatarImage,} from '@semantic-components/ui';

API reference

Each part takes class, merged over the style (cn: a later class wins).

PartSelectorDescription
ScAvatarspan[scAvatar] The avatar: round, with a thin outline. Input size: 'sm', 'default' or 'lg'. data-image: the image's state.
ScAvatarImageimg[scAvatarImage] The picture, over the fallback; invisible while it loads and if it fails (data-loading, data-error).
ScAvatarFallbackspan[scAvatarFallback] Initials or an icon: shown until the image has loaded, or with none.
ScAvatarBadgespan[scAvatarBadge] A dot in the corner (a status, your color), or a small icon; sized by the avatar.
ScAvatarGroupdiv[scAvatarGroup] Avatars overlapping, each ringed by the background; mirrored right to left.
ScAvatarGroupCountdiv[scAvatarGroupCount] How many more, after the group's avatars: text or an icon, sized by them.