Search results

Types and Styles

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.
razor
styles.cs
@section ControlsSection{
     @Html.EJS().Button("primarybtn").Content("Primary").CssClass("e-primary").Render()
     @Html.EJS().Button("successbtn").Content("Success").CssClass("e-success").Render()
     @Html.EJS().Button("infobtn").Content("Info").CssClass("e-info").Render()
     @Html.EJS().Button("warningbtn").Content("Warning").CssClass("e-warning").Render()
     @Html.EJS().Button("dangerbtn").Content("Danger").CssClass("e-danger").Render()
     @Html.EJS().Button("linkbtn").Content("Link").CssClass("e-link").Render()
}


<style>

button {
  margin: 25px 5px 20px 20px;
}

</style>
public ActionResult Styles()
{
    return View();
}

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.

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 to their initial values.
razor
basicbutton.cs
@section ControlsSection{
    @{IDictionary<string, object> submit = new Dictionary<string, object>();
      submit.Add("type", "submit");
    }
    @{IDictionary<string, object> reset = new Dictionary<string, object>();
      reset.Add("type", "reset");
    }
    @Html.EJS().Button("submit").Content("Submit").HtmlAttributes(submit).Render()
    @Html.EJS().Button("reset").Content("Reset").HtmlAttributes(reset).Render()
}
<style>

button {
  margin: 25px 5px 20px 20px;
}

</style>
public ActionResult BasicButton()
{
    return View();
}

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.

razor
buttontypes.cs
@section ControlsSection{
     @Html.EJS().Button("flat").Content("Flat").CssClass("e-flat").Render()
     @Html.EJS().Button("outline").Content("Outline").CssClass("e-outline").Render()
     @Html.EJS().Button("round").IconCss("e-icons e-plus-icon").CssClass("e-round").IsPrimary(true).Render()
}


<style>

button {
  margin: 25px 5px 20px 20px;
}

.e-plus-icon::before {
  content: '\e823';
}

</style>
public ActionResult ButtonTypes()
{
    return View();
}

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.

razor
togglebutton.cs
@section ControlsSection{
     @Html.EJS().Button("togglebtn").Content("Play").CssClass("e-flat").IconCss("e-icons e-play-icon").IsToggle(true).Render()
}

<style>
    .e-play-icon::before {
        content: '\e798';
    }

    .e-pause-icon::before {
        content: '\e753';
    }
</style>

<script>

document.getElementById('toggelbtn').onclick = (): void => {
    if (document.getElementById('toggelbtn').classList.contains('e-active')) {
        togglebtn.content = 'Pause';
        togglebtn.iconCss = 'e-icons e-pause-icon';
    } else {
        togglebtn.content = 'Play';
        togglebtn.iconCss = 'e-icons e-play-icon';
    }
};
</script>
public ActionResult ToggleButton()
{
    return View();
}

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 to e-icons 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.

razor
buttonicon.cs
@section ControlsSection{
     @Html.EJS().Button("iconbutton").Content("PREVIOUS").IconCss("e-icons e-prev-icon").Render()
     @Html.EJS().Button("iconposbtn").Content("STOP").IconCss("e-icons e-stop-icon").Render()
}


<style>

button {
  margin: 25px 5px 20px 20px;
}

/*For Right Icon Button*/
.e-stop-icon::before {
  content: '\e790';
}

/*For Left Icon Button*/
.e-prev-icon::before {
  content: '\e716';
}

</style>
public ActionResult ButtonIcon()
{
    return View();
}

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 the iconCss property.

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 property.

razor
buttonsvg.cs
@section ControlsSection{
     @Html.EJS().Button("iconbutton").IconCss("e-search-icon").Render()
}


<style>

button {
  margin: 25px 5px 20px 20px;
}

.e-btn-icon.e-search-icon {
   background: url('search_icon.svg'); 
   height: 25px; 
   width: 25px; 
}

</style>
public ActionResult ButtonSvg()
{
    return View();
}

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.

razor
size.cs
@section ControlsSection{
     @Html.EJS().Button("smallbtn").Content("SMALL").CssClass("e-small").Render()
     @Html.EJS().Button("normalbtn").Content("NORMAL").Render()
}


<style>

button {
  margin: 25px 5px 20px 20px;
}

</style>
public ActionResult Size()
{
    return View();
}

See Also