Password field

A text field that hides what is typed and can reveal it on request.

When to use

SecureTextField masks the input and blocks copy and cut, which is what a password field needs. By default it briefly reveals the last typed character, which helps on touch keyboards.

Offer a visibility toggle so people can check what they typed. Describe the toggle state in its content description.

Playground

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

Examples

With visibility toggle

val password = rememberTextFieldState()
var visible by remember { mutableStateOf(false) }

OutlinedSecureTextField(
    state = password,
    label = { Text("Password") },
    textObfuscationMode = if (visible) TextObfuscationMode.Visible else TextObfuscationMode.RevealLastTyped,
    trailingIcon = {
        IconButton(onClick = { visible = !visible }) {
            Icon(
                imageVector = if (visible) Icons.Rounded.VisibilityOff else Icons.Rounded.Visibility,
                contentDescription = if (visible) "Hide password" else "Show password",
            )
        }
    },
    modifier = Modifier.widthIn(max = 360.dp).fillMaxWidth(),
)

Parameters

NameTypeDefaultDescription
stateTextFieldStateHolds the secret text.
textObfuscationModeTextObfuscationModeRevealLastTypedHidden, RevealLastTyped or Visible.
trailingIcon@Composable (() -> Unit)?nullPlace the visibility toggle here.

Guidelines

Do:

Don't:

Accessibility

Related components