Avatar
Visual component for representing users with support for images, text initials, and status indicators. Available in multiple sizes and shapes with customizable borders and backgrounds.
Installation
Add Avatar to your project with the CK-UI CLI. It copies the source into your project, so the code is yours to change.
- Adds
Avatar.tsxto your CK-UI folder (src/components/ck-ui by default)- Installs
@radix-ui/react-avatarif your project does not have them yet
First time with CK-UI in this project? Run npx ck-ui-cli@latest init once before adding components. The installation guide explains what it sets up.
Manual installationInstall the packages and copy the files yourself.
Install the following dependencies
Run these commands in your terminal to install the required packages
Create or update your Avatar component
Copy this code to create your Avatar component
Test Your Component
- 1. Add the component to a test page
- 2. Check all props and variants work as expected
- 3. Verify responsive behavior
- 4. Test with different content/data
- 5. Ensure accessibility features work correctly
Sizes
Choose a predefined size (`xs` to `xl`) or pass Tailwind size classes, from large profile displays to compact navigation elements and lists.
Shape square
Use the `shape="square"` prop to create square-shaped avatars. This option is particularly useful for uniform layouts or when you need a consistent visual style across your application.
Placeholder image
Create minimal avatar placeholders by omitting the image or text content. If an image fails to load, Avatar.Image shows its fallback instead. Set custom backgrounds using standard Tailwind classes (like "bg-gray-100" or "bg-blue-50") through the background prop or className. Perfect for loading states or default user representations.
With text
Add text initials to avatars for quick identification. Use the `text` prop to set the text content or the `className` prop to customize the text style.
Custom border
Add custom borders to avatars for visual differentiation. Use the `border` prop to add a border and the `className` prop to set its color or width.
With background
Add custom backgrounds to avatars for visual differentiation. Use the `background` prop to set the background color or the `className` prop to customize the background style.
With indicator
Add indicators to avatars for additional information. Place content in `Avatar.Indicator` and use its `position` prop (top or bottom) or the `className` prop to customize it.
Other example with custom icons
Enhance avatars with custom status indicators using icon components. Combine colored indicators with appropriate icons to represent various states like favorites, pinned items, approved status, or errors. Perfect for interactive user lists and activity feeds.
Stacked
Stack multiple avatars to display a group of users or entities. Wrap them in a flex container with negative spacing (e.g. `-space-x-4`) and give each avatar a border in the background colour.
API Reference
The Avatar component provides a flexible way to display user avatars with various styling options.
Avatar.Root
Container element that holds all avatar components and provides common styling.
| Prop | Type | Default | Description |
|---|---|---|---|
size | "xs""sm""md""lg""xl""string" | "lg" | xs 24px · sm 32px · md 40px · lg 56px · xl 80px, or Tailwind size classes such as "size-12" |
type | "image""text" | "image" | Placeholder shown when the avatar has no children: a person silhouette (image) or a user icon (text) |
border | "boolean" | "false" | Adds a 1px border; set the colour with className (e.g. border-blue-500) |
background | "string" | "bg-transparent" | Background classes |
shape | "rounded""square" | "rounded" | Circle or rounded square. Avatar.Image follows the root's corner radius. |
className | "string" | "undefined" | Additional CSS classes for the avatar element, merged last |
Avatar.Image
Displays an image within the avatar with proper sizing and fallback handling. Must be rendered inside Avatar.Root.
| Prop | Type | Default | Description |
|---|---|---|---|
src | "string" | "undefined" | URL of the image. The <img> is rendered once the image has loaded. |
alt | "string" | """" | Empty by default (decorative), which suits avatars shown next to the person's name. Pass the name when the avatar is the only identification. |
lazy | "boolean" | "false" | Sets loading="lazy" on the rendered <img> |
fallback | "ReactNode" | "user icon" | Shown while the image loads, if it fails, or without src. Pass null to render nothing. |
Avatar.Text
Displays text (typically initials) when an image is not available or preferred.
| Prop | Type | Default | Description |
|---|---|---|---|
text | "string" | "undefined" | Text content to display (typically initials); falls back to children |
Avatar.Status
Adds a colored dot indicator to show user status (online, away, busy, etc.).
| Prop | Type | Default | Description |
|---|---|---|---|
color | "string" | "bg-green-500" | CSS class for the status indicator color |
position | "top""bottom" | "bottom" | Position of the status indicator |
aria-label | "string" | "undefined" | Accessible name, e.g. "Online". Without it the dot is decorative (aria-hidden). |
Avatar.Indicator
Allows for custom indicators like badges or icons to be placed on the avatar.
| Prop | Type | Default | Description |
|---|---|---|---|
children | "ReactNode" | "undefined" | Custom indicator content |
position | "top""bottom" | "bottom" | Position of the custom indicator |
className | "string" | "undefined" | Additional CSS classes |
Used in these blocks
Block families with at least one block built on this component. Each page previews its blocks and lists the components and packages they use.