Types and Styles in Button Control

19 Dec 20227 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.
@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();
}

ASP.NET MVC Button styles

NOTE

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.
@{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();
}

ASP.NET MVC Button

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.

@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();
}

ASP.NET MVC Button types

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.

@Html.EJS().Button("togglebtn").Content("Play").Click("clickHandler").CssClass("e-flat").IconCss("e-btn-sb-icons e-play-icon").IsToggle(true).Render()

<style>
	@@font-face {
        font-family: 'button-icons';
        src: url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAAKAIAAAwAgT1MvMj1uSf8AAAEoAAAAVmNtYXDOXM6wAAABtAAAAFRnbHlmcV/SKgAAAiQAAAJAaGVhZBNt0QcAAADQAAAANmhoZWEIUQQOAAAArAAAACRobXR4NAAAAAAAAYAAAAA0bG9jYQNWA+AAAAIIAAAAHG1heHABGQAZAAABCAAAACBuYW1lASvfhQAABGQAAAJhcG9zdFAouWkAAAbIAAAA2AABAAAEAAAAAFwEAAAAAAAD9AABAAAAAAAAAAAAAAAAAAAADQABAAAAAQAAYD3WXF8PPPUACwQAAAAAANgtxgsAAAAA2C3GCwAAAAAD9AP0AAAACAACAAAAAAAAAAEAAAANAA0AAgAAAAAAAgAAAAoACgAAAP8AAAAAAAAAAQQAAZAABQAAAokCzAAAAI8CiQLMAAAB6wAyAQgAAAIABQMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUGZFZABA5wHnDQQAAAAAXAQAAAAAAAABAAAAAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAAAAAIAAAADAAAAFAADAAEAA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BAkAAwAYAKkAAwABBAkABAAYAMEAAwABBAkABQAWANkAAwABBAkABgAYAO8AAwABBAkACgBYAQcAAwABBAkACwAkAV8gYnV0dG9uLWljb25zUmVndWxhcmJ1dHRvbi1pY29uc2J1dHRvbi1pY29uc1ZlcnNpb24gMS4wYnV0dG9uLWljb25zRm9udCBnZW5lcmF0ZWQgdXNpbmcgU3luY2Z1c2lvbiBNZXRybyBTdHVkaW93d3cuc3luY2Z1c2lvbi5jb20AIABiAHUAdAB0AG8AbgAtAGkAYwBvAG4AcwBSAGUAZwB1AGwAYQByAGIAdQB0AHQAbwBuAC0AaQBjAG8AbgBzAGIAdQB0AHQAbwBuAC0AaQBjAG8AbgBzAFYAZQByAHMAaQBvAG4AIAAxAC4AMABiAHUAdAB0AG8AbgAtAGkAYwBvAG4AcwBGAG8AbgB0ACAAZwBlAG4AZQByAGEAdABlAGQAIAB1AHMAaQBuAGcAIABTAHkAbgBjAGYAdQBzAGkAbwBuACAATQBlAHQAcgBvACAAUwB0AHUAZABpAG8AdwB3AHcALgBzAHkAbgBjAGYAdQBzAGkAbwBuAC4AYwBvAG0AAAAAAgAAAAAAAAAKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANAQIBAwEEAQUBBgEHAQgBCQEKAQsBDAENAQ4ACm1lZGlhLXBsYXkLbWVkaWEtcGF1c2UQLWRvd25sb2FkLTAyLXdmLQltZWRpYS1lbmQHYWRkLW5ldwtuZXctbWFpbC13ZhB1c2VyLWRvd25sb2FkLXdmDGV4cGFuZC0wMy13Zg5kb3dubG9hZC0wMi13ZgphZGQtbmV3XzAxC21lZGlhLWVqZWN0Dm1lZGlhLWVqZWN0LTAxAAA=) format('truetype');
        font-weight: normal;
        font-style: normal;
    }

    .e-btn-sb-icons {
        font-family: 'button-icons';
        line-height: 1;
        font-style: normal;
        font-weight: normal;
        font-variant: normal;
        text-transform: none;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    .e-play-icon::before {
        content: '\e701';
    }

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

<script>
	function clickHandler() {
		var togglebtn = ej.base.getComponent(document.getElementById("togglebtn"), 'btn');
		if (document.getElementById('togglebtn').classList.contains('e-active')) {
			togglebtn.content = 'Pause';
			togglebtn.iconCss = 'e-btn-sb-icons e-pause-icon';
		} else {
			togglebtn.content = 'Play';
			togglebtn.iconCss = 'e-btn-sb-icons e-play-icon';
		}
	}
</script>
public ActionResult ToggleButton()
{
    return View();
}

ASP.NET MVC Toggle Button

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.

@Html.EJS().Button("iconbutton").Content("PREVIOUS").IconCss("e-btn-sb-icon e-prev-icon").Render()
@Html.EJS().Button("iconposbtn").Content("STOP").IconCss("e-btn-sb-icon e-stop-icon").Render()

<style>

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

 @@font-face {
  font-family: 'btn-icon';
  src: url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAAKAIAAAwAgT1MvMj1tSfgAAAEoAAAAVmNtYXDnH+dzAAABoAAAAEJnbHlm1v48pAAAAfgAAAQYaGVhZBOPfZcAAADQAAAANmhoZWEIUQQJAAAArAAAACRobXR4IAAAAAAAAYAAAAAgbG9jYQN6ApQAAAHkAAAAEm1heHABFQCqAAABCAAAACBuYW1l07lFxAAABhAAAAIxcG9zdK9uovoAAAhEAAAAgAABAAAEAAAAAFwEAAAAAAAD9AABAAAAAAAAAAAAAAAAAAAACAABAAAAAQAAJ1LUzF8PPPUACwQAAAAAANg+nFMAAAAA2D6cUwAAAAAD9AP0AAAACAACAAAAAAAAAAEAAAAIAJ4AAwAAAAAAAgAAAAoACgAAAP8AAAAAAAAAAQQAAZAABQAAAokCzAAAAI8CiQLMAAAB6wAyAQgAAAIABQMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUGZFZABA5wDnBgQAAAAAXAQ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AGUAbgBlAHIAYQB0AGUAZAAgAHUAcwBpAG4AZwAgAFMAeQBuAGMAZgB1AHMAaQBvAG4AIABNAGUAdAByAG8AIABTAHQAdQBkAGkAbwB3AHcAdwAuAHMAeQBuAGMAZgB1AHMAaQBvAG4ALgBjAG8AbQAAAAACAAAAAAAAAAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgBAgEDAQQBBQEGAQcBCAEJAAptZWRpYS1wbGF5C21lZGlhLXBhdXNlDmFycm93aGVhZC1sZWZ0BHN0b3AJbGlrZS0tLTAxBGNvcHkQLWRvd25sb2FkLTAyLXdmLQAA) format('truetype');
  font-weight: normal;
  font-style: normal;
}

.e-btn-sb-icon {
  font-family: 'btn-icon' !important;
  speak: none;
  font-size: 55px;
  font-style: normal;
  font-weight: normal;
  font-variant: normal;
  text-transform: none;
  line-height: 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/*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();
}

ASP.NET MVC Button with font icons

NOTE

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.

@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();
}

ASP.NET MVC Button with SVG image

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.

@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();
}

ASP.NET MVC Button size

See Also