Skip to content

Avatar

The Avatar component is used to represent a user, and displays the profile picture, initials or fallback icon.

Installation

sh
npm add @heroui-vue/avatar
sh
pnpm add @heroui-vue/avatar
sh
yarn add @heroui-vue/avatar
sh
bun add @heroui-vue/avatar

NOTE

If you use global installation, you can skip this step.

Import

HeroUI Vue currently exports 2 avatar-related components:

  • Avatar: The main component to display an avatar.
  • AvatarGroup: A wrapper component to display a group of avatars.

AvatarIcon is still not exported as a standalone component in HeroUI Vue. You can use the built-in fallback icon or provide a custom icon.

js
import { Avatar, AvatarGroup } from '@heroui-vue/avatar'
js
import { Avatar, AvatarGroup } from 'heroui-vue'

Usage

avatarJavatarJavatarJ

Sizes

avataravataravataravataravatar

Disabled

avatarJavatarJavatarJ

Bordered

avataravataravataravataravataravatar

Radius

avataravataravataravatar

Colors

avataravataravataravataravataravatar

Avatar Fallbacks

If there is an error loading the src of the avatar, there are 2 fallbacks:

  • If there's a name prop, we use it to generate the initials.
  • If there's no name prop, we use a default avatar icon.

If showFallback is not passed, the fallbacks will not be displayed.

avatarJaneJoe

Custom Fallback

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

avatarJaneJoe

Custom Implementation

In case you need to customize avatar behavior further, HeroUI Vue currently keeps useAvatar as an internal composition utility and does not expose it as a stable public API yet.

Custom initials logic

HeroUI React supports getInitials for custom initials logic. HeroUI Vue does not expose this prop yet; by default initials are derived from the first characters of up to two words in name.

Avatar Group

avataravataravataravataravataravatar

Group Disabled

avataravataravataravataravataravatar

Group Max Count

You can limit the number of avatars displayed by passing the max prop to the AvatarGroup component.

avataravataravatar+3

Group Total Count

You can display the total number of avatars by passing the total prop to the AvatarGroup component.

avataravataravatar+7

Group Custom count

HeroUI React supports renderCount as a render function. HeroUI Vue currently supports renderCount as a boolean switch to show/hide the built-in count badge.

avataravataravatar

Group Grid

By passing the isGrid prop to the AvatarGroup component, avatars will be displayed in a grid layout.

avataravataravataravataravataravataravatar+2

Group Custom Implementation

In case you need lower-level customization, HeroUI React exposes useAvatarGroup and AvatarGroupProvider. HeroUI Vue has not exposed equivalent public APIs yet.

Slots

  • base: Avatar wrapper, it includes styles for focus ring, position, and general appearance.
  • img: Image element within the avatar, it includes styles for opacity transition and size.
  • fallback: Fallback content when the image fails to load or is not provided, it includes styles for centering the content.
  • name: Initials displayed when the image is not provided or fails to load, it includes styles for font and text alignment.
  • icon: Icon element within the avatar, it includes styles for centering the content and size.

Custom Avatar Styles

You can customize any part of the avatar by using the classNames prop.

Data Attributes

Avatar has the following attributes on the base element:

  • data-hover: When the avatar is being hovered.
  • data-focus: When the avatar is being focused.
  • data-focus-visible: When the avatar is being focused with keyboard navigation.

API

Avatar Props

NameTypeDefaultDescription
srcstring-The source URL of the image to be displayed.
color"default" | "primary" | "secondary" | "success" | "warning" | "danger""default"Sets the avatar background color.
radius"none" | "sm" | "md" | "lg" | "full""full"Sets the avatar border radius.
size"sm" | "md" | "lg""md"Sets the avatar size.
namestring-Displays initials if the image is not provided or fails to load.
iconany-Displays a custom icon inside the avatar fallback.
fallbackany-A custom fallback component to display when the image fails to load.
isBorderedbooleanfalseIf true, adds a border around the avatar.
isDisabledbooleanfalseIf true, disables the avatar and applies disabled styling.
isFocusablebooleanfalseIf true, makes the avatar focusable for keyboard navigation.
showFallbackbooleanfalseIf true, shows fallback icon/initials when image fails to load.
imgPropsImgHTMLAttributes-Props passed to the internal image element.
classNamesPartial<Record<"base" | "img" | "fallback" | "name" | "icon", string>>-Custom class names for avatar slots.

Avatar Group Props

NameTypeDefaultDescription
maxnumber-The maximum number of visible avatars.
totalnumber-Controls the number of avatars not visible.
isGridbooleanfalseWhether avatars should be displayed in a grid.
renderCountbooleantrueWhether to render the built-in count badge.
classNamesPartial<Record<"base" | "count", string>>-Custom class names for avatar group slots.

MIT Licensed