The Ignite UI for Angular Avatar component helps adding initials, images, or material icons to your application.



To get started with the Avatar component, first you need to install Ignite UI for Angular by typing the following command:

ng add igniteui-angular

For a complete introduction to the Ignite UI for Angular, read the getting started topic.

The next step is to import the IgxAvatarModule in the app.module.ts file:

// app.module.ts

import { IgxAvatarModule } from 'igniteui-angular';

    imports: [..., IgxAvatarModule],
export class AppModule {}


The Avatar can be either square or circular, with three size options (small, medium and large). It can be used for displaying initials, images or icons.

Avatar displaying initials

To get a simple avatar with initials (i.e. JS for 'Jack Sock'), add the following code inside the component template:

<igx-avatar initials="JS">

Let's enhance our avatar by making it circular and bigger in size.

<igx-avatar initials="JS"

We can also change the background through the background property or set a color on the initials through the color property.

// avatar.component.scss

.igx-avatar {
    background:  #e41c77;
    color: #000000;

If all went well, you should see something like the following in the browser:

Avatar displaying image

To get an avatar that displays an image, all you have to do is set the image source via the src property.

<igx-avatar src="https://randomuser.me/api/portraits/men/1.jpg"

If all went well, you should see something like the following in the browser:

Avatar displaying icon

Analogically, the avatar can display an icon via the icon property. Currently all icons from the material icon set are supported.

<igx-avatar icon="person"

You should see something like this:


To get started with styling the avatar, we need to import the index file, where all the theme functions and component mixins live:

@import '~igniteui-angular/lib/core/styles/themes/index';

Following the simplest approach, we create a new theme that extends the igx-avatar-theme and accepts the $initials-background, $initials-color, $icon-background, $icon-color and the $border-radius-square parameters.

$custom-avatar-theme: igx-avatar-theme(
    $initials-background: #72da67,
    $initials-color: #000000,
    $icon-background: #217346,
    $icon-color: #ffffff,
    $border-radius-square: 16px

Using CSS variables

The last step is to pass the custom avatar theme:

@include igx-css-vars($custom-avatar-theme);

Using mixins

In order to style components for Internet Explorer 11, we have to use different approach, since it doesn't support CSS variables.

If the component is using an Emulated ViewEncapsulation, it is necessary to penetrate this encapsulation using ::ng-deep. On the other side, in order to prevent the custom theme to leak to other components, be sure to include the :host selector before ::ng-deep:

:host {
    ::ng-deep {
        // Pass the custom avatar theme to the `igx-avatar` mixin
        @include igx-avatar($custom-avatar-theme);

If all went well, you should see something like the following in the browser:

API References

Additional Resources

Our community is active and always welcoming to new ideas.