<cs-avatar>
StableMediaSince 0.1

Avatars represent a person or object with an image, initials, or icon. Use them in lists, comments, and profiles to give users visual context at a glance.

By default, a generic icon will be shown. You can personalize avatars by adding images, initials, and custom icons. You should always provide a label for assistive devices.

Examples

Image

To use an image for the avatar, set the image and label attributes. This will take priority and be shown over initials and icons. Avatar images can be lazily loaded by setting the loading attribute to lazy.

Initials

When you don’t have an image to use, you can set the initials attribute to show something more personalized than an icon.

Custom Icon

When no image or initials are set, an icon will be shown. The default avatar shows a generic “user” icon, but you can customize this with the icon slot.

Shape

Avatars can be shaped using the shape attribute.

Avatar Groups

You can group avatars with a few lines of CSS.

API

Importing

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick this component, use one of the following snippets.

npm Self-Hosted React
import '@cruglobal/cornerstone-components/components/avatar/avatar.js';
import './cornerstone/components/avatar/avatar.js';
import CsAvatar from '@cruglobal/cornerstone-components/react/avatar/index.js';

Slots

Learn more about using slots.

NameDescription
iconThe default icon to use when no image or initials are present. Works best with <cs-icon>.

Attributes & Properties

Learn more about attributes and properties.

PropertyAttributeDescriptionTypeDefaultReflects
imageimageThe image source to use for the avatar.string''
initialsinitialsInitials to use as a fallback when no image is available (1-2 characters max recommended).string''
labellabelA label to use to describe the avatar to assistive devices.string''
loadingloadingIndicates how the browser should load the image.'eager' | 'lazy''eager'
shapeshapeThe shape of the avatar.'circle' | 'square' | 'rounded''circle'Yes

Events

Learn more about events.

NameDescription
cs-errorThe image could not be loaded. This may because of an invalid URL, a temporary network condition, or some unknown cause.

CSS Custom Properties

Learn more about CSS custom properties.

NameDescriptionDefault
--sizeThe size of the avatar.

CSS Parts

Learn more about CSS parts.

NameDescriptionCSS selector
iconThe container that wraps the avatar's icon.::part(icon)
imageThe avatar image. Only shown when the image attribute is set.::part(image)
initialsThe container that wraps the avatar's initials.::part(initials)

Dependencies

This component automatically imports the following elements. Sub-dependencies, if any exist, are included in this list.