📄 radixui/primitives/docs/components/switch

File: switch.md | Updated: 11/15/2025

Source: https://www.radix-ui.com/primitives/docs/components/switch

Radix Homepage

Made by WorkOS

Radix Homepage

Made by WorkOS

ThemesThemes PrimitivesPrimitives IconsIcons ColorsColors

Documentation Case studies Blog

Search

/

Overview

Introduction Getting started Accessibility Releases

Guides

Styling Animation Composition Server-side rendering

Components

Accordion Alert Dialog Aspect Ratio Avatar Checkbox Collapsible Context Menu Dialog Dropdown Menu Form

Preview
Hover Card Label Menubar Navigation Menu One-Time Password Field

Preview
Password Toggle Field

Preview
Popover Progress Radio Group Scroll Area Select Separator Slider Switch Tabs Toast Toggle Toggle Group Toolbar Tooltip

Utilities

Accessible Icon Direction Provider Portal Slot Visually Hidden

Components

Switch

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

Airplane mode

index.jsxindex.jsxstyles.cssstyles.css

CSS

import * as React from "react";
import { Switch } from "radix-ui";
import "./styles.css";

const SwitchDemo = () => (
	<form>
		<div style={{ display: "flex", alignItems: "center" }}>
			<label
				className="Label"
				htmlFor="airplane-mode"
				style={{ paddingRight: 15 }}
			>
				Airplane mode
			</label>
			<Switch.Root className="SwitchRoot" id="airplane-mode">
				<Switch.Thumb className="SwitchThumb" />
			</Switch.Root>
		</div>
	</form>
);

export default SwitchDemo;

Features

Full keyboard navigation.

Can be controlled or uncontrolled.

Installation


Install the component from your command line.

npm install @radix-ui/react-switch

Anatomy


Import all parts and piece them together.

import { Switch } from "radix-ui";

export default () => (
	<Switch.Root>
		<Switch.Thumb />
	</Switch.Root>
);

API Reference


Root

Contains all the parts of a switch. An input will also render when used within a form to ensure events propagate correctly.

| Prop | Type | Default | | --- | --- | --- | | asChild<br><br>Prop description | boolean | false | | defaultChecked<br><br>Prop description | boolean | No default value | | checked<br><br>Prop description | boolean | No default value | | onCheckedChange<br><br>Prop description | function<br><br>See full type | No default value | | disabled<br><br>Prop description | boolean | No default value | | required<br><br>Prop description | boolean | No default value | | name<br><br>Prop description | string | No default value | | value<br><br>Prop description | string | on |

| Data attribute | Values | | --- | --- | | [data-state] | "checked" \| "unchecked" | | [data-disabled] | Present when disabled |

Thumb

The thumb that is used to visually indicate whether the switch is on or off.

| Prop | Type | Default | | --- | --- | --- | | asChild<br><br>Prop description | boolean | false |

| Data attribute | Values | | --- | --- | | [data-state] | "checked" \| "unchecked" | | [data-disabled] | Present when disabled |

Accessibility


Adheres to the switch role requirements .

Keyboard Interactions

| Key | Description | | --- | --- | | Space | Toggles the component's state. | | Enter | Toggles the component's state. |

PreviousSlider

NextTabs

Edit this page on GitHub.