Close
Angular React Web Components Blazor Angular
Open Source

Angular Button Overview

Angular Button directive is used for creating and adding actionable buttons to a web page/application. There are different Angular Button types that are easy to customize and include several built-in features. By default, Angular Material uses native <button> and <a> elements to deliver an accessible experience.

The Ignite UI for Angular Button directive is intended to turn any button, span, div, or anchor element into a fully functional button. You can use the following Angular Button types - Flat Button, Contained Button, Outlined Button, and Floating Action Button. With customizable colors, options to create themes and change the Angular Button Style and enabling users to choose the button size and more.

Angular Button Example

We have created the Angular Button example below to show you how different button types can appear and look like when they are styled with a border or when a transparent background is applied.



Getting Started with Ignite UI for Angular Button

To get started with the Ignite UI for Angular Button directive, first you need to install Ignite UI for Angular. In an existing Angular application, type the following command:

ng add igniteui-angular

For a complete introduction to the Ignite UI for Angular, read the getting started topic.

The next step is to import the IgxButtonModule in your app.module.ts file.

// app.module.ts
import { IgxButtonModule } from 'igniteui-angular/directives';
// import { IgxButtonModule } from '@infragistics/igniteui-angular'; for licensed package
@NgModule({
    imports: [
        ...
        IgxButtonModule,
        ...
    ]
})
export class AppModule {}

Alternatively, as of 16.0.0 you can import the IgxButtonDirective as a standalone dependency.

// home.component.ts

...
import { IgxButtonDirective } from 'igniteui-angular/directives';
// import { IgxButtonDirective } from '@infragistics/igniteui-angular'; for licensed package

@Component({
    selector: 'app-home',
    template: '<button igxButton="flat">Flat</button>',
    styleUrls: ['home.component.scss'],
    standalone: true,
    imports: [IgxButtonDirective]
})
export class HomeComponent {}

Now that you have the Ignite UI for Angular Button module or directive imported, you can start using the igxButton directive on elements.

Angular Button Types

Flat Button

Use the igxButton directive to add a simple flat button in your component template. Note that if you do not choose a type, by default it will be set to flat.

<button igxButton="flat">Flat</button>

Contained Button

All you have to do to create a contained button is to change the value of the igxButton property:

<button igxButton="contained">Contained</button>

Outlined Button

Analogically, we can switch to outlined type:

<button igxButton="outlined">Outlined</button>

Icon Button

As of version 17.1.0 the IgniteUI for Angular exposes a new igxIconButton directive intended to turn icons into fully functional buttons. You can read more about the Icon Button here.

<button igxIconButton="flat">
  <igx-icon fontSet="material">favorite</igx-icon>
</button>

This component uses Material Icons. Add the following link to your index.html: <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

Floating Action Button

We can create a floating action button and use an icon to display:

<button igxButton="fab">
  <igx-icon fontSet="material">edit</igx-icon>
</button>

To create an extended FAB, you can add any element prior to the igx-icon:

<button class="btn" igxButton="fab">
  <span>like</span>
  <igx-icon fontSet="material">favorite</igx-icon>
</button>

To get the extended FAB text styled properly, use <span> or <div> tags.

Examples

Angular Disable Button

The disabled property can be used to make a button unclickable:

<button igxButton="contained" [disabled]="'true'">Disabled</button>

Ripple

The igxRipple directive adds a ripple effect to your buttons or other specified elements. You can easily change the default ripple color, position and duration, using its properties:

<button igxButton="contained" igxRipple="white" [igxRippleCentered]="true" [igxRippleDuration]="2000">
  Ripple
</button>

Span

We can also use the igxButton directive to turn elements like span and div into Ignite UI for Angular styled buttons. The default colors can be customized via the igxButtonColor and the igxButtonBackground properties:

<span igxButton="contained" igxButtonColor="white" igxButtonBackground="#72da67" igxRipple="white">
  Span
</span>

Size

We can allow the user to choose the size of the igxButton by using the --ig-size custom CSS property. To do this, first we have to import the IgxButtonGroupModule, and then use the igxButtonGroup component to display size values. This way whenever one gets selected, we will update the —ig-size CSS property.

// app.module.ts
...
import { IgxButtonGroupModule } from 'igniteui-angular/button-group';
// import { IgxButtonGroupModule } from '@infragistics/igniteui-angular'; for licensed package
@NgModule({
    imports: [
        ...
        IgxButtonGroupModule
        ...
    ]
})
{/*buttons-density.component.html*/}
<igx-buttongroup [values]="sizes" (selected)="selectSize($event)"></igx-buttongroup>
...
<button igxButton="flat">Flat</button>
// buttons-density.component.ts
public size = "large";
public sizes;
public ngOnInit() {
    this.sizes = [
        { label: 'large', selected: this.size === 'large', togglable: true },
        { label: 'medium', selected: this.size === 'medium', togglable: true },
        { label: 'small', selected: this.size === 'small', togglable: true }
    ];
}

public selectSize(event: any) {
    this.size = this.sizes[event.index].label;
}

@HostBinding('style.--ig-size')
protected get sizeStyle() {
    return `var(--ig-size-${this.size})`;
}

If all went well, you should see something like the following in the browser:


Styling

Button Theme Property Map

When you modify a primary property, all related dependent properties are updated automatically:

Material Theme

Flat Button

Primary PropertyDependent PropertyDescription
$foreground$hover-backgroundBackground color for hovered button
$focus-backgroundBackground color for focused button
$focus-hover-backgroundBackground color for button on focus + hover
$active-backgroundBackground color for active button
$hover-foregroundForeground color for hovered button
$icon-color-hoverIcon color for hovered button
$focus-foregroundForeground color for focused button
$focus-hover-foregroundForeground color for button on focus + hover
$active-foregroundForeground color for active button
$focus-visible-backgroundBackground when focus is visible
$focus-visible-foregroundForeground when focus is visible

Contained Button

Primary PropertyDependent PropertyDescription
$background$foregroundForeground based on background
$icon-colorIcon color based on background
$hover-backgroundHover background color
$hover-foregroundForeground on hover
$icon-color-hoverIcon color on hover
$focus-backgroundFocus background color
$focus-foregroundForeground on focus
$focus-hover-backgroundFocus + hover background
$focus-hover-foregroundForeground on focus + hover
$active-backgroundActive background color
$active-foregroundActive foreground color
$focus-visible-backgroundBackground when focus is visible
$focus-visible-foregroundForeground when focus is visible

Outlined Button

Primary PropertyDependent PropertyDescription
$foreground$hover-backgroundBackground color for hovered button
$focus-backgroundBackground color for focused button
$focus-hover-backgroundBackground color for button on focus + hover
$active-backgroundBackground color for active button
$hover-foregroundForeground color for hovered button
$icon-color-hoverIcon color for hovered button
$focus-foregroundForeground color for focused button
$focus-hover-foregroundForeground color for button on focus + hover
$active-foregroundForeground color for active button
$focus-visible-backgroundBackground when focus is visible
$focus-visible-foregroundForeground when focus is visible
$border-colorThe border color for outlined buttons.
$hover-border-colorThe border color for hovered outlined buttons.
$focus-border-colorThe border color for focused outlined buttons.
$focus-visible-border-colorThe border color for outlined buttons when focus is visible.
$active-border-colorThe border color for active outlined buttons.

FAB Button

Primary PropertyDependent PropertyDescription
$background$foregroundForeground based on background
$icon-colorIcon color based on background
$hover-backgroundHover background color
$hover-foregroundForeground on hover
$icon-color-hoverIcon color on hover
$focus-backgroundFocus background color
$focus-foregroundForeground on focus
$active-backgroundActive background color
$active-foregroundActive foreground color
$focus-hover-backgroundFocus + hover background
$focus-hover-foregroundForeground on focus + hover
$focus-visible-backgroundBackground when focus is visible
$focus-visible-foregroundForeground when focus is visible

Fluent Theme

Flat Button

Primary PropertyDependent PropertyDescription
$foreground$hover-backgroundBackground color for hovered button
$focus-backgroundBackground color for focused button
$focus-hover-backgroundBackground color for button on focus + hover
$active-backgroundBackground color for active button
$hover-foregroundForeground color for hovered button
$icon-color-hoverIcon color for hovered button
$focus-foregroundForeground color for focused button
$focus-hover-foregroundForeground color for button on focus + hover
$active-foregroundForeground color for active button
$focus-visible-foregroundForeground when focus is visible
$focus-visible-border-colorBorder color when focus is visible

Contained Button

Primary PropertyDependent PropertyDescription
$background$foregroundForeground based on background
$icon-colorIcon color based on background
$hover-backgroundHover background color
$focus-backgroundFocus background color
$active-backgroundActive background color
$hover-foregroundForeground on hover
$icon-color-hoverIcon color on hover
$focus-foregroundForeground on focus
$active-foregroundActive foreground color
$focus-hover-backgroundFocus + hover background
$focus-hover-foregroundForeground on focus + hover
$focus-visible-backgroundBackground when focus is visible
$focus-visible-foregroundForeground when focus is visible
$focus-visible-border-colorBorder color when focus is visible

Outlined Button

Primary PropertyDependent PropertyDescription
$foreground$hover-backgroundBackground color for hovered outlined button.
$focus-backgroundBackground color for focused outlined button.
$focus-hover-backgroundBackground color for outlined button on focus + hover.
$active-backgroundBackground color for active outlined button.
$hover-foregroundForeground color for hovered outlined button.
$icon-color-hoverIcon color for hovered outlined button.
$focus-foregroundForeground color for focused outlined button.
$focus-hover-foregroundForeground color for outlined button on focus + hover.
$active-foregroundForeground color for active outlined button.
$focus-visible-foregroundForeground color for outlined button when focus is visible.
$focus-visible-border-colorBorder color for outlined button when focus is visible.
$border-colorBorder color for outlined button.
$hover-border-colorBorder color for hovered outlined button.
$focus-border-colorBorder color for focused outlined button.
$active-border-colorBorder color for active outlined button.

FAB Button

Primary PropertyDependent PropertyDescription
$background$foregroundForeground based on background
$icon-colorIcon color based on background
$hover-backgroundHover background color
$hover-foregroundForeground on hover
$icon-color-hoverIcon color on hover
$active-backgroundActive background color
$active-foregroundActive foreground color
$focus-backgroundFocus background color
$focus-foregroundForeground on focus
$focus-hover-backgroundFocus + hover background
$focus-hover-foregroundForeground on focus + hover
$focus-visible-backgroundBackground when focus is visible
$focus-visible-foregroundForeground when focus is visible
$focus-visible-border-colorBorder color when focus is visible

Bootstrap Theme

Flat Button

Primary PropertyDependent PropertyDescription
$foreground$hover-foregroundForeground color for hovered button
$icon-color-hoverIcon color for hovered button
$focus-foregroundForeground color for focused button
$focus-hover-foregroundForeground color for button on focus + hover
$active-foregroundForeground color for active button
$focus-visible-foregroundForeground when focus is visible
$focus-visible-border-colorBorder color when focus is visible
$disabled-foregroundForeground color for disabled button
$disabled-icon-colorIcon color for disabled button
$shadow-colorShadow color

Contained Button

Primary PropertyDependent PropertyDescription
$background$foregroundForeground based on background
$icon-colorIcon color based on background
$hover-backgroundHover background color
$focus-backgroundFocus background color
$active-backgroundActive background color
$hover-foregroundForeground on hover
$icon-color-hoverIcon color on hover
$focus-foregroundForeground on focus
$focus-hover-backgroundFocus + hover background
$focus-hover-foregroundForeground on focus + hover
$focus-visible-backgroundBackground when focus is visible
$focus-visible-foregroundForeground when focus is visible
$active-foregroundActive foreground color
$shadow-colorShadow color
$disabled-backgroundDisabled background color
$disabled-foregroundDisabled foreground color
$disabled-icon-colorDisabled icon color

Outlined Button

Primary PropertyDependent PropertyDescription
$foreground$hover-backgroundBackground color for hovered button
$focus-backgroundBackground color for focused button
$focus-hover-backgroundBackground color for button on focus + hover
$active-backgroundBackground color for active button
$hover-foregroundForeground color for hovered button
$icon-color-hoverIcon color for hovered button
$focus-foregroundForeground color for focused button
$focus-hover-foregroundForeground color for button on focus + hover
$active-foregroundForeground color for active button
$focus-visible-backgroundBackground when focus is visible
$focus-visible-foregroundForeground when focus is visible
$focus-visible-border-colorBorder color when focus is visible
$disabled-foregroundForeground color for disabled button
$disabled-icon-colorIcon color for disabled button
$disabled-border-colorBorder color for disabled button
$hover-border-colorHover border color
$focus-border-colorFocus border color
$active-border-colorActive border color
$shadow-colorShadow color

FAB Button

Primary PropertyDependent PropertyDescription
$background$foregroundForeground based on background
$icon-colorIcon color based on background
$hover-backgroundHover background color
$focus-backgroundFocus background color
$active-backgroundActive background color
$disabled-backgroundDisabled background color
$hover-foregroundForeground on hover
$icon-color-hoverIcon color on hover
$focus-foregroundForeground on focus
$focus-hover-backgroundFocus + hover background
$focus-hover-foregroundForeground on focus + hover
$focus-visible-backgroundBackground when focus is visible
$focus-visible-foregroundForeground when focus is visible
$active-foregroundActive foreground color
$shadow-colorShadow color
$disabled-foregroundDisabled foreground color
$disabled-icon-colorDisabled icon color

Indigo Theme

Flat Button

Primary PropertyDependent PropertyDescription
$foreground$hover-backgroundBackground color for hovered button
$focus-backgroundBackground color for focused button
$focus-hover-backgroundBackground color for button on focus + hover
$active-backgroundBackground color for active button
$hover-foregroundForeground color for hovered button
$icon-color-hoverIcon color for hovered button
$focus-foregroundForeground color for focused button
$focus-hover-foregroundForeground color for button on focus + hover
$active-foregroundForeground color for active button
$focus-visible-foregroundForeground when focus is visible
$disabled-foregroundDisabled foreground color
$disabled-icon-colorDisabled icon color
$shadow-colorShadow color

Contained Button

Primary PropertyDependent PropertyDescription
$background$foregroundForeground based on background
$icon-colorIcon color based on background
$hover-backgroundHover background color
$focus-backgroundFocus background color
$active-backgroundActive background color
$hover-foregroundForeground on hover
$icon-color-hoverIcon color on hover
$focus-foregroundForeground on focus
$focus-hover-backgroundFocus + hover background
$focus-hover-foregroundForeground on focus + hover
$focus-visible-backgroundBackground when focus is visible
$focus-visible-foregroundForeground when focus is visible
$active-foregroundActive foreground color
$shadow-colorShadow color
$disabled-backgroundDisabled background color
$disabled-foregroundDisabled foreground color
$disabled-icon-colorDisabled icon color

Outlined Button

Primary PropertyDependent PropertyDescription
$foreground$hover-backgroundBackground color for hovered button
$focus-backgroundBackground color for focused button
$focus-hover-backgroundBackground color for button on focus + hover
$active-backgroundBackground color for active button
$hover-foregroundForeground color for hovered button
$icon-color-hoverIcon color for hovered button
$focus-foregroundForeground color for focused button
$focus-hover-foregroundForeground color for button on focus + hover
$active-foregroundForeground color for active button
$focus-visible-backgroundBackground when focus is visible
$focus-visible-foregroundForeground when focus is visible
$focus-visible-border-colorBorder color when focus is visible
$border-colorBorder color
$hover-border-colorHover border color
$focus-border-colorFocus border color
$active-border-colorActive border color
$shadow-colorShadow color

FAB Button

Primary PropertyDependent PropertyDescription
$background$foregroundForeground based on background
$icon-colorIcon color based on background
$hover-backgroundHover background color
$focus-backgroundFocus background color
$active-backgroundActive background color
$disabled-backgroundDisabled background color
$hover-foregroundForeground on hover
$icon-color-hoverIcon color on hover
$focus-foregroundForeground on focus
$focus-hover-backgroundFocus + hover background
$focus-hover-foregroundForeground on focus + hover
$focus-visible-backgroundBackground when focus is visible
$focus-visible-foregroundForeground when focus is visible
$active-foregroundActive foreground color
$shadow-colorShadow color
$disabled-foregroundDisabled foreground color
$disabled-icon-colorDisabled icon color

Note: The resulting dependent properties may vary slightly depending on the selected theme (Material, Fluent, Bootstrap, Indigo).

To style the button you can use our type-specific theme functions: flat-button-theme, outlined-button-theme, contained-button-theme, and fab-button-theme.

Each of them will target only the buttons of that specific type.

To get started, first import the themes module, which includes all theme functions and component mixins:

@use "igniteui-angular/theming" as *;

// IMPORTANT: Prior to Ignite UI for Angular version 13 use:
// @import '~igniteui-angular/lib/core/styles/themes/index';

Next, create a new theme that extends the type-specific theme function for the type of button you are styling. In this example, we will use the contained-button-theme function and pass values to the $foreground and the $background parameters, along with their respective hover and active parameters.

Given the following markup:

<div class="my-contained-btn">

  <button igxButton="contained">Contained button</button>
</div>

You can create the following theme:

$custom-contained-theme: contained-button-theme(
    $background: #f9f0ff,
    $foreground: #722ed1,
    $hover-background: #efdbff,
    $hover-foreground: #9254de,
    $active-foreground: #531dab,
    $active-background: #dfc2fa,
);

Take a look at the contained-button-theme section for a complete list of available parameters for styling the contained-type buttons.

Finally, include the custom theme in your application:

.my-contained-btn {
  @include tokens($custom-contained-theme);
}

With the type-specific theme functions, styling buttons is much easier.

For contained-button-theme and fab-button-theme functions, you only need to provide a color value to the $background parameter. All other button state and text colors (if they are not provided) will then be automatically generated and applied based on that value.

The text color is determined by the newly added adaptive-contrast function, which calculates whether black or white provides better contrast against the supplied background color.

For flat-button-theme and outlined-button-theme functions, the button state colors are also automatically generated and applied, but they are derived from the supplied $foreground parameter instead of $background.

In the sample below, you can see how using the button component with customized CSS variables allows you to create a design that visually resembles the button used in the Ant design system.

The sample uses the Bootstrap Light schema.

Styling with Tailwind

You can style the button using our custom Tailwind utility classes. Make sure to set up Tailwind first.

Along with the tailwind import in your global stylesheet, you can apply the desired theme utilities as follows:

@import "tailwindcss";
...
@use 'igniteui-theming/tailwind/utilities/material.css';

The utility file includes both light and dark theme variants.

  • Use light-* classes for the light theme.
  • Use dark-* classes for the dark theme.
  • Append the component name after the prefix. Because the button has types, the classes are used like so, e.g., light-contained-button, light-flat-button dark-outlined-button, dark-fab-button, etc.

Once applied, these classes enable dynamic theme calculations. From there, you can override the generated CSS variables using arbitrary properties. After the colon, provide any valid CSS color format (HEX, CSS variable, RGB, etc.).

You can find the full list of properties in the button-theme which reflect differently in the different variants, the primary property for the flat and outlined buttons is $foreground and for the contained and fab buttons is $background. The syntax is as follows:

<div class="buttons-sample">

  <div class="button-sample">

    <button
    igxButton="flat"
    class="!light-flat-button ![--foreground:#7B9E89]">
      Flat Button
    </button>
  
</div>
  <div class="button-sample">

    <button
    igxButton="contained"
    class="!light-contained-button ![--background:#7B9E89]">
      Contained Button
    </button>
  
</div>
  <div class="button-sample">

    <button
    igxButton="outlined"
    class="!light-outlined-button ![--foreground:#7B9E89]">
      Outlined Button
    </button>
  
</div>
  <div class="button-sample">

    <button
    igxButton="fab"
    class="!light-fab-button ![--background:#7B9E89]">
      Fab Button
    </button>
  
</div>
</div>

The exclamation mark(!) is required to ensure the utility class takes precedence. Tailwind applies styles in layers, and without marking these styles as important, they will get overridden by the component’s default theme.

At the end your buttons should look like this:

Custom sizing

You can change the button height either by using the --size variable, targeting the button directly:

button {
  --size: 50px;
}

Or you can use the universal --ig-button-size variable to target all instances:

<div class="my-app">

  <button igxButton="contained"></button>
</div>
.my-app {
  --ig-button-size: 50px;
}

You can also use one of the predefined sizes, assigning it to the --ig-size variable. The available values for --ig-size are --ig-size-small, --ig-size-medium, and --ig-size-large:

button {
  --ig-size: var(--ig-size-large);
}

Learn more about it in the Size article.


API References

Additional Resources


Our community is active and always welcoming to new ideas.