androidx.compose.material3
TextField
Composable function
A text field lets the user enter and edit text. There are two looks: filled (TextField) and outlined (OutlinedTextField). They take the same parameters.

val name = rememberTextFieldState("Ada")
TextField(state = name, label = { Text("Name") })

Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
TextField(state = rememberTextFieldState(), label = { Text("Filled") })
OutlinedTextField(state = rememberTextFieldState(), label = { Text("Outlined") })
}
For passwords, use SecureTextField or OutlinedSecureTextField. They hide the text and stop copying.

OutlinedSecureTextField(
state = rememberTextFieldState("hunter2"),
label = { Text("Password") },
)
There are three forms. Use the first one, with TextFieldState, for new code. Create the state with rememberTextFieldState().
StateSince 1.9
The recommended form. Takes a TextFieldState that holds the text.
@Composable
fun TextField(
state: TextFieldState,
modifier: Modifier = Modifier,
enabled: Boolean = true,
readOnly: Boolean = false,
textStyle: TextStyle = LocalTextStyle.current,
labelPosition: TextFieldLabelPosition = TextFieldLabelPosition.Inside(),
label: @Composable (TextFieldLabelScope.() -> Unit)? = null,
placeholder: @Composable (() -> Unit)? = null,
leadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
prefix: @Composable (() -> Unit)? = null,
suffix: @Composable (() -> Unit)? = null,
supportingText: @Composable (() -> Unit)? = null,
isError: Boolean = false,
inputTransformation: InputTransformation? = null,
outputTransformation: OutputTransformation? = null,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
onKeyboardAction: KeyboardActionHandler? = null,
lineLimits: TextFieldLineLimits = TextFieldLineLimits.Default,
onTextLayout: (Density.(getResult: () -> TextLayoutResult?) -> Unit)? = null,
scrollState: ScrollState = rememberScrollState(),
shape: Shape = TextFieldDefaults.shape,
colors: TextFieldColors = TextFieldDefaults.colors(),
contentPadding: PaddingValues = TextFieldDefaults.defaultContentPadding(label, labelPosition),
interactionSource: MutableInteractionSource? = null,
)
state: TextFieldStateRequired
state: TextFieldStateRequiredHolds the text and the cursor. Create it with rememberTextFieldState("initial text") and read it with state.text.
modifier: ModifierOptional
modifier: ModifierOptionalDefault: Modifier
Changes size, padding, or position of the field. See the Modifier guide.
Use Modifier.fillMaxWidth() to stretch it.
enabled: BooleanOptional
enabled: BooleanOptionalDefault: true
Set to false to make the field gray. The user cannot focus, edit or copy it.
readOnly: BooleanOptional
readOnly: BooleanOptionalDefault: false
Set to true to block editing. The user can still focus, select and copy the text.
textStyle: TextStyleOptional
textStyle: TextStyleOptionalDefault: LocalTextStyle.current
The style of the entered text. Default: the current LocalTextStyle.
labelPosition: TextFieldLabelPositionOptional
labelPosition: TextFieldLabelPositionOptionalDefault: TextFieldLabelPosition.Inside()
Where the label sits: inside the field (default for TextField), cut into the outline (default for OutlinedTextField), or above it.
label: @Composable (TextFieldLabelScope.() -> Unit)?Optional
label: @Composable (TextFieldLabelScope.() -> Unit)?OptionalDefault: null
A short name for the field, like "Email". It sits inside the field and moves up when the field has text or focus.
placeholder: @Composable (() -> Unit)?Optional
placeholder: @Composable (() -> Unit)?OptionalDefault: null
Gray text shown while the field is empty and focused, like an example value.

OutlinedTextField(
state = rememberTextFieldState(),
placeholder = { Text("[email protected]") },
label = { Text("Email") },
)
leadingIcon: @Composable (() -> Unit)?Optional
leadingIcon: @Composable (() -> Unit)?OptionalDefault: null
An icon at the start of the field, like a search icon.

val query = rememberTextFieldState("Lisbon")
TextField(
state = query,
leadingIcon = { Icon(Icons.Filled.Search, contentDescription = null) },
trailingIcon = { Icon(Icons.Filled.Clear, contentDescription = "Clear") },
lineLimits = TextFieldLineLimits.SingleLine,
)
trailingIcon: @Composable (() -> Unit)?Optional
trailingIcon: @Composable (() -> Unit)?OptionalDefault: null
An icon at the end of the field, like a clear button or a password toggle.
prefix: @Composable (() -> Unit)?Optional
prefix: @Composable (() -> Unit)?OptionalDefault: null
Text before the input that the user cannot edit, like a currency symbol.

OutlinedTextField(
state = rememberTextFieldState("25"),
label = { Text("Price") },
prefix = { Text("€") },
suffix = { Text("per night") },
modifier = Modifier.width(240.dp),
)
suffix: @Composable (() -> Unit)?Optional
suffix: @Composable (() -> Unit)?OptionalDefault: null
Text after the input that the user cannot edit, like a unit.
supportingText: @Composable (() -> Unit)?Optional
supportingText: @Composable (() -> Unit)?OptionalDefault: null
A line of help or error text below the field.
isError: BooleanOptional
isError: BooleanOptionalDefault: false
Set to true to show the field in the error color. Explain the error in supportingText.

OutlinedTextField(
state = rememberTextFieldState("12"),
label = { Text("Age") },
isError = true,
supportingText = { Text("Must be 18 or older") },
)
inputTransformation: InputTransformation?Optional
inputTransformation: InputTransformation?OptionalDefault: null
Changes or rejects what the user types, for example to allow only digits.
outputTransformation: OutputTransformation?Optional
outputTransformation: OutputTransformation?OptionalDefault: null
Changes how the text is shown without changing the text itself, for example to add spaces to a phone number.
keyboardOptions: KeyboardOptionsOptional
keyboardOptions: KeyboardOptionsOptionalDefault: KeyboardOptions.Default
Which keyboard to show (text, number, email, …) and what the action key says (Done, Search, Next, …).
onKeyboardAction: KeyboardActionHandler?Optional
onKeyboardAction: KeyboardActionHandler?OptionalDefault: null
Called when the user presses the keyboard action key.
lineLimits: TextFieldLineLimitsOptional
lineLimits: TextFieldLineLimitsOptionalDefault: TextFieldLineLimits.Default
One line or several. TextFieldLineLimits.SingleLine stops Enter from adding a new line.

OutlinedTextField(
state = rememberTextFieldState("Line one\nLine two"),
label = { Text("Notes") },
lineLimits = TextFieldLineLimits.MultiLine(minHeightInLines = 3),
modifier = Modifier.width(280.dp),
)
onTextLayout: (Density.(getResult: () -> TextLayoutResult?) -> Unit)?Optional
onTextLayout: (Density.(getResult: () -> TextLayoutResult?) -> Unit)?OptionalDefault: null
Called with the text layout after it changes. Rarely needed.
scrollState: ScrollStateOptional
scrollState: ScrollStateOptionalDefault: rememberScrollState()
Controls scrolling inside the field. Rarely needed.
shape: ShapeOptional
shape: ShapeOptionalDefault: TextFieldDefaults.shape
Sets the outline. See the Shapes guide.
colors: TextFieldColorsOptional
colors: TextFieldColorsOptionalDefault: TextFieldDefaults.colors()
Sets colors for every state: focused, unfocused, disabled and error.
Make one with TextFieldDefaults.colors or OutlinedTextFieldDefaults.colors.
contentPadding: PaddingValuesOptional
contentPadding: PaddingValuesOptionalDefault: TextFieldDefaults.defaultContentPadding(label, labelPosition)
Space between the edge of the field and the text.
interactionSource: MutableInteractionSource?Optional
interactionSource: MutableInteractionSource?OptionalDefault: null
Lets you observe or control press, hover and focus states. Leave it null unless your code must react to them. See InteractionSource.
String
The older form. You keep the text in a String and update it in onValueChange.
@Composable
fun TextField(
value: String,
onValueChange: (String) -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
readOnly: Boolean = false,
textStyle: TextStyle = LocalTextStyle.current,
label: @Composable (() -> Unit)? = null,
placeholder: @Composable (() -> Unit)? = null,
leadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
prefix: @Composable (() -> Unit)? = null,
suffix: @Composable (() -> Unit)? = null,
supportingText: @Composable (() -> Unit)? = null,
isError: Boolean = false,
visualTransformation: VisualTransformation = VisualTransformation.None,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
singleLine: Boolean = false,
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
minLines: Int = 1,
interactionSource: MutableInteractionSource? = null,
shape: Shape = TextFieldDefaults.shape,
colors: TextFieldColors = TextFieldDefaults.colors(),
)
value: StringRequired
value: StringRequiredThe current text. Pass your state here.
onValueChange: (String) -> UnitRequired
onValueChange: (String) -> UnitRequiredCalled with the new text on every change. Update your state here. If you do not, the field does not change.

var password by remember { mutableStateOf("hunter2") }
TextField(
value = password,
onValueChange = { password = it },
label = { Text("Password") },
visualTransformation = PasswordVisualTransformation(),
singleLine = true,
)
label: @Composable (() -> Unit)?Optional
label: @Composable (() -> Unit)?OptionalDefault: null
A short name for the field, like "Email". It sits inside the field and moves up when the field has text or focus.
visualTransformation: VisualTransformationOptional
visualTransformation: VisualTransformationOptionalDefault: VisualTransformation.None
Changes how the text is shown. Use PasswordVisualTransformation() to hide a password. The String-form version of outputTransformation.
keyboardActions: KeyboardActionsOptional
keyboardActions: KeyboardActionsOptionalDefault: KeyboardActions.Default
Called when the user presses the keyboard action key. The String-form version of onKeyboardAction.
singleLine: BooleanOptional
singleLine: BooleanOptionalDefault: false
Set to true to keep the text on one line. The String-form version of lineLimits.
maxLines: IntOptional
maxLines: IntOptionalDefault: if (singleLine) 1 else Int.MAX_VALUE
The most lines shown before the field scrolls.
minLines: IntOptional
minLines: IntOptionalDefault: 1
The fewest lines shown, even when empty.
Same as above: modifier, enabled, readOnly, textStyle, placeholder, leadingIcon, trailingIcon, prefix, suffix, supportingText, isError, keyboardOptions, interactionSource, shape, colors.
TextFieldValue
Like the String form, but also gives you the cursor and selection.
@Composable
fun TextField(
value: TextFieldValue,
onValueChange: (TextFieldValue) -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
readOnly: Boolean = false,
textStyle: TextStyle = LocalTextStyle.current,
label: @Composable (() -> Unit)? = null,
placeholder: @Composable (() -> Unit)? = null,
leadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
prefix: @Composable (() -> Unit)? = null,
suffix: @Composable (() -> Unit)? = null,
supportingText: @Composable (() -> Unit)? = null,
isError: Boolean = false,
visualTransformation: VisualTransformation = VisualTransformation.None,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
singleLine: Boolean = false,
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
minLines: Int = 1,
interactionSource: MutableInteractionSource? = null,
shape: Shape = TextFieldDefaults.shape,
colors: TextFieldColors = TextFieldDefaults.colors(),
)
value: TextFieldValueRequired
value: TextFieldValueRequiredThe current text. Pass your state here.
onValueChange: (TextFieldValue) -> UnitRequired
onValueChange: (TextFieldValue) -> UnitRequiredCalled with the new text on every change. Update your state here. If you do not, the field does not change.

var password by remember { mutableStateOf("hunter2") }
TextField(
value = password,
onValueChange = { password = it },
label = { Text("Password") },
visualTransformation = PasswordVisualTransformation(),
singleLine = true,
)
Same as above: modifier, enabled, readOnly, textStyle, label, placeholder, leadingIcon, trailingIcon, prefix, suffix, supportingText, isError, visualTransformation, keyboardOptions, keyboardActions, singleLine, maxLines, minLines, interactionSource, shape, colors.
Text field types
See also
TextFieldDefaults: default values and helper functions forTextField.