On/off toggle built on a native checkbox with role switch, no JavaScript needed in Blade.
<x-markas.switch label="Airplane mode" /><x-markas.switch label="Airplane mode" disabled />import { Switch } from "@/components/markas/Switch";
<Switch label="Airplane mode" />import { Switch } from "@/components/markas/Switch";
<Switch label="Airplane mode" disabled />import Switch from "@/components/markas/Switch.vue";
<Switch label="Airplane mode" />import Switch from "@/components/markas/Switch.vue";
<Switch label="Airplane mode" disabled /><script lang="ts">
import Switch from "$lib/components/markas/Switch.svelte";
</script>
<div class="grid gap-4">
<Switch name="notifications" label="Email notifications" checked />
<Switch name="saver" label="Data saver mode" />
<Switch name="beta" label="Beta features" disabled />
</div>---
import Switch from "@/components/markas/Switch.astro";
---
<div class="grid gap-4">
<Switch name="notifications" label="Email notifications" checked />
<Switch name="saver" label="Data saver mode" />
<Switch name="beta" label="Beta features" disabled />
</div>Examples
States
<div class="grid gap-4">
<x-markas.switch name="wifi" label="Wi-Fi" checked />
<x-markas.switch name="bluetooth" label="Bluetooth" />
<x-markas.switch name="location" label="Location services" disabled />
<x-markas.switch name="find_device" label="Find my device" checked disabled />
</div><script lang="ts">
import Switch from "$lib/components/markas/Switch.svelte";
</script>
<div class="grid gap-4">
<Switch name="wifi" label="Wi-Fi" checked />
<Switch name="bluetooth" label="Bluetooth" />
<Switch name="location" label="Location services" disabled />
<Switch name="find_device" label="Find my device" checked disabled />
</div>---
import Switch from "@/components/markas/Switch.astro";
---
<div class="grid gap-4">
<Switch name="wifi" label="Wi-Fi" checked />
<Switch name="bluetooth" label="Bluetooth" />
<Switch name="location" label="Location services" disabled />
<Switch name="find_device" label="Find my device" checked disabled />
</div>Settings list
Push notifications
Alerts on your phone for new messages.
Weekly digest
A summary of activity every Monday.
Product news
Occasional emails about new features.
Push notifications
Alerts on your phone for new messages.
Weekly digest
A summary of activity every Monday.
Product news
Occasional emails about new features.
Push notifications
Alerts on your phone for new messages.
Weekly digest
A summary of activity every Monday.
Product news
Occasional emails about new features.
Push notifications
Alerts on your phone for new messages.
Weekly digest
A summary of activity every Monday.
Product news
Occasional emails about new features.
Push notifications
Alerts on your phone for new messages.
Weekly digest
A summary of activity every Monday.
Product news
Occasional emails about new features.
Feature card
Two-factor authentication
Ask for a code from your authenticator app each time you sign in.
Two-factor authentication
Ask for a code from your authenticator app each time you sign in.
Two-factor authentication
Ask for a code from your authenticator app each time you sign in.
Two-factor authentication
Ask for a code from your authenticator app each time you sign in.
Two-factor authentication
Ask for a code from your authenticator app each time you sign in.
<div class="flex items-start gap-4 rounded-lg border border-line bg-surface p-4 transition-colors duration-150 ease-out has-checked:border-primary motion-reduce:transition-none">
<span class="flex size-10 shrink-0 items-center justify-center rounded-md bg-primary-soft text-primary">
<svg class="size-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3 5 6v5c0 4.5 3 8.5 7 10 4-1.5 7-5.5 7-10V6l-7-3z" /><path d="m9 12 2 2 4-4" /></svg>
</span>
<div class="grid flex-1 gap-0.5">
<p class="text-sm font-medium text-ink">Two-factor authentication</p>
<p class="text-sm text-muted">Ask for a code from your authenticator app each time you sign in.</p>
</div>
<x-markas.switch name="two_factor" aria-label="Two-factor authentication" checked />
</div>Horizontal
<div class="flex flex-wrap gap-x-6 gap-y-3">
<x-markas.switch name="autoplay" label="Autoplay" checked />
<x-markas.switch name="captions" label="Captions" />
<x-markas.switch name="loop" label="Loop" />
</div>import { Switch } from "@/components/markas/Switch";
export default function Example() {
return (
<div className="flex flex-wrap gap-x-6 gap-y-3">
<Switch name="autoplay" label="Autoplay" defaultChecked />
<Switch name="captions" label="Captions" />
<Switch name="loop" label="Loop" />
</div>
);
}<script lang="ts">
import Switch from "$lib/components/markas/Switch.svelte";
</script>
<div class="flex flex-wrap gap-x-6 gap-y-3">
<Switch name="autoplay" label="Autoplay" checked />
<Switch name="captions" label="Captions" />
<Switch name="loop" label="Loop" />
</div>---
import Switch from "@/components/markas/Switch.astro";
---
<div class="flex flex-wrap gap-x-6 gap-y-3">
<Switch name="autoplay" label="Autoplay" checked />
<Switch name="captions" label="Captions" />
<Switch name="loop" label="Loop" />
</div>Installation
npx markasui@latest add switchpnpm dlx markasui@latest add switchyarn dlx markasui@latest add switchbunx --bun markasui@latest add switch- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
resources/views/components/markas/switch.blade.php.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/Switch.tsx.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/Switch.vue.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/lib/components/markas/Switch.svelte.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/Switch.astro.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/app/markas/switch.component.ts.
Usage
<x-markas.switch name="notifications" label="Email notifications" :checked="$user->wants_email" />No Alpine.js needed.
import { Switch } from "@/components/markas/Switch";
<Switch
name="notifications"
label="Email notifications"
defaultChecked
onCheckedChange={(checked) => console.log(checked)}
/>;<script setup lang="ts">
import { ref } from "vue";
import Switch from "@/components/markas/Switch.vue";
const notifications = ref(true);
</script>
<template>
<Switch
v-model="notifications"
name="notifications"
label="Email notifications"
/>
</template><script lang="ts">
import Switch from "$lib/components/markas/Switch.svelte";
let notifications = $state(true);
</script>
<Switch
bind:checked={notifications}
name="notifications"
label="Email notifications"
/>---
import Switch from "@/components/markas/Switch.astro";
---
<Switch name="notifications" label="Email notifications" checked />No client script: the switch is a native checkbox.
import { Component, signal } from "@angular/core";
import { Switch } from "./markas/switch.component";
@Component({
selector: "app-settings",
imports: [Switch],
template: `
<markas-switch
[(checked)]="notifications"
name="notifications"
label="Email notifications"
/>
`,
})
export class Settings {
readonly notifications = signal(true);
}- Switch is an
<input type="checkbox" role="switch">, so its value is submitted with the form like a regular checkbox. - The on state is announced from the native
checked, so noaria-checkedis needed. The look useschecked:andpeer-checked:, notdata-state. - The component has no built-in text. Translate
labeldirectly.
Props
| Name | Type | Default | Description |
|---|---|---|---|
label | string | - | Label text next to the switch, linked through for/id. |
checked / defaultChecked / v-model / bind:checked | boolean | false | On state. Blade and Astro use the checked attribute, React checked or defaultChecked, Vue v-model, Svelte bind:checked, Angular checked or [(checked)]. |
onCheckedChange | (checked: boolean) => void | - | React only. Called with the new state every time the switch changes. |
checkedChange | output<boolean> | - | Angular only. Emits the new state every time the switch changes. |
disabled | boolean | false | Disables the switch and dims the label. |
id | string | auto | Input id. Generated when empty. |
Accessibility
- A native checkbox input with role switch, so screen readers announce on or off from the checked state.
- Space toggles the state, and clicking the label toggles it too.
- The thumb is decorative (aria-hidden) and moves through CSS peer-checked.
Related components
More form components with the same classes in every framework.
- ButtonButton with primary, secondary, ghost, and danger variants.
- CheckboxNative checkbox with an optional label and description, custom styled without JavaScript.
- ComboboxText input with a filtered suggestion list in a popover, following the WAI-ARIA Combobox pattern with list autocomplete.
- InputText field with a label, hint, and error message wired up through ARIA.
- Input OTPOne-time code input split into single-digit boxes, with auto advance, paste support, and one hidden field for form submit.
- LabelForm label with consistent styling and optional required or optional markers that screen readers announce correctly.