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/button';
// 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/button';
// 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>
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>
Note
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 Property | Dependent Property | Description |
|---|---|---|
$foreground |
$hover-background | Background color for hovered button |
| $focus-background | Background color for focused button | |
| $focus-hover-background | Background color for button on focus + hover | |
| $active-background | Background color for active button | |
| $hover-foreground | Foreground color for hovered button | |
| $icon-color-hover | Icon color for hovered button | |
| $focus-foreground | Foreground color for focused button | |
| $focus-hover-foreground | Foreground color for button on focus + hover | |
| $active-foreground | Foreground color for active button | |
| $focus-visible-background | Background when focus is visible | |
| $focus-visible-foreground | Foreground when focus is visible |
Contained Button
| Primary Property | Dependent Property | Description |
|---|---|---|
$background |
$foreground | Foreground based on background |
| $icon-color | Icon color based on background | |
| $hover-background | Hover background color | |
| $hover-foreground | Foreground on hover | |
| $icon-color-hover | Icon color on hover | |
| $focus-background | Focus background color | |
| $focus-foreground | Foreground on focus | |
| $focus-hover-background | Focus + hover background | |
| $focus-hover-foreground | Foreground on focus + hover | |
| $active-background | Active background color | |
| $active-foreground | Active foreground color | |
| $focus-visible-background | Background when focus is visible | |
| $focus-visible-foreground | Foreground when focus is visible |
Outlined Button
| Primary Property | Dependent Property | Description |
|---|---|---|
$foreground |
$hover-background | Background color for hovered button |
| $focus-background | Background color for focused button | |
| $focus-hover-background | Background color for button on focus + hover | |
| $active-background | Background color for active button | |
| $hover-foreground | Foreground color for hovered button | |
| $icon-color-hover | Icon color for hovered button | |
| $focus-foreground | Foreground color for focused button | |
| $focus-hover-foreground | Foreground color for button on focus + hover | |
| $active-foreground | Foreground color for active button | |
| $focus-visible-background | Background when focus is visible | |
| $focus-visible-foreground | Foreground when focus is visible | |
| $border-color | The border color for outlined buttons. | |
| $hover-border-color | The border color for hovered outlined buttons. | |
| $focus-border-color | The border color for focused outlined buttons. | |
| $focus-visible-border-color | The border color for outlined buttons when focus is visible. | |
| $active-border-color | The border color for active outlined buttons. |
FAB Button
| Primary Property | Dependent Property | Description |
|---|---|---|
$background |
$foreground | Foreground based on background |
| $icon-color | Icon color based on background | |
| $hover-background | Hover background color | |
| $hover-foreground | Foreground on hover | |
| $icon-color-hover | Icon color on hover | |
| $focus-background | Focus background color | |
| $focus-foreground | Foreground on focus | |
| $active-background | Active background color | |
| $active-foreground | Active foreground color | |
| $focus-hover-background | Focus + hover background | |
| $focus-hover-foreground | Foreground on focus + hover | |
| $focus-visible-background | Background when focus is visible | |
| $focus-visible-foreground | Foreground when focus is visible |
Fluent Theme
Flat Button
| Primary Property | Dependent Property | Description |
|---|---|---|
$foreground |
$hover-background | Background color for hovered button |
| $focus-background | Background color for focused button | |
| $focus-hover-background | Background color for button on focus + hover | |
| $active-background | Background color for active button | |
| $hover-foreground | Foreground color for hovered button | |
| $icon-color-hover | Icon color for hovered button | |
| $focus-foreground | Foreground color for focused button | |
| $focus-hover-foreground | Foreground color for button on focus + hover | |
| $active-foreground | Foreground color for active button | |
| $focus-visible-foreground | Foreground when focus is visible | |
| $focus-visible-border-color | Border color when focus is visible |
Contained Button
| Primary Property | Dependent Property | Description |
|---|---|---|
$background | $foreground | Foreground based on background |
| $icon-color | Icon color based on background | |
| $hover-background | Hover background color | |
| $focus-background | Focus background color | |
| $active-background | Active background color | |
| $hover-foreground | Foreground on hover | |
| $icon-color-hover | Icon color on hover | |
| $focus-foreground | Foreground on focus | |
| $active-foreground | Active foreground color | |
| $focus-hover-background | Focus + hover background | |
| $focus-hover-foreground | Foreground on focus + hover | |
| $focus-visible-background | Background when focus is visible | |
| $focus-visible-foreground | Foreground when focus is visible | |
| $focus-visible-border-color | Border color when focus is visible |
Outlined Button
| Primary Property | Dependent Property | Description |
|---|---|---|
$foreground | $hover-background | Background color for hovered outlined button. |
| $focus-background | Background color for focused outlined button. | |
| $focus-hover-background | Background color for outlined button on focus + hover. | |
| $active-background | Background color for active outlined button. | |
| $hover-foreground | Foreground color for hovered outlined button. | |
| $icon-color-hover | Icon color for hovered outlined button. | |
| $focus-foreground | Foreground color for focused outlined button. | |
| $focus-hover-foreground | Foreground color for outlined button on focus + hover. | |
| $active-foreground | Foreground color for active outlined button. | |
| $focus-visible-foreground | Foreground color for outlined button when focus is visible. | |
| $focus-visible-border-color | Border color for outlined button when focus is visible. | |
| $border-color | Border color for outlined button. | |
| $hover-border-color | Border color for hovered outlined button. | |
| $focus-border-color | Border color for focused outlined button. | |
| $active-border-color | Border color for active outlined button. |
FAB Button
| Primary Property | Dependent Property | Description |
|---|---|---|
$background | $foreground | Foreground based on background |
| $icon-color | Icon color based on background | |
| $hover-background | Hover background color | |
| $hover-foreground | Foreground on hover | |
| $icon-color-hover | Icon color on hover | |
| $active-background | Active background color | |
| $active-foreground | Active foreground color | |
| $focus-background | Focus background color | |
| $focus-foreground | Foreground on focus | |
| $focus-hover-background | Focus + hover background | |
| $focus-hover-foreground | Foreground on focus + hover | |
| $focus-visible-background | Background when focus is visible | |
| $focus-visible-foreground | Foreground when focus is visible | |
| $focus-visible-border-color | Border color when focus is visible |
Bootstrap Theme
Flat Button
| Primary Property | Dependent Property | Description |
|---|---|---|
$foreground |
$hover-foreground | Foreground color for hovered button |
| $icon-color-hover | Icon color for hovered button | |
| $focus-foreground | Foreground color for focused button | |
| $focus-hover-foreground | Foreground color for button on focus + hover | |
| $active-foreground | Foreground color for active button | |
| $focus-visible-foreground | Foreground when focus is visible | |
| $focus-visible-border-color | Border color when focus is visible | |
| $disabled-foreground | Foreground color for disabled button | |
| $disabled-icon-color | Icon color for disabled button | |
| $shadow-color | Shadow color |
Contained Button
| Primary Property | Dependent Property | Description |
|---|---|---|
$background |
$foreground | Foreground based on background |
| $icon-color | Icon color based on background | |
| $hover-background | Hover background color | |
| $focus-background | Focus background color | |
| $active-background | Active background color | |
| $hover-foreground | Foreground on hover | |
| $icon-color-hover | Icon color on hover | |
| $focus-foreground | Foreground on focus | |
| $focus-hover-background | Focus + hover background | |
| $focus-hover-foreground | Foreground on focus + hover | |
| $focus-visible-background | Background when focus is visible | |
| $focus-visible-foreground | Foreground when focus is visible | |
| $active-foreground | Active foreground color | |
| $shadow-color | Shadow color | |
| $disabled-background | Disabled background color | |
| $disabled-foreground | Disabled foreground color | |
| $disabled-icon-color | Disabled icon color |
Outlined Button
| Primary Property | Dependent Property | Description |
|---|---|---|
$foreground |
$hover-background | Background color for hovered button |
| $focus-background | Background color for focused button | |
| $focus-hover-background | Background color for button on focus + hover | |
| $active-background | Background color for active button | |
| $hover-foreground | Foreground color for hovered button | |
| $icon-color-hover | Icon color for hovered button | |
| $focus-foreground | Foreground color for focused button | |
| $focus-hover-foreground | Foreground color for button on focus + hover | |
| $active-foreground | Foreground color for active button | |
| $focus-visible-background | Background when focus is visible | |
| $focus-visible-foreground | Foreground when focus is visible | |
| $focus-visible-border-color | Border color when focus is visible | |
| $disabled-foreground | Foreground color for disabled button | |
| $disabled-icon-color | Icon color for disabled button | |
| $disabled-border-color | Border color for disabled button | |
| $hover-border-color | Hover border color | |
| $focus-border-color | Focus border color | |
| $focus-visible-border-color | Focus-visible border color | |
| $active-border-color | Active border color | |
| $shadow-color | Shadow color |
FAB Button
| Primary Property | Dependent Property | Description |
|---|---|---|
$background |
$foreground | Foreground based on background |
| $icon-color | Icon color based on background | |
| $hover-background | Hover background color | |
| $focus-background | Focus background color | |
| $active-background | Active background color | |
| $disabled-background | Disabled background color | |
| $hover-foreground | Foreground on hover | |
| $icon-color-hover | Icon color on hover | |
| $focus-foreground | Foreground on focus | |
| $focus-hover-background | Focus + hover background | |
| $focus-hover-foreground | Foreground on focus + hover | |
| $focus-visible-background | Background when focus is visible | |
| $focus-visible-foreground | Foreground when focus is visible | |
| $active-foreground | Active foreground color | |
| $shadow-color | Shadow color | |
| $disabled-foreground | Disabled foreground color | |
| $disabled-icon-color | Disabled icon color |
Each of them will target only the buttons of that specific type.
Indigo Theme
Flat Button
| Primary Property | Dependent Property | Description |
|---|---|---|
$foreground | $hover-background | Background color for hovered button |
| $focus-background | Background color for focused button | |
| $focus-hover-background | Background color for button on focus + hover | |
| $active-background | Background color for active button | |
| $hover-foreground | Foreground color for hovered button | |
| $icon-color-hover | Icon color for hovered button | |
| $focus-foreground | Foreground color for focused button | |
| $focus-hover-foreground | Foreground color for button on focus + hover | |
| $active-foreground | Foreground color for active button | |
| $focus-visible-foreground | Foreground when focus is visible | |
| $disabled-foreground | Disabled foreground color | |
| $disabled-icon-color | Disabled icon color | |
| $shadow-color | Shadow color |
Contained Button
| Primary Property | Dependent Property | Description |
|---|---|---|
$background |
$foreground | Foreground based on background |
| $icon-color | Icon color based on background | |
| $hover-background | Hover background color | |
| $focus-background | Focus background color | |
| $active-background | Active background color | |
| $hover-foreground | Foreground on hover | |
| $icon-color-hover | Icon color on hover | |
| $focus-foreground | Foreground on focus | |
| $focus-hover-background | Focus + hover background | |
| $focus-hover-foreground | Foreground on focus + hover | |
| $focus-visible-background | Background when focus is visible | |
| $focus-visible-foreground | Foreground when focus is visible | |
| $active-foreground | Active foreground color | |
| $shadow-color | Shadow color | |
| $disabled-background | Disabled background color | |
| $disabled-foreground | Disabled foreground color | |
| $disabled-icon-color | Disabled icon color |
Outlined Button
| Primary Property | Dependent Property | Description |
|---|---|---|
$foreground |
$hover-background | Background color for hovered button |
| $focus-background | Background color for focused button | |
| $focus-hover-background | Background color for button on focus + hover | |
| $active-background | Background color for active button | |
| $hover-foreground | Foreground color for hovered button | |
| $icon-color-hover | Icon color for hovered button | |
| $focus-foreground | Foreground color for focused button | |
| $focus-hover-foreground | Foreground color for button on focus + hover | |
| $active-foreground | Foreground color for active button | |
| $focus-visible-background | Background when focus is visible | |
| $focus-visible-foreground | Foreground when focus is visible | |
| $focus-visible-border-color | Border color when focus is visible | |
| $border-color | Border color | |
| $hover-border-color | Hover border color | |
| $focus-border-color | Focus border color | |
| $focus-visible-border-color | Focus-visible border color | |
| $active-border-color | Active border color | |
| $shadow-color | Shadow color |
FAB Button
| Primary Property | Dependent Property | Description |
|---|---|---|
$background |
$foreground | Foreground based on background |
| $icon-color | Icon color based on background | |
| $hover-background | Hover background color | |
| $focus-background | Focus background color | |
| $active-background | Active background color | |
| $disabled-background | Disabled background color | |
| $hover-foreground | Foreground on hover | |
| $icon-color-hover | Icon color on hover | |
| $focus-foreground | Foreground on focus | |
| $focus-hover-background | Focus + hover background | |
| $focus-hover-foreground | Foreground on focus + hover | |
| $focus-visible-background | Background when focus is visible | |
| $focus-visible-foreground | Foreground when focus is visible | |
| $active-foreground | Active foreground color | |
| $shadow-color | Shadow color | |
| $disabled-foreground | Disabled foreground color | |
| $disabled-icon-color | Disabled 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 with styling the button, 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 css-vars($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.
Note
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-buttondark-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>
Note
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 --igx-button-size variable to target all instances:
<div class="my-app">
<button igxButton="raised"></button>
</div>
.my-app {
--igx-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
- IgxButtonDirective
- IgxButton Styles
- IgxRippleDirective
- IgxIconButtonDirective
- IgxButtonGroupComponent
Additional Resources
Our community is active and always welcoming to new ideas.