# contentType

Common/AllAndroid/JVM

## Functions summary

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.https://developer.android.com/reference/kotlin/androidx/compose/ui/autofill/contentType.modifier#(androidx.compose.ui.Modifier).contentType(androidx.compose.ui.autofill.ContentType)(contentType: https://developer.android.com/reference/kotlin/androidx/compose/ui/autofill/ContentType)` Set autofill hint with `https://developer.android.com/reference/kotlin/androidx/compose/ui/autofill/package-summary#(androidx.compose.ui.Modifier).contentType(androidx.compose.ui.autofill.ContentType)`. | Cmn |

## Functions

### Modifier.contentType

Cmn Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/autofill/AutofillModifier.kt+function:contentType) Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.9.0)

```
fun Modifier.contentType(contentType: ContentType): Modifier
```

Set autofill hint with `https://developer.android.com/reference/kotlin/androidx/compose/ui/autofill/package-summary#(androidx.compose.ui.Modifier).contentType(androidx.compose.ui.autofill.ContentType)`.

This applies the `https://developer.android.com/reference/kotlin/androidx/compose/ui/autofill/package-summary#(androidx.compose.ui.Modifier).contentType(androidx.compose.ui.autofill.ContentType)` to the modifier's semantics, in turn enabling autofill and marking the hint to be associated with this composable. This allows autofill frameworks to provide relevant suggestions to users.

Using `contentType` is equivalent to simply setting the `contentType` semantic property, i.e. `Modifier.contentType(ContentType.NewUsername)` is equivalent to setting `Modifier.semantics { contentType = ContentType.NewUsername }`.

```kotlin
import androidx.compose.foundation.text.input.rememberTextFieldState
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.ui.Modifier
import androidx.compose.ui.autofill.ContentType
import androidx.compose.ui.autofill.contentType
import androidx.compose.ui.semantics.contentType

TextField(
    state = rememberTextFieldState(),
    label = { Text("Enter your new username here.") },
    // Set the content type hint with the modifier extension.
    modifier = Modifier.contentType(ContentType.NewUsername),
)
```

```kotlin
import androidx.compose.foundation.text.input.rememberTextFieldState
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.ui.Modifier
import androidx.compose.ui.autofill.ContentType
import androidx.compose.ui.autofill.contentType
import androidx.compose.ui.semantics.contentType
import androidx.compose.ui.semantics.semantics

TextField(
    state = rememberTextFieldState(),
    label = { Text("Enter your new password here.") },
    // Set the content type hint with semantics.
    modifier = Modifier.semantics { contentType = ContentType.NewPassword },
)
```

| Parameters |
|---|---|
| `contentType: https://developer.android.com/reference/kotlin/androidx/compose/ui/autofill/ContentType` | The `https://developer.android.com/reference/kotlin/androidx/compose/ui/autofill/ContentType` to apply to the component's semantics. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` | The `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` with the specified `https://developer.android.com/reference/kotlin/androidx/compose/ui/autofill/ContentType` semantics set. |