Checkbox

Previous Next

A control that allows the user to toggle between checked and not checked.

By clicking this checkbox, you agree to the terms and conditions.

<div class="flex flex-col gap-6">
    <div class="flex items-center gap-3">
        <Checkbox Id="terms" />
        <Label For="terms">Accept terms and conditions</Label>
    </div>
    <div class="flex items-start gap-3">
        <Checkbox Id="terms-2" DefaultChecked="true" />
        <div class="grid gap-2">
            <Label For="terms-2">Accept terms and conditions</Label>
            <p class="text-muted-foreground text-sm">By clicking this checkbox, you agree to the terms and conditions.</p>
        </div>
    </div>
    <div class="flex items-start gap-3">
        <Checkbox Id="toggle" Disabled="true" />
        <Label For="toggle">Enable notifications</Label>
    </div>
</div>

Installation

Install the checkbox component using the command or manual steps.

blazor-shadcn add checkbox

Usage

@using BlazorShadcn.Components.UI
<Checkbox />

Checked State

<Checkbox Id="checked-a" DefaultChecked="true" />

Invalid State

<div class="flex items-center gap-3 text-destructive" data-invalid="true">
    <Checkbox Id="invalid-a" aria-invalid="true" />
    <Label For="invalid-a">Accept terms and conditions</Label>
</div>

Examples

Basic

<div class="flex items-center gap-3">
    <Checkbox Id="basic-a" />
    <Label For="basic-a">Accept terms and conditions</Label>
</div>

Description

By clicking this checkbox, you agree to the terms and conditions.

<div class="flex items-start gap-3">
    <Checkbox Id="desc-a" DefaultChecked="true" />
    <div class="grid gap-2">
        <Label For="desc-a">Accept terms and conditions</Label>
        <p class="text-muted-foreground text-sm">By clicking this checkbox, you agree to the terms and conditions.</p>
    </div>
</div>

Disabled

<div class="flex items-center gap-3" data-disabled="true">
    <Checkbox Id="disabled-a" Disabled="true" />
    <Label For="disabled-a">Accept terms and conditions</Label>
</div>

Group

Show these items on the desktop:

<div class="grid gap-3">
    <p class="text-sm font-medium">Show these items on the desktop:</p>
    <div class="flex items-center gap-3">
        <Checkbox Id="group-hard" DefaultChecked="true" />
        <Label For="group-hard" Class="font-normal">Hard disks</Label>
    </div>
    <div class="flex items-center gap-3">
        <Checkbox Id="group-external" DefaultChecked="true" />
        <Label For="group-external" Class="font-normal">External disks</Label>
    </div>
    <div class="flex items-center gap-3">
        <Checkbox Id="group-cds" />
        <Label For="group-cds" Class="font-normal">CDs, DVDs, and iPods</Label>
    </div>
    <div class="flex items-center gap-3">
        <Checkbox Id="group-servers" />
        <Label For="group-servers" Class="font-normal">Connected servers</Label>
    </div>
</div>

TableComing soon

Coming Soon

API Reference

Checkbox

PropTypeDefault
Checkedbool?null
DefaultCheckedboolfalse
CheckedChangedEventCallback<bool>-
Disabledboolfalse
Idstring?null