import { Avatar, AvatarGroup } from "@opengovsg/oui"<Avatar name="John Doe">
<Avatar.Image src="https://example.com/avatar.jpg" />
<Avatar.Fallback />
</Avatar>OUI exports 2 avatar-related components:
Avatar.Image and Avatar.Fallback.Use the size prop to change the size of the avatar. Available sizes are 2xs, xs, sm, and md.
Use the radius prop to change the border radius of the avatar.
Use the prominence and color props to customize the avatar's appearance.
strong (filled background) or subtle (light background)primary or whiteIf the image fails to load, the avatar will display a fallback. There are 2 fallback options:
name prop, the initials are generated from the name.name prop, a default user icon is displayed.

You can provide a custom fallback component to be displayed when the image fails to load.

You can customize the logic used to generate initials by passing a function to the getInitials prop. By default, we use the first character of each word in the name prop.
<Avatar
name="John Doe"
getInitials={(name) =>
name
.split(" ")
.map((n) => n[0])
.join("")
.toUpperCase()
}
>
<Avatar.Image src="https://example.com/avatar.jpg" />
<Avatar.Fallback />
</Avatar>Use the AvatarGroup component to display a group of avatars together.
You can limit the number of avatars displayed by passing the max prop to the AvatarGroup component.
You can display the total number of avatars by passing the total prop to the AvatarGroup component. This is useful when you have more avatars than what you're displaying.
AvatarGroup provides a renderCount prop to customize the count displayed.
+10 others
Avatar has the following attributes on the base element:
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | - | The avatar content (Image and Fallback) |
| name | string | - | The name used for initials and alt text |
| size | "2xs" | "xs" | "sm" | "md" | "md" | The size of the avatar |
| radius | "none" | "sm" | "md" | "lg" | "full" | "full" | The border radius of the avatar |
| prominence | "strong" | "subtle" | "strong" | The visual prominence of the avatar |
| color | "primary" | "white" | "primary" | The color scheme of the avatar |
| getInitials | (name: string) => string | - | Custom function to generate initials from name |
| classNames | Record<Slot, string> | - | Classes to apply to each slot |
| Prop | Type | Description |
|---|---|---|
| src | string | The image source URL |
| ... | - | All native img attributes |
| Prop | Type | Description |
|---|---|---|
| children | ReactNode | Custom fallback content (defaults to icon/initials) |
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | - | The avatars to display |
| max | number | 5 | Maximum number of visible avatars |
| total | number | - | Total count (for calculating overflow) |
| size | "2xs" | "xs" | "sm" | "md" | - | Size applied to all avatars |
| color | "primary" | "white" | - | Color applied to all avatars |
| prominence | "strong" | "subtle" | - | Prominence applied to all avatars |
| radius | "none" | "sm" | "md" | "lg" | "full" | - | Radius applied to all avatars |
| renderCount | (count: number) => ReactNode | - | Custom render function for overflow count |
| classNames | Record<"base" | "count", string> | - | Classes to apply to each slot |
You can use the Avatar component as a trigger for a Menu to create a user profile menu.