Blazor Buttons

Use Blazor Bootstrap button styles for actions in forms, dialogs, and more with support for multiple sizes, states, and more.

Examples#

Bootstrap includes several predefined button styles, each serving its own semantic purpose, with a few extras thrown in for more control.
razor
<Button Color="ButtonColor.Primary"> Primary </Button>
<Button Color="ButtonColor.Secondary"> Secondary </Button>
<Button Color="ButtonColor.Success"> Success </Button>
<Button Color="ButtonColor.Danger"> Danger </Button>
<Button Color="ButtonColor.Warning"> Warning </Button>
<Button Color="ButtonColor.Info"> Info </Button>
<Button Color="ButtonColor.Light"> Light </Button>
<Button Color="ButtonColor.Dark"> Dark </Button>
<Button Color="ButtonColor.Link"> Link </Button>

Button tags#

Link
razor
<Button Type="ButtonType.Link" Color="ButtonColor.Primary" To="#"> Link </Button>
<Button Type="ButtonType.Submit" Color="ButtonColor.Primary" To="#"> Button </Button>

Outline buttons#

razor
<Button Color="ButtonColor.Primary" Outline="true"> Primary </Button>
<Button Color="ButtonColor.Secondary" Outline="true"> Secondary </Button>
<Button Color="ButtonColor.Success" Outline="true"> Success </Button>
<Button Color="ButtonColor.Danger" Outline="true"> Danger </Button>
<Button Color="ButtonColor.Warning" Outline="true"> Warning </Button>
<Button Color="ButtonColor.Info" Outline="true"> Info </Button>
<Button Color="ButtonColor.Dark" Outline="true"> Dark </Button>
INFO
Some of the button styles use a relatively light foreground color, and should only be used on a dark background in order to have sufficient contrast.

Sizes#

Fancy larger or smaller buttons? Add Size="Size.Large" or Size="Size.Small" for additional sizes.
razor
<Button Color="ButtonColor.Primary" Size="Size.Large"> Large button </Button>
<Button Color="ButtonColor.Secondary" Size="Size.Large"> Large button </Button>
razor
<Button Color="ButtonColor.Primary" Size="Size.Small"> Small button </Button>
<Button Color="ButtonColor.Secondary" Size="Size.Small"> Small button </Button>
razor
<Button Color="ButtonColor.Primary" Size="Size.ExtraLarge"> Extra large button </Button>
<Button Color="ButtonColor.Secondary" Size="Size.Large"> Large button </Button>
<Button Color="ButtonColor.Success" Size="Size.Medium"> Medium button </Button>
<Button Color="ButtonColor.Danger" Size="Size.Small"> Small button </Button>
<Button Color="ButtonColor.Warning" Size="Size.ExtraSmall"> Extra small button </Button>

Disabled state#

Make buttons look inactive by adding the Disabled="true" boolean parameter to any Button component. Disabled buttons have pointer-events: none applied to, preventing hover and active states from triggering.
INFO
Disabled buttons using the Type="ButtonType.Link" parameter behave a bit different.
razor
<Button Color="ButtonColor.Primary" Size="Size.Large" Disabled="true"> Large button </Button>
<Button Color="ButtonColor.Secondary" Size="Size.Large" Disabled="true"> Large button </Button>
razor
<Button Type="ButtonType.Link" Color="ButtonColor.Primary" Size="Size.Large" Disabled="true"> Primary link </Button>
<Button Type="ButtonType.Link" Color="ButtonColor.Secondary" Size="Size.Large" Disabled="true"> Link </Button>

Disable and enable state dynamically#

Link Button
razor
<Button Type="ButtonType.Link" Color="ButtonColor.Primary" Disabled="@disableButton" TooltipTitle="@tooltip">Link Button</Button>
<Button Type="ButtonType.Submit" Color="ButtonColor.Primary" Disabled="@disableButton" TooltipTitle="@tooltip">Submit Button</Button>
<Button Type="ButtonType.Button" Color="ButtonColor.Primary" Disabled="@disableButton" TooltipTitle="@tooltip">Button</Button>
<Button Type="ButtonType.Reset" Color="ButtonColor.Primary" Disabled="@disableButton" TooltipTitle="@tooltip">Reset Button</Button>

<Button Color="ButtonColor.Danger" @onclick="() => SwapDisable()">Swap Disable</Button>

@code
{
    bool disableButton = true;
    string tooltip = "";

    public void SwapDisable()
    {
        disableButton = !disableButton;
        tooltip = $"Updated at {DateTime.Now}";
    }
}

Block buttons#

razor
<div class="d-grid gap-2">
    <Button Color="ButtonColor.Primary"> Button </Button>
    <Button Color="ButtonColor.Primary"> Button </Button>
</div>
razor
<div class="d-grid gap-2 d-md-block mt-2">
    <Button Color="ButtonColor.Primary"> Button </Button>
    <Button Color="ButtonColor.Primary"> Button </Button>
</div>
razor
<div class="d-grid gap-2 col-6 mx-auto mt-2">
    <Button Color="ButtonColor.Primary"> Button </Button>
    <Button Color="ButtonColor.Primary"> Button </Button>
</div>
razor
<div class="d-grid gap-2 d-md-flex justify-content-md-end mt-2">
    <Button Color="ButtonColor.Primary"> Button </Button>
    <Button Color="ButtonColor.Primary"> Button </Button>
</div>

Toggle states#

razor
<Button Color="ButtonColor.Primary"> Toggle button </Button>
<Button Color="ButtonColor.Primary" Active="true"> Active toggle button </Button>
<Button Color="ButtonColor.Primary" Disabled="true"> Disabled toggle button </Button>
razor
<Button Type="ButtonType.Link" Color="ButtonColor.Primary" To="#"> Toggle button </Button>
<Button Type="ButtonType.Link" Color="ButtonColor.Primary" To="#" Active="true"> Active toggle button </Button>
<Button Type="ButtonType.Link" Color="ButtonColor.Primary" To="#" Disabled="true"> Disabled toggle button </Button>

Loading spinner#

Use spinners within buttons to indicate an action is currently processing or taking place. You may also swap the text out of the spinner element and utilize button text as needed.
razor
<Button Color="ButtonColor.Primary" Loading="true" />
<Button Color="ButtonColor.Primary" Loading="true" LoadingText="Saving..." />
<Button Color="ButtonColor.Primary" Loading="true">
    <LoadingTemplate>
        <span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
        Loading...
    </LoadingTemplate>
</Button>

Show/Hide loading spinner#

Show Tooltip#

Hover over the buttons below to see the four tooltips directions: top, right, bottom, and left.
razor
<Button Color="ButtonColor.Primary" TooltipTitle="Tooltip text" TooltipPlacement="TooltipPlacement.Top"> Tooltip Top </Button>

<Button Color="ButtonColor.Primary" TooltipTitle="Tooltip text" TooltipPlacement="TooltipPlacement.Right"> Tooltip Right </Button>

<Button Color="ButtonColor.Primary" TooltipTitle="Tooltip text" TooltipPlacement="TooltipPlacement.Bottom"> Tooltip Bottom </Button>

<Button Color="ButtonColor.Primary" TooltipTitle="Tooltip text" TooltipPlacement="TooltipPlacement.Left"> Tooltip Left </Button>

Dynamically update the tooltip text#

razor
<div class="mb-3">
    <Button Color="ButtonColor.Primary" TooltipTitle="@text" TooltipPlacement="TooltipPlacement.Top"> Tooltip Top </Button>
</div>

<Button Type="ButtonType.Button" Color="ButtonColor.Primary" @onclick="ChangeTooltip">Change Tooltip</Button>

@code {
    private string text = "Tooltip text";

    private void ChangeTooltip() => text = $"Updated {DateTime.Now.ToLongTimeString()}";
}

Custom tooltips#

Blazor Bootstrap includes several predefined tooltip styles, each serving its own semantic purpose. The TooltipColor parameter can be used to customize the color of the tooltip.
razor
<Button Color="ButtonColor.Light" TooltipTitle="This top tooltip is themed via TooltipColor parameter." TooltipPlacement="TooltipPlacement.Top" TooltipColor="TooltipColor.None"> Default Tooltip </Button>
<Button Color="ButtonColor.Light" TooltipTitle="This top tooltip is themed via TooltipColor parameter." TooltipPlacement="TooltipPlacement.Top" TooltipColor="TooltipColor.Primary"> Primary Tooltip  </Button>
<Button Color="ButtonColor.Light" TooltipTitle="This top tooltip is themed via TooltipColor parameter." TooltipPlacement="TooltipPlacement.Top" TooltipColor="TooltipColor.Secondary"> Secondary Tooltip </Button>
<Button Color="ButtonColor.Light" TooltipTitle="This top tooltip is themed via TooltipColor parameter." TooltipPlacement="TooltipPlacement.Top" TooltipColor="TooltipColor.Success"> Success Tooltip </Button>
<Button Color="ButtonColor.Light" TooltipTitle="This top tooltip is themed via TooltipColor parameter." TooltipPlacement="TooltipPlacement.Top" TooltipColor="TooltipColor.Danger"> Danger Tooltip </Button>
<Button Color="ButtonColor.Light" TooltipTitle="This top tooltip is themed via TooltipColor parameter." TooltipPlacement="TooltipPlacement.Top" TooltipColor="TooltipColor.Warning">Warning Tooltip </Button>
<Button Color="ButtonColor.Light" TooltipTitle="This top tooltip is themed via TooltipColor parameter." TooltipPlacement="TooltipPlacement.Top" TooltipColor="TooltipColor.Info"> Info Tooltip </Button>
<Button Color="ButtonColor.Light" TooltipTitle="This top tooltip is themed via TooltipColor parameter." TooltipPlacement="TooltipPlacement.Top" TooltipColor="TooltipColor.Light"> Light Tooltip </Button>
<Button Color="ButtonColor.Light" TooltipTitle="This top tooltip is themed via TooltipColor parameter." TooltipPlacement="TooltipPlacement.Top" TooltipColor="TooltipColor.Dark"> Dark Tooltip </Button>
NOTE
Support for HTML tooltips is not available at this moment.

Click events#

razor
<Button Color="ButtonColor.Primary" @onclick="OnClick"> Click here </Button>

@code {
    protected void OnClick(EventArgs args)
    {
        Console.WriteLine("click event");
    }
}
razor
<Button Color="ButtonColor.Primary" @ondblclick="OnDoubleClick"> Double click here </Button>

@code {
    protected void OnDoubleClick(EventArgs args)
    {
        Console.WriteLine("double click event");
    }
}
razor
<Button Color="ButtonColor.Primary" @onclick="((args) => OnClickWithArgs(args, message))"> Click event with args </Button>

@code {
    public string message = "Test message";

    protected void OnClickWithArgs(EventArgs args, string message)
    {
        Console.WriteLine($"message: {message}");
    }
}