Badge customization in React Badge component

30 Jan 202319 minutes to read

Colour customization

Even though badges come with 8 predefined colors, you can also customize the colour of the badge as desired.

import * as React from "react";
import * as ReactDOM from "react-dom";
function App() {
    return (<div>
        <h1>Color Customization <span className="e-badge e-badge-primary e-badge-pill green">New</span></h1>
        <h1>Color Customization <span className="e-badge e-badge-primary e-badge-pill bue">New</span></h1>
        <h1>Color Customization <span className="e-badge e-badge-primary e-badge-pill purple">New</span></h1>
        <h1>Color Customization <span className="e-badge e-badge-primary e-badge-pill gradient">New</span></h1>
    </div>);
}
export default App;
ReactDOM.render(<App />, document.getElementById("element"));
import * as React from "react";
import * as ReactDOM from "react-dom";

function App() {
    return (
    <div>
        <h1>Color Customization <span className="e-badge e-badge-primary e-badge-pill green">New</span></h1>
        <h1>Color Customization <span className="e-badge e-badge-primary e-badge-pill bue">New</span></h1>
        <h1>Color Customization <span className="e-badge e-badge-primary e-badge-pill purple">New</span></h1>
        <h1>Color Customization <span className="e-badge e-badge-primary e-badge-pill gradient">New</span></h1>
    </div>
    );
}
export default App;
ReactDOM.render(<App />, document.getElementById("element"));
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Essential JS 2 React Badge 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="https://cdn.syncfusion.com/ej2/27.1.48/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="https://cdn.syncfusion.com/ej2/27.1.48/ej2-notifications/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" />
    <style>
        #loader {
            color: #008cff;
            height: 40px;
            left: 45%;
            position: absolute;
            top: 45%;
            width: 30%;
        }
    </style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    <div id='element'>
        <div id='loader'>Loading....</div></div>
</body>
</html>

Customize badge size

Badges are designed to change its size based on the content. To change the size of a badge, adjust the
font size of the badge.

import * as React from "react";
import * as ReactDOM from "react-dom";
function App() {
    return (<div>
            <h1>Badge Component <span className="e-badge e-badge-primary size_1">New</span></h1>
            <h1>Badge Component <span className="e-badge e-badge-primary size_2">New</span></h1>
            <h1>Badge Component <span className="e-badge e-badge-primary size_3">New</span></h1>
        </div>);
}
export default App;
ReactDOM.render(<App />, document.getElementById("element"));
import * as React from "react";
import * as ReactDOM from "react-dom";

function App() {
    return (
        <div>
            <h1>Badge Component <span className="e-badge e-badge-primary size_1">New</span></h1>
            <h1>Badge Component <span className="e-badge e-badge-primary size_2">New</span></h1>
            <h1>Badge Component <span className="e-badge e-badge-primary size_3">New</span></h1>
        </div>
    );
}
export default App;
ReactDOM.render(<App />, document.getElementById("element"));
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Essential JS 2 React Badge 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="https://cdn.syncfusion.com/ej2/27.1.48/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="https://cdn.syncfusion.com/ej2/27.1.48/ej2-notifications/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" />
    <style>
        #loader {
            color: #008cff;
            height: 40px;
            left: 45%;
            position: absolute;
            top: 45%;
            width: 30%;
        }
    </style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    <div id='element'>
        <div id='loader'>Loading....</div></div>
</body>
</html>

Custom position

Even though the badges support the conventional top and bottom positions, the position of the badges can be changed as desired.This can be done by adding a custom class to the badge element to override the default position applied from the source.

import * as React from "react";
import * as ReactDOM from "react-dom";
function App() {
    return (<div>
            <div className="block">
                <div className="badge-block">
                    <div className="firefox svg_icons"></div>
                    {/* Warning Colored Notification Badge*/}
                    <span className="e-badge e-badge-warning e-badge-notification e-badge-overlap leftTop">99+</span>
                </div>

                <div className="badge-block">
                    <div className="facebook svg_icons"></div>
                    {/* Danger Colored Notification Badge*/}
                    <span className="e-badge e-badge-danger e-badge-notification e-badge-overlap leftTop">99+</span>
                </div>

                <div className="badge-block">
                    <div className="skype svg_icons"></div>
                    {/* Secondary Colored Notification Badge*/}
                    <span className="e-badge e-badge-secondary e-badge-notification e-badge-overlap leftTop">18</span>
                </div>
            </div>
            <div className="badge-block">
                <div className="badge-block">
                    <div className="firefox svg_icons"></div>
                    {/* Warning Colored Notification Badge*/}
                    <span className="e-badge e-badge-warning e-badge-notification e-badge-overlap leftBottom">99+</span>
                </div>

                <div className="badge-block">
                    <div className="facebook svg_icons"></div>
                    {/* Danger Colored Notification Badge*/}
                    <span className="e-badge e-badge-danger e-badge-notification e-badge-overlap leftBottom">99+</span>
                </div>

                <div className="badge-block">
                    <div className="skype svg_icons"></div>
                    {/* Secondary Colored Notification Badge*/}
                    <span className="e-badge e-badge-secondary e-badge-notification e-badge-overlap leftBottom">18</span>
                </div>
            </div>
        </div>);
}
export default App;
ReactDOM.render(<App />, document.getElementById("element"));
import * as React from "react";
import * as ReactDOM from "react-dom";

function App() {
    return (
        <div>
            <div className="block">
                <div className="badge-block">
                    <div className="firefox svg_icons"></div>
                    {/* Warning Colored Notification Badge*/}
                    <span className="e-badge e-badge-warning e-badge-notification e-badge-overlap leftTop">99+</span>
                </div>

                <div className="badge-block">
                    <div className="facebook svg_icons"></div>
                    {/* Danger Colored Notification Badge*/}
                    <span className="e-badge e-badge-danger e-badge-notification e-badge-overlap leftTop">99+</span>
                </div>

                <div className="badge-block">
                    <div className="skype svg_icons"></div>
                    {/* Secondary Colored Notification Badge*/}
                    <span className="e-badge e-badge-secondary e-badge-notification e-badge-overlap leftTop">18</span>
                </div>
            </div>
            <div className="badge-block">
                <div className="badge-block">
                    <div className="firefox svg_icons"></div>
                    {/* Warning Colored Notification Badge*/}
                    <span className="e-badge e-badge-warning e-badge-notification e-badge-overlap leftBottom">99+</span>
                </div>

                <div className="badge-block">
                    <div className="facebook svg_icons"></div>
                    {/* Danger Colored Notification Badge*/}
                    <span className="e-badge e-badge-danger e-badge-notification e-badge-overlap leftBottom">99+</span>
                </div>

                <div className="badge-block">
                    <div className="skype svg_icons"></div>
                    {/* Secondary Colored Notification Badge*/}
                    <span className="e-badge e-badge-secondary e-badge-notification e-badge-overlap leftBottom">18</span>
                </div>
            </div>
        </div>
    );
}
export default App;
ReactDOM.render(<App />, document.getElementById("element"));
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Essential JS 2 React Badge 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="https://cdn.syncfusion.com/ej2/27.1.48/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="https://cdn.syncfusion.com/ej2/27.1.48/ej2-notifications/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" />
    <style>
        #loader {
            color: #008cff;
            height: 40px;
            left: 45%;
            position: absolute;
            top: 45%;
            width: 30%;
        }
    </style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    <div id='element'>
        <div id='loader'>Loading....</div></div>
</body>
</html>