Skip to content
Components

Avatar

Avatar with thoughtful defaults, semantic styling, and editable source.

Open ↗

Make it yours.

Install the editable source and its dependencies into your React + Tailwind project.

Scroll horizontally for long lines
pnpm dlx shadcn@4.0.8 add http://localhost:3000/r/avatar.json

Use it

Scroll horizontally for long lines
"use client";
import {Avatar} from '@/components/jez-ui/ui/avatar';

export default function Example(){

return <><div className="grid justify-items-center gap-6"><div className="flex -space-x-3">{['AM','JL','SK','RT'].map((person,i)=><Avatar key={person} alt={['Alex Morgan','Jamie Lee','Sam Kim','Rory Tate'][i]} fallback={person} className="size-14 border-4 border-background bg-muted text-base"/>)}</div><div className="text-center"><h3 className="text-2xl">Better, together.</h3><p className="mt-2 text-sm text-muted-foreground">Four people. One shared idea.</p></div></div></>;
}

Props & types

Scroll horizontally for long lines
React.HTMLAttributes<HTMLSpanElement> & {
  src?: string;
  alt: string;
  fallback?: string;
}

Source

View 2 source files

registry/ui/avatar.tsx

Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
export function Avatar({
  src,
  alt,
  fallback = "JU",
  className,
  ...props
}: React.HTMLAttributes<HTMLSpanElement> & {
  src?: string;
  alt: string;
  fallback?: string;
}) {
  const [failed, setFailed] = React.useState(false);
  return (
    <span
      role={src && !failed ? undefined : "img"}
      aria-label={src && !failed ? undefined : alt}
      className={cn(
        "inline-flex size-10 shrink-0 items-center justify-center overflow-hidden rounded-full bg-accent text-[#171817] text-sm font-medium",
        className,
      )}
      {...props}
    >
      {src && !failed ? (
        <img
          src={src}
          alt={alt}
          onError={() => setFailed(true)}
          className="size-full object-cover"
        />
      ) : (
        fallback
      )}
    </span>
  );
}

registry/ui/utils.ts

Scroll horizontally for long lines
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...values: ClassValue[]) {
  return twMerge(clsx(values));
}

Dependencies

clsx@2.1.1 · tailwind-merge@3.5.0

Accessibility & behaviour

Provide meaningful labels and preserve keyboard focus styles. Check contrast when customising theme colours.

Read the accessibility and performance guide →