Skip to content
daisyBlazor

Switch

A toggle switch bound to a bool, with the same API as Checkbox. Reach for it when the change takes effect immediately, like a setting.
Data input.toggleReplaces MudSwitch
Cover · <Switch>
Notifications
Auto-deploy
Backups

Examples

Binding

@bind-Value is a plain bool.

email=True · digest=False

website/Examples/DataInput/SwitchBasicExample.razor Source

Colors

Color maps to daisyUI's toggle-* colours.

website/Examples/DataInput/SwitchColorsExample.razor Source

Sizes and states

Small, Medium and Large, plus Disabled and ReadOnly.

website/Examples/DataInput/SwitchSizesExample.razor Source

Rich label

ChildContent replaces Label when the text needs markup.

website/Examples/DataInput/SwitchContentExample.razor Source

Playground

Color Color
Size Size
<Switch
        Label="Email notifications"
        Value="true"
        Color="Color.Primary" />

API

<Switch>

DaisyBlazor

Parameters

  • Checked bool
    = false

    MudBlazor-style alias for Value; used when CheckedChanged is wired or set to true.

  • Color Color
    = Color.Default

    Theme color mapped to toggle-primary, toggle-accent, etc.; Default adds no color class.

  • Disabled bool
    = false

    Disables the input and ignores change events.

  • Label string
    = null

    Text rendered in a .label-text span next to the input.

  • ReadOnly bool
    = false

    Cancels clicks and ignores change events, so the toggle stays put and the state cannot be changed by the user.

  • Size Size
    = Size.Medium

    Input size: Small adds toggle-sm, Large adds toggle-lg; Medium uses the daisyUI default.

  • Value bool
    = false

    Whether the toggle is checked; two-way bindable with @bind-Value.

  • Class string
    = null

    Extra CSS classes merged onto the wrapping <label> element.

  • Style string
    = null

    Inline CSS style applied to the wrapping <label> element.

Events

  • CheckedChanged EventCallback<bool>

    MudBlazor-style alias for ValueChanged; wiring it makes Checked the source of truth.

  • ValueChanged EventCallback<bool>

    Raised with the new state when the user toggles the toggle.

Content

  • ChildContent RenderFragment

    Additional content rendered inside the label after the input and Label.

From MudSwitch

Switch keeps MudSwitch's parameter names, so most markup moves over by dropping the Mud prefix. See the migration guide for the shared enums, icons and services.

<MudSwitch> <Switch>
Something went wrong while running the docs. Reload