Close
Angular React Web Components Blazor
Open Source

Web Components Avatar

The Ignite UI for Web Components Avatar helps to display initials, images, or icons in your application.

Web Components Icon Avatar Example

Usage

First, you need to install the Ignite UI for Web Components npm package by running the following command:

npm install igniteui-webcomponents

Before using the Avatar, you need to register it as follows:

import { defineComponents, IgcAvatarComponent } from 'igniteui-webcomponents';

defineComponents(IgcAvatarComponent);

For a complete introduction to the Ignite UI for Web Components, read the Getting Started topic.

The Avatar is capable of displaying images, initials, or any other content, including icons. Declaring an Avatar is as simple as:

<igc-avatar></igc-avatar>

The avatar has several attributes that allow rendering different content based on the context. The most basic way to display content in the boundaries of the avatar is to provide content between the opening and closing tags.

<igc-avatar>
  <igc-icon name="home"></igc-icon>
</igc-avatar>

Initials

If the Initials attribute is set all children elements of the avatar will be ignored and the string passed to this attribute will be displayed.

<!-- Initials("AZ") will be displayed instead of the icon. -->

<igc-avatar initials="AZ">
  <igc-icon name="home"></igc-icon>
</igc-avatar>

Image

The avatar can also display an image when the Src attribute is assigned a valid URL to a static asset. In that case the Initials value will be ignored and children elements will not be rendered.

<igc-avatar
  initials="AZ"
  src="https://pt-br.infragistics.com/angular-demos/assets/images/men/1.jpg"
  alt="A photo of a man.">
  <igc-icon name="home"></igc-icon>
</igc-avatar>

Shape

The avatar supports three shapes - circle, rounded, and square. The default shape of the avatar is square and it can be changed via the shape attribute.

Size

Apart from the shape, the size of the avatar can also be changed by utilizing the --ig-size CSS variable. The supported sizes are small (default), medium, and large. The following code snippet shows how to use a different component size:

igc-avatar {
  --ig-size: var(--ig-size-large);
}

Styling

The Avatar component exposes several CSS parts, giving you full control over its style:

NameDescription
baseThe base wrapper of the avatar.
initialsThe initials wrapper of the avatar.
imageThe image wrapper of the avatar.
iconThe icon wrapper of the avatar.
igc-avatar::part(base) {
  --size: 60px;
  color: var(--ig-success-500-contrast);
  background: var(--ig-success-500);;
  border-radius: 20px;
}

API References

Additional Resources