Search results

How To

The avatar is a completely customizable and integral component. This section explains some of the customization and integration of avatar with other components.

Customize avatars

Color customization

The avatar comes with default background color (grey). This can be easily customized to desired color by adding the custom class or directly selecting the avatar class from the CSS.

Source
Preview
index.js
index.html
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 for Avatar </title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Essential JS 2 for Avatar UI Control">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet">
    <link href="//cdn.syncfusion.com/ej2/ej2-layouts/styles/material.css" rel="stylesheet">
    
    
<script src="//cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="element">
            <span class="e-avatar e-avatar-xlarge e-avatar-circle green">AJ</span>
            <span class="e-avatar e-avatar-xlarge e-avatar-circle violet">JK</span>
            <span class="e-avatar e-avatar-xlarge e-avatar-circle rose">EL</span>
            <span class="e-avatar e-avatar-xlarge e-avatar-circle blue">SR</span>
            <span class="e-avatar e-avatar-xlarge e-avatar-circle red">PD</span>
        </div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
    ele.style.visibility = "visible";
 }   
        </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

Customize avatar sizes

Even though the avatar comes with five predefined sizes, sometimes it’s not enough. So, the avatar is designed in such a way that the width and height will be relative to font-size. By changing the font-size of the avatar element, you can change the width and height automatically.

Source
Preview
index.js
index.html
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 for Avatar </title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Essential JS 2 for Avatar UI Control">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet">
    <link href="//cdn.syncfusion.com/ej2/ej2-layouts/styles/material.css" rel="stylesheet">
    
    
<script src="//cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="element">
            <span class="e-avatar">26px</span>
            <span class="e-avatar">24px</span>
            <span class="e-avatar">22px</span>
            <span class="e-avatar">20px</span>
            <span class="e-avatar">18px</span>
        </div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
    ele.style.visibility = "visible";
 }   
        </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

Use various media in avatar

Avatars can be used with a wide variety of media formats like SVG, font-icons, images, letters, words, etc. Some of them are given below.

Source
Preview
index.js
index.html
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 for Avatar </title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Essential JS 2 for Avatar UI Control">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet">
    <link href="//cdn.syncfusion.com/ej2/ej2-layouts/styles/material.css" rel="stylesheet">
    
    
<script src="//cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="element">
            <div class="sample_container avatar-types">
                <div class="avatar-block">
                    <!-- Card Component -->
                    <div class="e-card e-avatar-showcase">
                        <div class="e-card-content">
                            <!-- XLarge Circle Avatar Component -->
                            <div class="e-avatar e-avatar-xlarge e-avatar-circle image"></div>
                        </div>
                        <div class="e-card-content">
                            <div>Image</div>
                        </div>
                    </div>
                </div>

                <div class="avatar-block">
                    <!-- Card Component -->
                    <div class="e-card e-avatar-showcase">
                        <div class="e-card-content">
                            <!-- XLarge Circle Avatar Component -->
                            <div class="e-avatar e-avatar-xlarge e-avatar-circle">
                                <div class="svg_icons chrome"></div>
                            </div>
                        </div>
                        <div class="e-card-content">
                            <div>SVG</div>
                        </div>
                    </div>
                </div>

                <div class="avatar-block">
                    <!-- Card Component -->
                    <div class="e-card e-avatar-showcase">
                        <div class="e-card-content">
                            <!-- XLarge Circle Avatar Component -->
                            <div class="e-avatar e-avatar-xlarge e-avatar-circle">GR</div>
                        </div>
                        <div class="e-card-content">
                            <div>Initial</div>
                        </div>
                    </div>
                </div>

                <div class="avatar-block">
                    <!-- Card Component -->
                    <div class="e-card e-avatar-showcase">
                        <div class="e-card-content">
                            <!-- XLarge Circle Avatar Component -->
                            <div class="e-avatar e-avatar-xlarge e-avatar-circle">
                                <div class="e-people icons"></div>
                            </div>
                        </div>
                        <div class="e-card-content">
                            <div>FontIcon</div>
                        </div>
                    </div>
                </div>

                <div class="avatar-block">
                    <!-- Card Component -->
                    <div class="e-card e-avatar-showcase">
                        <div class="e-card-content">
                            <!-- XLarge Circle Avatar Component -->
                            <div class="e-avatar e-avatar-xlarge e-avatar-circle">User</div>
                        </div>
                        <div class="e-card-content">
                            <div>Word</div>
                        </div>
                    </div>
                </div>

                <div class="avatar-block">
                    <!-- Card Component -->
                    <div class="e-card e-avatar-showcase">
                        <div class="e-card-content">
                            <!-- XLarge Circle Avatar Component -->
                            <div class="e-avatar e-avatar-xlarge e-avatar-circle custom">
                                <div class="e-people icons"></div>
                            </div>
                        </div>
                        <div class="e-card-content">
                            <div>Custom</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
    ele.style.visibility = "visible";
 }   
        </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

Integrate avatars

Avatar can be integrated into various components to make a wide variety of applications. Some of the integrations are shown in the following section.

Listview

Avatar is integrated into the listview to create contacts applications. The xsmall size avatar is used to match the size of the list item. Letters and images are also used as avatar content.

Source
Preview
index.js
index.html
var dataSource = [
    { id: 's_01', text: 'Robert', avatar: '', pic: 'pic04' },
    { id: 's_02', text: 'Nancy', avatar: 'N', pic: '' },
    { id: 's_05', text: 'John', pic: 'pic01', avatar: '' },
    { id: 's_03', text: 'Andrew', avatar: 'A', pic: '' },
    { id: 's_06', text: 'Michael', pic: 'pic02', avatar: '' },
    { id: 's_07', text: 'Steven', pic: 'pic03', avatar: '' },
    { id: 's_08', text: 'Margaret', avatar: 'M', pic: '' }
];

var letterAvatarList = new ej.lists.ListView({
    // Bind listview datasource
    dataSource: dataSource,
    // Assign header title
    headerTitle: 'Contacts',
    // Enable header title
    showHeader: true,
    // Assign list-item template
    template: '<div class="listWrapper">' +
        '${if(avatar!=="")}' +
        '<span class="e-avatar e-avatar-small e-avatar-circle">${avatar}</span>' +
        '${else}' +
        '<span class="${pic} e-avatar e-avatar-small e-avatar-circle"> </span>' +
        '${/if}' +
        '<span class="text">' +
        '${text} </span> </div>',
    // Assign sorting order
    sortOrder: 'Ascending'
});
letterAvatarList.appendTo('#letterAvatarList');
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 for Avatar </title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Essential JS 2 for Avatar UI Control">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet">
    <link href="//cdn.syncfusion.com/ej2/ej2-layouts/styles/material.css" rel="stylesheet">
    <link href="//cdn.syncfusion.com/ej2/ej2-lists/styles/material.css" rel="stylesheet">
    
    
<script src="//cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="element">
            <!-- Listview element -->
            <div id="letterAvatarList"></div>
        </div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
    ele.style.visibility = "visible";
 }   
        </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

Badge

The badge is dependent and supportive component, and it can be used with avatar to create a notification avatar. The default avatar (.e-avatar) and circle avatar (.e-avatar-circle) have been used with notification badges (.e-badge-notification) in the following sample.

Source
Preview
index.js
index.html
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 for Avatar </title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Essential JS 2 for Avatar UI Control">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet">
    <link href="//cdn.syncfusion.com/ej2/ej2-layouts/styles/material.css" rel="stylesheet">
    <link href="//cdn.syncfusion.com/ej2/ej2-notifications/styles/material.css" rel="stylesheet">
    
    
<script src="//cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="element">
            <div class="sample_container avatar-badge">
                <div class="avatar-block">
                    <!-- Card Component -->
                    <div class="e-card e-avatar-showcase">
                        <div class="e-card-content">
                            <div class="avatar-sub-block">
                                <!-- xSmall Avatar-->
                                <div class="e-avatar e-avatar-xsmall">
                                    <img src="./pic01.png" alt="profile_pic">
                                </div>
                                <!-- Notification Badge -->
                                <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification e-badge-circle">6</span>
                            </div>
                            <div class="avatar-sub-block">
                                <!-- Small Avatar-->
                                <div class="e-avatar e-avatar-small">
                                    <img src="./pic01.png" alt="profile_pic">
                                </div>
                                <!-- Notification Badge -->
                                <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification e-badge-circle">12</span>
                            </div>
                            <div class="avatar-sub-block">
                                <!-- Avatar-->
                                <div class="e-avatar">
                                    <img src="./pic01.png" alt="profile_pic">
                                </div>
                                <!-- Notification Badge -->
                                <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification">46</span>
                            </div>
                            <div class="avatar-sub-block">
                                <!-- Large Avatar-->
                                <div class="e-avatar e-avatar-large">
                                    <img src="./pic01.png" alt="profile_pic">
                                </div>
                                <!-- Notification Badge -->
                                <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification">82</span>
                            </div>
                            <div class="avatar-sub-block">
                                <!-- xLarge Avatar-->
                                <div class="e-avatar e-avatar-xlarge">
                                    <img src="./pic01.png" alt="profile_pic">
                                </div>
                                <!-- Notification Badge -->
                                <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification">99+</span>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="circleAvatar avatar-block">
                    <!-- Card Component -->
                    <div class="e-card e-avatar-showcase">
                        <div class="e-card-content">
                            <div class="avatar-sub-block">
                                <!-- xSmall Circle Avatar-->
                                <div class="e-avatar e-avatar-circle e-avatar-xsmall">
                                    <img src="./pic01.png" alt="profile_pic">
                                </div>
                                <!-- Notification Badge -->
                                <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification e-badge-circle">6</span>
                            </div>
                            <div class="avatar-sub-block">
                                <!-- Small Circle Avatar-->
                                <div class="e-avatar e-avatar-circle e-avatar-small">
                                    <img src="./pic01.png" alt="profile_pic">
                                </div>
                                <!-- Notification Badge -->
                                <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification e-badge-circle">12</span>
                            </div>
                            <div class="avatar-sub-block">
                                <!-- Circle Avatar-->
                                <div class="e-avatar e-avatar-circle">
                                    <img src="./pic01.png" alt="profile_pic">
                                </div>
                                <!-- Notification Badge -->
                                <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification">46</span>
                            </div>
                            <div class="avatar-sub-block">
                                <!-- Large Circle Avatar-->
                                <div class="e-avatar e-avatar-circle e-avatar-large">
                                    <img src="./pic01.png" alt="profile_pic">
                                </div>
                                <!-- Notification Badge -->
                                <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification">82</span>
                            </div>
                            <div class="avatar-sub-block">
                                <!-- xLarge Circle Avatar-->
                                <div class="e-avatar e-avatar-circle e-avatar-xlarge">
                                    <img src="./pic01.png" alt="profile_pic">
                                </div>
                                <!-- Notification Badge -->
                                <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification">99+</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
    ele.style.visibility = "visible";
 }   
        </script>
<script src="index.js" type="text/javascript"></script>
</body></html>