Switch

Toggles one setting on or off, and applies the change immediately.

When to use

Use a switch for a setting whose effect is immediate, such as turning notifications on. Use a checkbox when the change is applied later, for example after pressing a submit button.

A thumb icon makes the state visible without relying on color alone.

Playground

The interactive page has a playground with live property controls for this component and generated code.

Examples

Basic

var checked by rememberSaveable { mutableStateOf(false) }

Row(
    modifier = Modifier.toggleable(value = checked, onValueChange = { checked = it }, role = Role.Switch),
    verticalAlignment = Alignment.CenterVertically,
    horizontalArrangement = Arrangement.spacedBy(16.dp),
) {
    Text("Notifications")
    Switch(checked = checked, onCheckedChange = null)
}

Parameters

NameTypeDefaultDescription
checkedBooleanWhether the switch is on.
onCheckedChange((Boolean) -> Unit)?Pass null when a parent toggleable handles the change.
thumbContent@Composable (() -> Unit)?nullIcon inside the thumb.
colorsSwitchColorsSwitchDefaults.colors()Track, thumb and border colors.

Guidelines

Do:

Don't:

Accessibility

Related components