Text field

Lets people enter and edit text. Filled or outlined, with labels, icons and helper text.

When to use

Use filled text fields for the highest emphasis and outlined ones in dense forms. Always provide a label that stays visible, and use supporting text to explain format or errors.

TextFieldState based overloads keep the text in a state holder instead of a String, which suits input transformations and secure fields.

Playground

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

Examples

Filled and outlined

var text by rememberSaveable { mutableStateOf("") }

Column(Modifier.widthIn(max = 360.dp).fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(16.dp)) {
    TextField(
        value = text,
        onValueChange = { text = it },
        label = { Text("Filled") },
        modifier = Modifier.fillMaxWidth(),
    )
    OutlinedTextField(
        value = text,
        onValueChange = { text = it },
        label = { Text("Outlined") },
        modifier = Modifier.fillMaxWidth(),
    )
}

Secure

Hides the input and offers a reveal toggle through the trailing icon.

val password = rememberTextFieldState()

SecureTextField(
    state = password,
    label = { Text("Password") },
    modifier = Modifier.widthIn(max = 360.dp).fillMaxWidth(),
)

Parameters

NameTypeDefaultDescription
value / stateString | TextFieldStateThe text, as a value or a state holder.
label@Composable (() -> Unit)?nullFloats above the text when focused or filled.
supportingText@Composable (() -> Unit)?nullHelper or error message below the field.
isErrorBooleanfalseSwitches to error colors.
leadingIcon / trailingIcon@Composable (() -> Unit)?nullIcons inside the field.
keyboardOptionsKeyboardOptionsDefaultKeyboard type and IME action.

Guidelines

Do:

Don't:

Accessibility

Related components