androidx.compose.material3

Surface

Composable function

A surface is a container with a background color, a shape, an optional shadow and an optional outline. Most Material components, like Card and Button, are a Surface with some defaults. Use it when no component fits.

A surface also sets the content color: text and icons inside get the matching "on" color, like onPrimaryContainer on primaryContainer.

Color, shape, shadow and outline
Color, shape, shadow and outline
Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
    Surface(color = MaterialTheme.colorScheme.primaryContainer, shape = MaterialTheme.shapes.medium) {
        Text("Colored", Modifier.padding(16.dp))
    }
    Surface(shadowElevation = 6.dp, shape = MaterialTheme.shapes.medium) {
        Text("Shadow", Modifier.padding(16.dp))
    }
    Surface(border = BorderStroke(1.dp, MaterialTheme.colorScheme.outline), shape = MaterialTheme.shapes.medium) {
        Text("Outline", Modifier.padding(16.dp))
    }
}

Basic

Not clickable.

@Composable
fun Surface(
    modifier: Modifier = Modifier,
    shape: Shape = RectangleShape,
    color: Color = MaterialTheme.colorScheme.surface,
    contentColor: Color = contentColorFor(color),
    tonalElevation: Dp = 0.dp,
    shadowElevation: Dp = 0.dp,
    border: BorderStroke? = null,
    content: @Composable () -> Unit,
)

modifier: ModifierOptional

Default: Modifier

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

shape: ShapeOptional

Default: RectangleShape

Sets the outline. Default: square corners. See the Shapes guide.

color: ColorOptional

Default: MaterialTheme.colorScheme.surface

The background color. Default: the theme's surface.

contentColor: ColorOptional

Default: contentColorFor(color)

The default color for text and icons inside. Default: the matching "on" color for color.

tonalElevation: DpOptional

Default: 0.dp

Tints the background a little toward the primary color. Higher values give a stronger tint. This only works when color is the theme's surface.

shadowElevation: DpOptional

Default: 0.dp

The size of the shadow under the surface.

border: BorderStroke?Optional

Default: null

Draws an outline. null means no outline.

content: @Composable () -> UnitRequired

What the surface shows. The surface adds no padding and no layout. Put a Column or Row inside if you have several items.

Clickable

Takes onClick.

@Composable
fun Surface(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    shape: Shape = RectangleShape,
    color: Color = MaterialTheme.colorScheme.surface,
    contentColor: Color = contentColorFor(color),
    tonalElevation: Dp = 0.dp,
    shadowElevation: Dp = 0.dp,
    border: BorderStroke? = null,
    interactionSource: MutableInteractionSource? = null,
    content: @Composable () -> Unit,
)

onClick: () -> UnitRequired

Called when the surface is clicked. Only on the clickable, selectable and toggleable forms.

A clickable surface
A clickable surface
Surface(
    onClick = {},
    color = MaterialTheme.colorScheme.secondaryContainer,
    shape = CircleShape,
) {
    Text("Tap me", Modifier.padding(horizontal = 20.dp, vertical = 10.dp))
}

enabled: BooleanOptional

Default: true

Set to false to make it not clickable. The surface does not turn gray by itself.

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.

Same as above: modifier, shape, color, contentColor, tonalElevation, shadowElevation, border, content.

Selectable

Takes selected and onClick, like a tab or a radio button.

@Composable
fun Surface(
    selected: Boolean,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    shape: Shape = RectangleShape,
    color: Color = MaterialTheme.colorScheme.surface,
    contentColor: Color = contentColorFor(color),
    tonalElevation: Dp = 0.dp,
    shadowElevation: Dp = 0.dp,
    border: BorderStroke? = null,
    interactionSource: MutableInteractionSource? = null,
    content: @Composable () -> Unit,
)

selected: BooleanRequired

Whether the surface is selected. Screen readers announce it.

Same as above: onClick, modifier, enabled, shape, color, contentColor, tonalElevation, shadowElevation, border, interactionSource, content.

Toggleable

Takes checked and onCheckedChange, like a switch.

@Composable
fun Surface(
    checked: Boolean,
    onCheckedChange: (Boolean) -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    shape: Shape = RectangleShape,
    color: Color = MaterialTheme.colorScheme.surface,
    contentColor: Color = contentColorFor(color),
    tonalElevation: Dp = 0.dp,
    shadowElevation: Dp = 0.dp,
    border: BorderStroke? = null,
    interactionSource: MutableInteractionSource? = null,
    content: @Composable () -> Unit,
)

checked: BooleanRequired

Whether the surface is checked. Screen readers announce it as on or off.

onCheckedChange: (Boolean) -> UnitRequired

Called with the new value when the surface is clicked.

Same as above: modifier, enabled, shape, color, contentColor, tonalElevation, shadowElevation, border, interactionSource, content.