Avatar

lightning:avatar

A visual representation of an object.

For Aura components only. For LWC development, use lightning-avatar.

For Use In

Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline

A lightning:avatar component is an image that represents an object, such as an account or user. By default, the image renders in medium sizing with a rounded rectangle, which is also known as the square variant.

This component implements styling from avatars in the Lightning Design System.

Use the class attribute to apply additional styling.

Here is an example.

1<aura:component>
2  <lightning:avatar src="/images/codey.jpg" alternativeText="Codey Bear" />
3</aura:component>

To use an image in your org, upload it as a static resource in the Static Resources setup page. Use the {!$Resource.logo} syntax in your src attribute, where logo is the name you provided in the Name field on the setup page.

Handling Invalid Image Paths 

The src attribute resolves the relative path to an image, but sometimes the image path doesn’t resolve correctly because the user is offline or the image has been deleted. To handle an invalid image path, you can provide fallback initials using the initials attribute. This example displays the initials “Sa” if the image path is invalid.

1<lightning:avatar
2  src="/bad/image/url.jpg"
3  initials="Sa"
4  fallbackIconName="standard:account"
5  alternativeText="Salesforce"
6/>

In the previous example, the fallback icon “standard:account” is displayed if initials are not provided.

When applying Lightning Design System classes or icons, check that they are available in the Lightning Design System release tied to your org. The latest Lightning Design System resources become available only when the new release is available in your org.

Accessibility 

Use the alternativeText attribute to describe the avatar, such as a user’s initials or name. This description provides the value for the alt attribute in the img HTML tag.

Attributes 

NameDescriptionTypeDefaultRequired
alternativeTextThe alternative text used to describe the avatar, which is displayed as hover text on the image.String
bodyThe body of the component. In markup, this is everything in the body of the tag.Aura.Component[]
classA CSS class for the outer element, in addition to the component's base classes.String
fallbackIconNameThe Lightning Design System name of the icon used as a fallback when the image fails to load. The initials fallback relies on this for its background color. Names are written in the format 'standard:account' where 'standard' is the category, and 'account' is the specific icon to be displayed. Only icons from the standard and custom categories are allowed.String
initialsIf the record name contains two words, like first and last name, use the first capitalized letter of each. For records that only have a single word name, use the first two letters of that word using one capital and one lower case letter.String
sizeThe size of the avatar. Valid values are x-small, small, medium, and large. This value defaults to medium.Stringmedium
srcThe URL for the image.String
titleDisplays tooltip text when the mouse moves over the element.String
variantThe variant changes the shape of the avatar. Valid values are empty, circle, and square. This value defaults to square.Stringsquare