androidx.compose.material3

IconButton

Composable function

An icon button runs an action with just an icon. Use it in toolbars and lists, where text would take too much space.

An icon button
An icon button
IconButton(onClick = {}) {
    Icon(Icons.Filled.Settings, contentDescription = "Settings")
}

The standard IconButton has no background. The others add a filled, tonal or outlined container. See Icon button types.

Standard, filled, tonal and outlined
Standard, filled, tonal and outlined
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
    IconButton(onClick = {}) { Icon(Icons.Filled.Favorite, "Like") }
    FilledIconButton(onClick = {}) { Icon(Icons.Filled.Favorite, "Like") }
    FilledTonalIconButton(onClick = {}) { Icon(Icons.Filled.Favorite, "Like") }
    OutlinedIconButton(onClick = {}) { Icon(Icons.Filled.Favorite, "Like") }
}

Basic

Takes one shape.

@Composable
fun IconButton(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    colors: IconButtonColors = IconButtonDefaults.iconButtonColors(),
    interactionSource: MutableInteractionSource? = null,
    shape: Shape = IconButtonDefaults.standardShape,
    content: @Composable () -> Unit,
)

onClick: () -> UnitRequired

Called when the button is clicked.

modifier: ModifierOptional

Default: Modifier

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

Expressive has five sizes. Set one with Modifier.size(IconButtonDefaults.mediumContainerSize()), and the icon size with IconButtonDefaults.mediumIconSize.

Expressive sizesExpressive theme
Expressive sizes
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically) {
    FilledIconButton(onClick = {}, modifier = Modifier.size(IconButtonDefaults.smallContainerSize())) {
        Icon(Icons.Filled.Favorite, "Like", Modifier.size(IconButtonDefaults.smallIconSize))
    }
    FilledIconButton(onClick = {}, modifier = Modifier.size(IconButtonDefaults.mediumContainerSize())) {
        Icon(Icons.Filled.Favorite, "Like", Modifier.size(IconButtonDefaults.mediumIconSize))
    }
    FilledIconButton(onClick = {}, modifier = Modifier.size(IconButtonDefaults.largeContainerSize())) {
        Icon(Icons.Filled.Favorite, "Like", Modifier.size(IconButtonDefaults.largeIconSize))
    }
}

enabled: BooleanOptional

Default: true

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

Disabled
Disabled
FilledIconButton(onClick = {}, enabled = false) {
    Icon(Icons.Filled.Favorite, contentDescription = "Like")
}

colors: IconButtonColorsOptional

Default: IconButtonDefaults.iconButtonColors()

Sets the container and icon colors, for both enabled and disabled. Each type has its own function in IconButtonDefaults, for example filledIconButtonColors().

Tertiary colors
Tertiary colors
FilledIconButton(
    onClick = {},
    colors = IconButtonDefaults.filledIconButtonColors(
        containerColor = MaterialTheme.colorScheme.tertiary,
        contentColor = MaterialTheme.colorScheme.onTertiary,
    ),
) {
    Icon(Icons.Filled.Favorite, contentDescription = "Like")
}

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.

shape: ShapeOptionalSince 1.9

Default: IconButtonDefaults.standardShape

Sets the outline. Default: round. IconButtonDefaults has round and square presets for each size, like smallSquareShape.

Square shape
Square shape
FilledIconButton(onClick = {}, shape = IconButtonDefaults.smallSquareShape) {
    Icon(Icons.Filled.Favorite, contentDescription = "Like")
}

content: @Composable () -> UnitRequired

The icon. Always set a contentDescription on the Icon, so screen readers can say what the button does.

Expressive

Takes shapes: one shape at rest and one while pressed.

@Composable
fun IconButton(
    onClick: () -> Unit,
    shapes: IconButtonShapes,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    colors: IconButtonColors = IconButtonDefaults.iconButtonColors(),
    interactionSource: MutableInteractionSource? = null,
    content: @Composable () -> Unit,
)

shapes: IconButtonShapesRequiredSince 1.10

Sets two shapes: one at rest and one while pressed. Make one with IconButtonDefaults.shapes.

Shape that changes when pressedExpressive theme
Shape that changes when pressed
FilledIconButton(onClick = {}, shapes = IconButtonDefaults.shapes()) {
    Icon(Icons.Filled.Favorite, contentDescription = "Like")
}

Same as above: onClick, modifier, enabled, colors, interactionSource, content.

Icon button types

See also