Avatar
Avatar displays a user or entity with an image, initials fallback, or placeholder icon.
Import
import { Avatar } from "@tosui/react";
Basic Usage
- Code
- Preview
<Avatar src="https://i.pravatar.cc/150?img=1" name="John Doe" />
Sizes
- Code
- Preview
<HStack gap={4} align="center">
<Avatar size="sm" name="John Doe" />
<Avatar size="md" name="John Doe" />
<Avatar size="lg" name="John Doe" />
<Avatar size="xl" name="John Doe" />
</HStack>
JD
JD
JD
JD
Initials Fallback
When no image is provided, Avatar shows initials from the name.
- Code
- Preview
<HStack gap={4}>
<Avatar name="John Doe" />
<Avatar name="Jane Smith" />
<Avatar name="Alice" />
<Avatar name="Bob Builder" />
</HStack>
JD
JS
A
BB
Placeholder
When no name or image is provided, a placeholder icon is shown.
- Code
- Preview
<Avatar />
Rounded Variants
- Code
- Preview
<HStack gap={4}>
<Avatar rounded="full" name="John Doe" />
<Avatar rounded="md" name="Jane Smith" />
</HStack>
JD
JS
Image Error Fallback
If the image fails to load, Avatar falls back to initials.
<Avatar
src="https://broken-url.example/image.jpg"
name="John Doe"
/>
// Falls back to "JD" initials
Common Patterns
Avatar with Name
- Code
- Preview
<HStack gap={3} align="center">
<Avatar size="md" name="John Doe" />
<VStack gap={0} align="flex-start">
<Box fontWeight="medium">John Doe</Box>
<Box fontSize="sm" color="foreground-muted">john@example.com</Box>
</VStack>
</HStack>
JD
John Doe
Avatar Group
- Code
- Preview
<HStack gap={-2}>
<Avatar name="Alice" size="md" />
<Avatar name="Bob" size="md" />
<Avatar name="Carol" size="md" />
<Avatar name="Dan" size="md" />
</HStack>
A
B
C
D
Props Reference
| Prop | Type | Default | Description |
|---|---|---|---|
| src | string | - | Image source URL |
| name | string | - | Name for initials fallback |
| size | "sm" | "md" | "lg" | "xl" | "md" | Avatar size |
| rounded | "full" | "md" | "full" | Border radius |
| alt | string | name or "Avatar" | Alt text for image |
Size Dimensions
| Size | Dimensions |
|---|---|
| sm | 32px |
| md | 40px |
| lg | 48px |
| xl | 64px |
TypeScript
import { Avatar, type AvatarSize, type AvatarProps } from "@tosui/react";