---
title: "Avatar"
description: "An image with an accessible fallback for a person or team."
---

Interactive preview: https://ui.coderocket.app/docs/components/avatar

## Usage

Get this component from a [saved library export](/docs/export) or the [connected CLI](/docs/agents). The imports below refer to local files installed in your app.

Import `styles/components.css`, then `styles/theme.css` once. Wrap your app in `ThemeScope` from `components/ui/utils` so typography, focus and overlays share the theme. The [installation guide](/docs/export) covers runtime dependencies and React/Next.js setup.

```tsx
import { Avatar } from './components/ui/avatar';

<Avatar name="Alex Morgan"/>
```

## Design system

This component consumes your semantic colors, spacing, typography and shape tokens. Import the compiled styles and your theme once as described in [Export](/docs/export).

## Behavior and accessibility

- Provide meaningful labels for interactive controls.
- Connect action callbacks to your application logic.
- Verify keyboard navigation and contrast in your application.

Status: **experimental** during early access. Sample previews do not send emails, process payments or upload files to a service.

## Source and props

This is the exported source, using the same implementation as the editor.

```tsx
"use client";
import type { ComponentProps, CSSProperties } from "react";
import { Avatar as Base } from "@base-ui/react/avatar";
import { cx } from "./utils";
export function Avatar({
  src,
  name,
  size = 36,
  className,
  style,
  ...props
}: Omit<
  ComponentProps<typeof Base.Root>,
  "className" | "children" | "style"
> & {
  src?: string;
  name: string;
  size?: number;
  className?: string;
  style?: CSSProperties;
}) {
  const initials =
    name
      .trim()
      .split(/\s+/)
      .slice(0, 2)
      .map((word) => Array.from(word)[0] ?? "")
      .join("")
      .toLocaleUpperCase() || "?";
  return (
    <Base.Root
      {...props}
      className={cx("cr-avatar", className)}
      style={{ width: size, height: size, ...style }}
    >
      <Base.Image src={src} alt={name} className="cr-avatar-image" />
      <Base.Fallback role="img" aria-label={name || "Avatar"}>
        {initials}
      </Base.Fallback>
    </Base.Root>
  );
}
```
