androidx.compose.material3

Checkbox

Composable function

A checkbox turns an item on or off. Use checkboxes when the user can pick several items from a list. For a single setting that takes effect right away, use a Switch.

The checkbox does not remember its state. You keep it in a variable and update it in onCheckedChange.

A checkbox that remembers its state
A checkbox that remembers its state
var checked by remember { mutableStateOf(true) }
Checkbox(checked = checked, onCheckedChange = { checked = it })
Checked, unchecked and disabled
Checked, unchecked and disabled
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
    Checkbox(checked = true, onCheckedChange = {})
    Checkbox(checked = false, onCheckedChange = {})
    Checkbox(checked = true, onCheckedChange = {}, enabled = false)
    Checkbox(checked = false, onCheckedChange = {}, enabled = false)
}

Basic

Uses the default line widths.

@Composable
fun Checkbox(
    checked: Boolean,
    onCheckedChange: ((Boolean) -> Unit)?,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    colors: CheckboxColors = CheckboxDefaults.colors(),
    interactionSource: MutableInteractionSource? = null,
)

checked: BooleanRequired

Whether the box is checked. Pass your state here.

onCheckedChange: ((Boolean) -> Unit)?Required

Called with the new value when the user clicks. Update your state here. Pass null if a whole row handles the click. This makes the label clickable too.

With a clickable label
With a clickable label
var agree by remember { mutableStateOf(false) }
Row(
    modifier = Modifier.toggleable(value = agree, onValueChange = { agree = it }, role = Role.Checkbox),
    verticalAlignment = Alignment.CenterVertically,
) {
    // The Row handles clicks, so the checkbox itself does not.
    Checkbox(checked = agree, onCheckedChange = null)
    Text("I agree to the terms", Modifier.padding(start = 8.dp))
}

modifier: ModifierOptional

Default: Modifier

Changes size, padding, or position of the checkbox. See the Modifier guide.

enabled: BooleanOptional

Default: true

Set to false to make the checkbox gray and not clickable.

colors: CheckboxColorsOptional

Default: CheckboxDefaults.colors()

Sets the box, checkmark and border colors for every state. Make one with CheckboxDefaults.colors. Pass only the colors you want to change.

Tertiary color when checked
Tertiary color when checked
Checkbox(
    checked = true,
    onCheckedChange = {},
    colors = CheckboxDefaults.colors(checkedColor = MaterialTheme.colorScheme.tertiary),
)

interactionSource: MutableInteractionSource?Optional

Default: null

Lets you observe or control press, hover and focus states. Leave it null unless your code must react to them. See InteractionSource.

Custom strokesSince 1.9

Takes checkmarkStroke and outlineStroke to change line widths.

@Composable
fun Checkbox(
    checked: Boolean,
    onCheckedChange: ((Boolean) -> Unit)?,
    checkmarkStroke: Stroke,
    outlineStroke: Stroke,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    colors: CheckboxColors = CheckboxDefaults.colors(),
    interactionSource: MutableInteractionSource? = null,
)

checkmarkStroke: StrokeRequired

The line style of the checkmark, for example Stroke(width = 3f).

outlineStroke: StrokeRequired

The line style of the box outline.

Same as above: checked, onCheckedChange, modifier, enabled, colors, interactionSource.

Checkbox types

See also