Search results

Types in React Avatar component

02 Feb 2023 / 2 minutes to read

This section explains different types of avatar.

Avatar size

The Essential JS 2 Avatar has the following predefined sizes that can be used with the .e-avatar class to change the appearance of the avatar.

Class Name Description
e-avatar-xlarge Displays xlarge size avatar.
e-avatar-large Displays apply large size avatar.
e-avatar Displays apply default size avatar.
e-avatar-small Displays apply small size avatar.
e-avatar-xsmall Displays apply xsmall size avatar.
Source
Preview
index.jsx
index.html
index.css
index.tsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
function ReactApp() {
    return (<div>
      <span className="e-avatar e-avatar-xlarge"></span>
      <span className="e-avatar e-avatar-large"></span>
      <span className="e-avatar"></span>
      <span className="e-avatar e-avatar-small"></span>
      <span className="e-avatar e-avatar-xsmall"></span>
  </div>);
}
export default ReactApp;
ReactDOM.render(<ReactApp />, document.getElementById("element"));
Copied to clipboard
<!DOCTYPE html>
<html lang="en">

<head>
            
    <title>Syncfusion EJ2 React Avatar Sample</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/20.4.48/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/20.4.48/ej2-layouts/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
    <link rel="stylesheet" href="index.css">
</head>
<body>
    <div id='element'>
        <div id='loader'>Loading....</div>
    </div>
</body>
</html>
Copied to clipboard
#container {
    visibility: hidden;
}

#loader {
  color: #008cff;
  height: 40px;
  width: 30%;
  position: absolute;
  font-family: 'Helvetica Neue','calibiri';
  font-size: 14px;
  top: 45%;
  left: 45%;
}

#element {
    display: block;
    width: 300px;
    margin: 100px auto;
    border-radius: 3px;
}

.e-avatar {
    background-image: url(https://ej2.syncfusion.com/demos/src/grid/images/2.png);
    margin: 2px;
}
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";

function ReactApp() {
  return (
  <div>
      <span className="e-avatar e-avatar-xlarge"></span>
      <span className="e-avatar e-avatar-large"></span>
      <span className="e-avatar"></span>
      <span className="e-avatar e-avatar-small"></span>
      <span className="e-avatar e-avatar-xsmall"></span>
  </div>
  );
}
export default ReactApp;
ReactDOM.render(<ReactApp/>, document.getElementById("element"));

Avatar types

The types of Essential JS 2 avatar are:

  • Default
  • Circle

Default

The default style of the avatar is rectangular shape with rounded corners, which can be applied from adding the modifier class .e-avatar to the target element.

Source
Preview
index.jsx
index.html
index.css
index.tsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
function ReactApp() {
    return (<div>
      <span className="e-avatar e-avatar-xlarge">RT</span>
      <span className="e-avatar e-avatar-large">RT</span>
      <span className="e-avatar">RT</span>
      <span className="e-avatar e-avatar-small">RT</span>
      <span className="e-avatar e-avatar-xsmall">RT</span>
  </div>);
}
export default ReactApp;
ReactDOM.render(<ReactApp />, document.getElementById("element"));
Copied to clipboard
<!DOCTYPE html>
<html lang="en">

<head>
            
    <title>Syncfusion EJ2 React Avatar Sample</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/20.4.48/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/20.4.48/ej2-layouts/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
    <link rel="stylesheet" href="index.css">
</head>
<body>
    <div id='element'>
        <div id='loader'>Loading....</div>
    </div>
</body>
</html>
Copied to clipboard
#container {
    visibility: hidden;
}

#loader {
  color: #008cff;
  height: 40px;
  width: 30%;
  position: absolute;
  font-family: 'Helvetica Neue','calibiri';
  font-size: 14px;
  top: 45%;
  left: 45%;
}

#element {
    display: block;
    width: 260px;
    margin: 100px auto;
    border-radius: 3px;
}

.e-avatar {
    margin: 2px;
}
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";

function ReactApp() {
  return (
  <div>
      <span className="e-avatar e-avatar-xlarge">RT</span>
      <span className="e-avatar e-avatar-large">RT</span>
      <span className="e-avatar">RT</span>
      <span className="e-avatar e-avatar-small">RT</span>
      <span className="e-avatar e-avatar-xsmall">RT</span>
  </div>
  );
}
export default ReactApp;
ReactDOM.render(<ReactApp/>, document.getElementById("element"));

Circle

The circle avatar style can be applied by adding the modifier class .e-avatar-circle to the target element.

Source
Preview
index.jsx
index.html
index.css
index.tsx
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";
function ReactApp() {
    return (<div>
      <span className="e-avatar e-avatar-xlarge e-avatar-circle">SJ</span>
      <span className="e-avatar e-avatar-large e-avatar-circle">SJ</span>
      <span className="e-avatar e-avatar-circle">SJ</span>
      <span className="e-avatar e-avatar-small e-avatar-circle">SJ</span>
      <span className="e-avatar e-avatar-xsmall e-avatar-circle">SJ</span>
  </div>);
}
export default ReactApp;
ReactDOM.render(<ReactApp />, document.getElementById("element"));
Copied to clipboard
<!DOCTYPE html>
<html lang="en">

<head>
            
    <title>Syncfusion EJ2 React Avatar Sample</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/20.4.48/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/20.4.48/ej2-layouts/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
    <link rel="stylesheet" href="index.css">
</head>
<body>
    <div id='element'>
        <div id='loader'>Loading....</div>
    </div>
</body>
</html>
Copied to clipboard
#container {
    visibility: hidden;
}

#loader {
  color: #008cff;
  height: 40px;
  width: 30%;
  position: absolute;
  font-family: 'Helvetica Neue','calibiri';
  font-size: 14px;
  top: 45%;
  left: 45%;
}

#element {
    display: block;
    width: 300px;
    margin: 100px auto;
    border-radius: 3px;
}

.e-avatar {
    margin: 2px;
}
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";

function ReactApp() {
  return (
  <div>
      <span className="e-avatar e-avatar-xlarge e-avatar-circle">SJ</span>
      <span className="e-avatar e-avatar-large e-avatar-circle">SJ</span>
      <span className="e-avatar e-avatar-circle">SJ</span>
      <span className="e-avatar e-avatar-small e-avatar-circle">SJ</span>
      <span className="e-avatar e-avatar-xsmall e-avatar-circle">SJ</span>
  </div>
  );
}
export default ReactApp;
ReactDOM.render(<ReactApp/>, document.getElementById("element"));