Icon button

A compact button that shows one icon. Four types, five sizes and three widths.

When to use

Use an icon button for familiar actions where the icon alone is clear, such as favorite, share or close.

Choose the size with the matching container size from IconButtonDefaults. The width option changes the container without changing the icon, which helps in dense toolbars.

Playground

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

Examples

Types

IconButton(onClick = {}) { Icon(Icons.Rounded.Favorite, contentDescription = "Favorite") }
FilledIconButton(onClick = {}) { Icon(Icons.Rounded.Favorite, contentDescription = "Favorite") }
FilledTonalIconButton(onClick = {}) { Icon(Icons.Rounded.Favorite, contentDescription = "Favorite") }
OutlinedIconButton(onClick = {}) { Icon(Icons.Rounded.Favorite, contentDescription = "Favorite") }

Toggle

The shape morphs between unselected and selected.

var liked by rememberSaveable { mutableStateOf(false) }

FilledIconToggleButton(
    checked = liked,
    onCheckedChange = { liked = it },
    shapes = IconButtonDefaults.toggleableShapes(),
) {
    Icon(
        imageVector = if (liked) Icons.Rounded.Favorite else Icons.Rounded.FavoriteBorder,
        contentDescription = if (liked) "Remove from favorites" else "Add to favorites",
    )
}

Parameters

NameTypeDefaultDescription
onClick() -> UnitCalled when the button is clicked.
shapesIconButtonShapesIconButtonDefaults.shapes()Resting and pressed shape.
modifierModifierModifierApply Modifier.size(containerSize) to choose a size and width.
colorsIconButtonColorsiconButtonColors()Container and content colors.
content@Composable () -> UnitUsually a single Icon.

Guidelines

Do:

Don't:

Accessibility

Related components