Avatar
Displays a user or entity image with a fallback option.
First release: 1.0.0 Latest update: July 1, 2025 Current version: 1.0.0
Import
import { PlusAvatar } from '@plusui/react';import { PlusAvatarComponent } from '@plusui/angular';import { PlusAvatar } from '@plusui/vue';import PlusAvatar from '@plusui/svelte';<script src="https://cdn.jsdelivr.net/npm/@plusui/core"></script>Package
@plusui/react@plusui/angular@plusui/vue@plusui/svelte@plusui/coreDocs
Changelog
Avatar Changelog
Recent changes and updates for the avatar component
v1.0.0
Added Avatar component for user representation
- Image, icon, and text fallbacks
- Multiple sizes: xs, sm, md, lg, xl
- Circle and square shapes
- Inverted color scheme support
The Avatar component displays an image representing a user or entity. It supports images, icons, or initials as fallback content when an image isn’t available or fails to load.
Anatomy
Section titled “Anatomy”
Basic Example
Section titled “Basic Example”import { PlusAvatar } from '@plusui/react';
export default () => { return ( <> <PlusAvatar image="https://i.pravatar.cc/50" alt="User Name"> </PlusAvatar> </> );};import { Component } from '@angular/core';
@Component({ selector: 'app-example', template: ` <plus-avatar image="https://i.pravatar.cc/50" alt="User Name"> </plus-avatar> `})export class ExampleComponent {}<template> <plus-avatar image="https://i.pravatar.cc/50" alt="User Name"> </plus-avatar></template><plus-avatar image="https://i.pravatar.cc/50" alt="User Name"></plus-avatar><plus-avatar image="https://i.pravatar.cc/50" alt="User Name"></plus-avatar>The size prop controls the dimensions of the avatar. It accepts predefined values (xs, sm, md, lg, xl) or any valid CSS size unit.
import { PlusAvatar } from '@plusui/react';
export default () => { return ( <> <PlusAvatar size="xs"> </PlusAvatar> <PlusAvatar size="sm"> </PlusAvatar> <PlusAvatar size="md"> </PlusAvatar> <PlusAvatar size="lg"> </PlusAvatar> <PlusAvatar size="xl"> </PlusAvatar> </> );};import { Component } from '@angular/core';
@Component({ selector: 'app-example', template: ` <plus-avatar size="xs"> </plus-avatar> <plus-avatar size="sm"> </plus-avatar> <plus-avatar size="md"> </plus-avatar> <plus-avatar size="lg"> </plus-avatar> <plus-avatar size="xl"> </plus-avatar> `})export class ExampleComponent {}<template> <plus-avatar size="xs"> </plus-avatar> <plus-avatar size="sm"> </plus-avatar> <plus-avatar size="md"> </plus-avatar> <plus-avatar size="lg"> </plus-avatar> <plus-avatar size="xl"> </plus-avatar></template><plus-avatar size="xs"></plus-avatar><plus-avatar size="sm"></plus-avatar><plus-avatar size="md"></plus-avatar><plus-avatar size="lg"></plus-avatar><plus-avatar size="xl"></plus-avatar><plus-avatar size="xs"></plus-avatar><plus-avatar size="sm"></plus-avatar><plus-avatar size="md"></plus-avatar><plus-avatar size="lg"></plus-avatar><plus-avatar size="xl"></plus-avatar>The shape prop determines the overall shape of the avatar.
import { PlusAvatar } from '@plusui/react';
export default () => { return ( <> <PlusAvatar shape="circle" image="https://i.pravatar.cc/50"> </PlusAvatar> <PlusAvatar shape="square" image="https://i.pravatar.cc/50"> </PlusAvatar> </> );};import { Component } from '@angular/core';
@Component({ selector: 'app-example', template: ` <plus-avatar shape="circle" image="https://i.pravatar.cc/50"> </plus-avatar> <plus-avatar shape="square" image="https://i.pravatar.cc/50"> </plus-avatar> `})export class ExampleComponent {}<template> <plus-avatar shape="circle" image="https://i.pravatar.cc/50"> </plus-avatar> <plus-avatar shape="square" image="https://i.pravatar.cc/50"> </plus-avatar></template><plus-avatar shape="circle" image="https://i.pravatar.cc/50"></plus-avatar><plus-avatar shape="square" image="https://i.pravatar.cc/50"></plus-avatar><plus-avatar shape="circle" image="https://i.pravatar.cc/50"></plus-avatar><plus-avatar shape="square" image="https://i.pravatar.cc/50"></plus-avatar>Fallback Behavior
Section titled “Fallback Behavior”When an image is not provided or fails to load, the avatar displays fallback content based on the fallbackStrategy prop. You can provide text for initials or use the default icon (customizable via the icon prop).
import { PlusAvatar } from '@plusui/react';
export default () => { return ( <> <PlusAvatar text="Murat Polat Özkan" fallbackStrategy="text"> </PlusAvatar> <PlusAvatar text="Single" fallbackStrategy="text"> </PlusAvatar> <PlusAvatar icon="ghost"> </PlusAvatar> <PlusAvatar> </PlusAvatar> </> );};import { Component } from '@angular/core';
@Component({ selector: 'app-example', template: ` <plus-avatar text="Murat Polat Özkan" fallback-strategy="text"> </plus-avatar> <plus-avatar text="Single" fallback-strategy="text"> </plus-avatar> <plus-avatar icon="ghost"> </plus-avatar> <plus-avatar> </plus-avatar> `})export class ExampleComponent {}<template> <plus-avatar text="Murat Polat Özkan" fallback-strategy="text"> </plus-avatar> <plus-avatar text="Single" fallback-strategy="text"> </plus-avatar> <plus-avatar icon="ghost"> </plus-avatar> <plus-avatar> </plus-avatar></template><plus-avatar text="Murat Polat Özkan" fallback-strategy="text"></plus-avatar><plus-avatar text="Single" fallback-strategy="text"></plus-avatar><plus-avatar icon="ghost"></plus-avatar><plus-avatar></plus-avatar><plus-avatar text="Murat Polat Özkan" fallback-strategy="text"></plus-avatar><plus-avatar text="Single" fallback-strategy="text"></plus-avatar><plus-avatar icon="ghost"></plus-avatar><plus-avatar></plus-avatar>Visual Sections
Section titled “Visual Sections”Layout & Spacing
Section titled “Layout & Spacing”Proper layout and spacing are crucial for integrating avatars seamlessly into the UI.
Light & Dark Mode
Section titled “Light & Dark Mode”The Avatar component adapts to both light and dark themes.
Accessibility (a11y)
Section titled “Accessibility (a11y)”- Keyboard Behavior: The component itself is not typically interactive, but if used within an interactive element (like a button or link), ensure that element follows standard keyboard navigation patterns.
- Screen Reader: The
role="img"is automatically applied. Provide meaningful alternative text via thealtprop, especially when animageis used. Ifaltis absent, the component attempts to use thetextprop or a generic label, but explicitalttext is always recommended for clarity. - Developer Actions: Always provide a descriptive
altprop when using theimageprop. Ensure sufficient color contrast between the avatar background and foreground (text/icon) if customizing colors.
API Reference
Section titled “API Reference”Properties
Section titled “Properties”| Name | Type | Default | Description |
|---|---|---|---|
image | string | undefined | URL of the avatar image. |
alt | string | undefined | Alternative text for the image. |
shape | 'circle' | 'square' | 'circle' | Shape of the avatar. |
size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | string | 'md' | Size of the avatar (predefined or custom CSS unit). |
icon | string | 'fa-solid fa-user' | CSS class for the fallback icon. |
invert | boolean | false | Toggles the inverted color scheme. |
text | string | undefined | Text to display as initials. |
fallbackStrategy | 'icon' | 'text' | 'custom' | 'icon' | Strategy when image fails to load. |
Events
Section titled “Events”| Name | Payload Type | Description |
|---|---|---|
error | CustomEvent<void> | Fired when the image fails to load. |
load | CustomEvent<void> | Fired when the image loads. |
| Name | Description |
|---|---|
(default) | Main content area (image, icon, or text). |
fallback | Custom content for fallbackStrategy='custom'. |
CSS Custom Properties
Section titled “CSS Custom Properties”| Name | Description |
|---|---|
--text-color | Text color for initials or icon. |
--bg-default | Default background color. |
Shadow Parts
Section titled “Shadow Parts”| Name | Description |
|---|---|
base | The main container element. |
Join the Community
Plus UI is built by the community. Join us on our platforms to contribute, get help, and stay up to date.