Types and styles in Angular Button component
27 Apr 202417 minutes to read
This section explains the different styles and types of Buttons.
Button styles
The Essential JS 2 Button has the following predefined styles that can be defined using the cssClass
property.
Class | Description |
---|---|
e-primary | Used to represent a primary action. |
e-success | Used to represent a positive action. |
e-info | Used to represent an informative action. |
e-warning | Used to represent an action with caution. |
e-danger | Used to represent a negative action. |
e-link | Changes the appearance of the Button like a hyperlink. |
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { enableRipple } from '@syncfusion/ej2-base'
import { Component } from '@angular/core';
@Component({
imports: [
ButtonModule
],
standalone: true,
selector: 'app-root',
styleUrls: ['./style.css'],
template: `<div class="e-section-control">
<!-- Primary Button - Used to represent a primary action. -->
<button ejs-button cssClass="e-primary">Primary</button>
<!-- Success Button - Used to represent a positive action. -->
<button ejs-button cssClass="e-success">Success</button>
<!-- Info Button - Used to represent an informative action -->
<button ejs-button cssClass="e-info">Info</button>
<!-- Warning Button - Used to represent an action with caution. -->
<button ejs-button cssClass="e-warning">Warning</button>
<!-- Danger Button - Used to represent a negative action. -->
<button ejs-button cssClass="e-danger">Danger</button>
<!-- Link Button - Changes the appearance of the Button like a hyperlink. -->
<button ejs-button cssClass="e-link">Link</button>
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Predefined Button styles provide only the visual indication. So, Button content should define the Button
style for the users of assistive technologies such as screen readers.
Primary action button can also be achieved by settingisPrimary
property astrue
.
Button types
The types of Essential JS 2 Button are as follows:
- Basic types
- Flat Button
- Outline Button
- Round Button
- Toggle Button
Basic types
The basic Button types are explained below.
Type | Description |
---|---|
Button | Defines a click Button. |
Submit | This Button submits the form data to the server. |
Reset | This Button resets all the controls in the form elements to their initial values. |
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { enableRipple } from '@syncfusion/ej2-base'
import { Component } from '@angular/core';
@Component({
imports: [
ButtonModule
],
standalone: true,
selector: 'app-root',
styleUrls: ['./style.css'],
template: `<div class="e-section-control">
<form>
<!-- Submit type button -->
<button type="submit" ejs-button>Submit</button>
<!-- Reset type button -->
<button type="reset" ejs-button>Reset</button>
</form>
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Flat Button
The Flat Button is styled with no background color. To create a flat Button,
set the cssClass
property to e-flat
.
Outline Button
An outline Button has a border with transparent background. To create an outline Button,
set the cssClass
property to e-outline
.
Round Button
A round Button is shaped like a circle. Usually, it contains an icon representing its action.
To create a round Button, set the cssClass
property to e-round
.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { enableRipple } from '@syncfusion/ej2-base'
import { Component } from '@angular/core';
@Component({
imports: [
ButtonModule
],
standalone: true,
selector: 'app-root',
styleUrls: ['./style.css'],
template: `<div class="e-section-control">
<!-- Flat Button. -->
<button ejs-button cssClass="e-flat">Flat</button>
<!-- Outline Button. -->
<button ejs-button cssClass="e-outline">Outline</button>
<!-- Round Button - Icon can be loaded by setting "e-icons e-plus-icon" in "iconCss" property.-->
<!-- Use "e-icons" class name to load Essential JS 2 built-in icons.-->
<!-- Use "e-plus-icon" class name to load plus icon that you can refer in "styles.css" -->
<button ejs-button cssClass="e-round" iconCss="e-icons e-plus-icon" [isPrimary]="true"></button>
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Toggle Button
A toggle Button allows you to change between the two states. The Button is active in toggled state and can be recognized through the e-active
class. The functionality of the toggle Button is handled by click event. To create a toggle Button, set the isToggle
property to true
. In the following code snippet, the toggle Button text changes to play/pause based on the state of the Button with the use of click event.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { enableRipple } from '@syncfusion/ej2-base'
import { Component, ViewChild, HostListener } from '@angular/core';
import { ButtonComponent } from '@syncfusion/ej2-angular-buttons';
@Component({
imports: [
ButtonModule
],
standalone: true,
selector: 'app-root',
styleUrls: ['./style.css'],
template: `<div class="e-section-control">
<!-- Button is active in toggled state. -->
<button #togglebtn ejs-button cssClass="e-flat" iconCss="e-btn-sb-icon e-play-icon" [isToggle]="true" content="Play"></button>
</div>`
})
// Click event handled using HostListener.
export class AppComponent {
@ViewChild('togglebtn') togglebtn: ButtonComponent | any;
@HostListener('click', ['togglebtn'])
btnClick() {
if(this.togglebtn.element.classList.contains('e-active')){
this.togglebtn.content = 'Pause';
this.togglebtn.iconCss = 'e-btn-sb-icon e-pause-icon';
}
else {
this.togglebtn.content = 'Play';
this.togglebtn.iconCss = 'e-btn-sb-icon e-play-icon';
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Icons
Button with font icons
The Button can have an icon to provide the visual representation of the action. To place the icon on a Button,set the iconCss
property with the required icon CSS. By default, the icon is positioned to the left side of the Button. You can customize the icon’s position
by using the iconPosition
property.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { enableRipple } from '@syncfusion/ej2-base'
import { Component } from '@angular/core';
@Component({
imports: [
ButtonModule
],
standalone: true,
selector: 'app-root',
styleUrls: ['./style.css'],
template: `<div class="e-section-control">
<!-- To position the icon to the left of the text on a Button. -->
<button ejs-button iconCss="e-btn-sb-icon e-prev-icon">Previous</button>
<!-- To position the icon to the right of the text on a Button. -->
<button ejs-button iconCss= "e-btn-sb-icon e-stop-icon" iconPosition="Right">Stop</button>
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Button with SVG image
SVG image can be added to the Button using iconCss
property.
In the following example, SVG image is added using the iconCss class e-search-icon
by setting height
and width
.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { enableRipple } from '@syncfusion/ej2-base'
import { Component } from '@angular/core';
@Component({
imports: [
ButtonModule
],
standalone: true,
selector: 'app-root',
styleUrls: ['styles.css'],
template: `<div class="e-section-control">
<button ejs-button iconCss= "e-search-icon"></button>
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
The Essential JS 2 provides a set of icons that can be loaded by applying
e-icons
class name to the element. You can also use third party icons on the Button using theiconCss
property.
Button size
The two types of Button sizes are default and small. To change the size of the default Button to small Button, set the cssClass
property to e-small
.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { enableRipple } from '@syncfusion/ej2-base'
import { Component } from '@angular/core';
@Component({
imports: [
ButtonModule
],
standalone: true,
selector: 'app-root',
styleUrls: ['./style.css'],
template: `<div class="e-section-control">
<!-- Small Button. -->
<button ejs-button cssClass="e-small">Small</button>
<!-- Normal Button. -->
<button ejs-button>Normal</button>
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));