Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (161).NET Core  (29).NET MAUI  (64)Angular  (74)ASP.NET  (50)ASP.NET Core  (79)ASP.NET MVC  (88)Azure  (36)Blazor  (153)DocIO  (23)Essential JS 2  (85)Essential Studio  (174)File Formats  (29)Flutter  (123)JavaScript  (187)Microsoft  (113)PDF  (67)React  (62)Succinctly series  (128)Syncfusion  (610)TypeScript  (31)Uno Platform  (3)UWP  (4)Vue  (39)Webinar  (35)Windows Forms  (59)WinUI  (52)WPF  (138)Xamarin  (155)XlsIO  (25)Other CategoriesBarcode  (5)BI  (29)Bold BI  (5)Build conference  (6)Business intelligence  (54)Button  (4)C#  (120)Chart  (57)Cloud  (12)Company  (445)Dashboard  (8)Data Science  (3)Data Validation  (6)DataGrid  (55)Development  (400)Doc  (7)DockingManager  (1)eBook  (96)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (23)Extensions  (18)File Manager  (4)Gantt  (11)Gauge  (11)Git  (4)Grid  (28)HTML  (11)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (312)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (30)Performance  (9)PHP  (1)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (7)Road Map  (10)Scheduler  (36)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (22)Solution Services  (3)Spreadsheet  (11)SQL  (8)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (11)Tips and Tricks  (92)UI  (224)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (23)Visual Studio Code  (17)Web  (375)What's new  (213)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Share on twitter
Share on facebook
Share on linkedin

Quick Overview of JavaScript Button in Essential JS 2

The Essential JS 2 button component is an advanced version of an HTML button. It is the best alternative for an HTML button since it has all the core functionalities of an HTML button plus advanced features such as different types and predefined styles that are adaptable to different application environments.

The Essential JS 2 button can contain text, icons, or both. The button can also be used to communicate with users through colors, shapes, and images without any text. For example, a button with an image of a magnifying glass almost always represents a search option. A green button almost always represents a successful action, such as a GitHub merge.

This blog post will provide an overview of the Essential JS 2 button, how to configure it, and how to use its advanced features.

Getting started

You need to set up the development environment before creating a button. It is very easy to get started with the button since its source code is available in GitHub and packages are available in npm.

To get started with the button component, you can clone the Essential JS 2 quick-start project using the following commands.

git clone quickstart
cd quickstart
npm install

The project is preconfigured with common settings (i.e. src/styles/styles.css and system.config.js files) for starting all the Essential JS 2 components.

Configuring the button

Now all configuration related to the environment is completed. Next, we need to configure the button in an application. Add the HTML button tag with an id attribute set as element to your index.html file.

<!DOCTYPE html>
<html lang="en">
    <title>Essential JS 2</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
    <meta name="description" content="Essential JS 2" />
    <meta name="author" content="Syncfusion" />
    <link rel="shortcut icon" href="resources/favicon.ico" />
    <link href="" rel="stylesheet" />
    <!--style reference from node_modules/@syncfusion/ej2/-->
    <link href="/styles/styles.css" rel="stylesheet" />
    <script src="node_modules/systemjs/dist/system.src.js" type="text/javascript"></script>
    <script src="system.config.js" type="text/javascript"></script>
        <!--Element that is going to be rendered-->
        <button id="element">Button</button>

Now let’s initialize the button component in your app.ts file and append it to #element as shown in following code example.

import { Button } from '@syncfusion/ej2-buttons';

// Initialize button component.
let button: Button = new Button();

// Render initialized button.
npm start

Run the application in the browser using the previous command to render the button. It should appear as follows.

JavaScript Button

Button component

Themes give components a look and feel that fits the application environment. The Essential JS 2 button supports the following themes:

  • Material
  • Office 365
  • Bootstrap
  • High contrast

In this demo application, the Material theme will be used for the button.


Defining button styles

The button has a predefined set of styles. Each style serves its own purpose. You can style the button by simply adding a class name through its interface. For this demo we are going to create several buttons and style them through classes.

<button id="primarybtn">Primary</button>
<button id="successbtn">Success</button>
<button id="infobtn">Info</button>
<button id="warningbtn">Warning</button>
<button id="dangerbtn">Danger</button>
<button id="linkbtn">Link</button>
import { Button } from '@syncfusion/ej2-buttons';
//Primary Button - Used to represent a primary action.
let button: Button = new Button({ cssClass: `e-primary`}, '#primarybtn');
//Success Button - Used to represent a positive action.
button = new Button({ cssClass: `e-success`}, '#successbtn');
//Info Button - Used to represent an informative action.
button = new Button({ cssClass: `e-info`}, '#infobtn');
//Warning Button - Used to represent an action with caution.
button = new Button({ cssClass: `e-warning`}, '#warningbtn');
//Danger Button - Used to represent a negative action.
button = new Button({ cssClass: `e-danger`}, '#dangerbtn');
//Link Button - Changes the appearance of the Button like a hyperlink.
button = new Button({ cssClass: `e-link`}, '#linkbtn');

Predefined Button Styles

Button components with styles 

Creating an icon button

Users tend to perceive visual information better than text. The button can include an icon to add a visual representation of its action. Icons can be added to buttons through their interface. You can customize the icon position to either the left or right side of the button. Icon-only buttons are also supported. In this demo we are going to create a button and load it with different icons.

 /*For stop icon button*/
        .e-stop-icon::before {
            content: '\e790';
        /*For play icon button*/
        .e-play-icon::before {
            content: '\e798';
        /*For open icon button*/
        .e-open-icon::before {
            content: '\e782';
<button id= 'iconbutton'></button>
<button id= 'iconleftbtn'>Play</button>
<button id= 'iconrightbtn'>Stop</button>
import { Button } from '@syncfusion/ej2-buttons';

let button: Button = new Button({iconCss: 'e-icons e-open-icon'}, '#iconbutton');

button = new Button({iconCss: 'e-icons e-play-icon', iconPosition: 'Right'}, '#iconleftbtn');

button = new Button({iconCss: 'e-icons e-stop-icon'}, '#iconrightbtn');

Icon Button

Icon-only button (top), button with icon on left (center), button with icon on right (bottom)


Buttons also have options for customizing their size, shape, and functionalities:

  • A button’s shape can be customized as a round button, block button, or outline button.
  • Two different sizes are available.
  •  A button can be extended as a toggle button or repeat button by handling event handlers.

In this demo we are going to create different buttons and customize their CSS.

/*For round add icon button*/
		.e-add:before {
            content: '\e823';
        .block {
            margin: 40px 0px;
        .block button {
            margin-right: 15px;
<div class="block">
            <div class="col-xs-6 col-sm-4 col-lg-4 col-md-4 ">
                <div class="block">
                    <button id='outlinebtn'></button>
                <div class="block">
                    <button id='roundbtn'></button>
            <div class="col-xs-6 col-sm-4 col-lg-4 col-md-4 ">
                <div class="block">
                    <button id='smallbtn'>Small</button>
                <div class="block">
                    <button id='normalbtn'>Normal</button>
            <div class="col-xs-12 col-sm-4 col-lg-4 col-md-4 ">
                <div class="block">
                    <button id="blockbtn">Block Button</button>
                <div class="block">
                    <button id="primaryblockbtn">Block Button</button>
import { Button } from '@syncfusion/ej2-buttons';
let button: Button =new Button({cssClass:'e-outline e-primary', content: 'outline'}, '#outlinebtn');
button = new Button({cssClass:'e-round e-primary', iconCss: 'e-icons e-add'}, '#roundbtn');
button = new Button({cssClass: `e-block`});
button = new Button({ isPrimary: true, cssClass: `e-block` });
button = new Button({ cssClass: `e-small`}, '#smallbtn');
button = new Button();


Button types

Buttons with different shapes, sizes, and behaviors


In this blog, we have looked at how to create a simple button, change its style, and customize its UI and behavior through its properties and CSS. You can download the button sample on GitHub that has been prepared for this blog.

Feel free to view our interactive samples and documentation to explore the other features of the button. If you have any questions or require clarification, please let us know in the comments section below. You can also contact us through our support forum or Direct-Trac. We are happy to assist you!


Share this post:

Share on twitter
Share on facebook
Share on linkedin
Popular Now

Be the first to get updates

Subscribe RSS feed
Scroll To Top