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

Skip to main content

Directory

Switch Component

The Switch component creates an interactive on/off control perfect for settings, preferences, and feature toggles. It’s accessible, customizable, and easy to implement in your AstroJS project.

  • Check Circle

    Multiple Variants: Support for default, success, and destructive states

  • Check Circle

    Size Options: Three size variants for different contexts

  • Check Circle

    Accessibility: Full ARIA support and keyboard navigation

Add a simple switch by importing and using the component:

Notifications
<Switch
label="Notifications"
checked={true}
/>

The switch comes in three sizes to match your design needs:

Compact Switch Standard Switch Large Switch
<Switch size="sm" label="Compact Switch" />
<Switch label="Standard Switch" />
<Switch size="lg" label="Large Switch" />

The switch supports different color variants to indicate various states or actions:

Default Switch Success Switch Destructive Switch
<Switch variant="default" label="Default Switch" />
<Switch variant="success" label="Success Switch" />
<Switch variant="destructive" label="Destructive Switch" />
Switch Component Props Extends <button> HTMLElement
Prop Type Default Description
label string - Main label for the switch
sublabel string - Additional descriptive text
variant "default" | "success" | "destructive" default Color variant
size "sm" | "default" | "lg" default Size of the switch
checked boolean false Initial switch state

Listen for switch state changes:

Notifications
Waiting for events to be emitted… (Click on the switch to see the events)
document.querySelector('switch-wrapper').addEventListener(SwitchEventNames.Change, (event) => {
const isChecked = event.detail.checked;
// Handle state change
});

Limited Time Launch Sale

Get started with our AstroJS starter template and access a complete collection of pre-built components, including this Switch. Save development time and build better websites faster.

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