We use cookies to ensure you get the best experience on our website. Read our privacy policy

Skip to main content

Directory

Checkbox Component

The Checkbox component creates interactive form controls that work for both checkboxes and radio buttons. It includes built-in label support, multiple styling variants, and comprehensive accessibility features.

  • Check Circle

    Dual Functionality: Works as both checkbox and radio button

  • Check Circle

    Smart Styling: Multiple variants with hover and focus states

  • Check Circle

    Label Integration: Built-in label support with required field indication

  • Check Circle

    State Management: Supports various states including error handling

Choose from three distinct styling variants:

Accept terms and conditions

Delete my account

Select this option

  • Default: Standard form controls and general usage
  • Destructive: Actions requiring caution or confirmation
  • Outline: When you need a more prominent selection area or want to emphasize the entire option

The component supports various interactive states:

Subscribe to newsletter

Agree to privacy policy

*

Receive marketing emails

Remember my preferences

Auto-save settings

Required field with error

*

Create simple checkbox inputs with labels:

<Checkbox value="terms" name="terms" required>
Accept terms and conditions
</Checkbox>
<Checkbox variant="destructive" value="delete" name="delete">
Delete account
</Checkbox>

Use the component in radio button mode:

<RadioGroup title="Choose your favorite fruit" titleClass="text-lg mb-2">
<Checkbox type="radio" name="fruit" value="apple">Apple</Checkbox>
<Checkbox type="radio" name="fruit" value="banana">Banana</Checkbox>
<Checkbox type="radio" name="fruit" value="cherry">Cherry</Checkbox>
</RadioGroup>
Choose your favorite fruit

Apple

Banana

Cherry

Checkbox Component Extends <div> HTMLElement
Prop Type Default Description
checked boolean false Checked state
disabled boolean false Disabled state
inputProps Omit<HTMLAttributes<input>, "type" | "name" | "value" | "required" | "disabled" | "checked"> Input props
labelProps HTMLAttributes<label> Label props
name string Input name
required boolean false Required field
type checkbox | radio checkbox Input type
value string Input value
variant default | destructive | outline default Visual style

The checkbox component emits a custom event that you can listen to:

Click Me

Waiting for events… (Interact with the checkbox to see events)
Change Event
const checkbox = document.querySelector('checkbox-wrapper');
checkbox?.addEventListener(CheckboxEventNames.Change, (e) => {
console.log(e.detail.checked);
});
  • Check Circle

    Automatic ID generation for label association

  • Check Circle

    Proper focus states and indicators

  • Check Circle

    Screen reader compatibility

  • Check Circle

    Keyboard navigation support

  • Check Circle

    Required field indication

  • Check Circle

    Error state handling

  • Check Circle

    ARIA attributes

  1. Label Usage

    • Use clear, concise labels
    • Indicate required fields
    • Maintain consistent terminology
    • Consider label length
  2. Grouping

    • Group related checkboxes
    • Use fieldsets for radio groups
    • Provide clear group labels
    • Maintain logical order
  3. Visual Design

    • Ensure adequate spacing
    • Maintain clear hierarchy
    • Use consistent sizing
    • Consider mobile touch targets
Form submissions
Terms acceptance
Preference selection
Feature toggles
Filter interfaces

Limited Time Launch Sale

Build user-friendly forms faster with our pre-built Checkbox component. Get the AstroJS starter template now and access a complete form controls toolkit.

GET 60% OFF!
North Star Themes Logo

Subscribe to our newsletter

Get the latest AstroJS tips and tricks right to your inbox

Email: [email protected]

© 2025 North Star Themes

Web Kit Provided By North Star Themes