Avatar

An image element with a fallback for representing the user, featuring built-in loading and error states.

Preview

Avatar
TypeScript
@

Installation

bash
bash
1
npx shadcn@latest add https://fysk.dev/r/avatar.json

Usage

tsx
tsx
1
import { Avatar } from "@/components/ui"
2
3
<Avatar src="https://github.com/ameghcoder.png" fallback="FY" />

Examples

Default

Standard circular avatar with image and fallback.

Component
TypeScript

With Image

FY

No Image - Fallback

FD

Mutliple sizes

Mutliple sizes of avatar.

Component
TypeScript

Default

SSSS

Outline

AAAA

Features

  • Built-in States: Integrated loading (shows a loader) and error (shows alert icon) feedback.

  • Auto-Initials: Automatically extracts initials from the alt prop if no image is found and no fallback is provided.

  • Glassmorphism: Fallbacks and state overlays feature subtle blurs and modern backgrounds.

  • Responsive Sizing: Six pre-configured sizes from xs to 2xl.

Props

The Avatar component accepts the following props:

PropTypeDefaultDescription
size"xs" | "sm" | "md" | "lg" | "xl" | "2xl""md"The visual size of the avatar.
variant"default" | "outline" | "ghost" | "glass""default"Visual style of the border/container.
state"idle" | "loading" | "error""idle"Current interaction or async state.
srcstring-Image source URL.
altstring-Accessible name and source for auto-initials.
fallbackReact.Node-Custom content for the fallback state.

Accepts all standard props from @radix-ui/react-avatar.

Built with 💖 | Created by Yashraj