# SwiftUI forms: TextField

> Learn how to use the TextField control in SwiftUI to get text input from the user, binding it to a @State property and setting placeholder text.

Author: Flavio Copes | Published: 2021-09-25 | Canonical: https://flaviocopes.com/swiftui-forms-textfield/

The first form control we'll see is the simplest: `TextField`.

This lets us show some text, like the `Text` view, and it can be editable by the user, so we can get input in the form of text.

Here's the most basic example of `TextField`:

```swift
struct ContentView: View {
    @State private var name = ""
    
    var body: some View {
        Form {
            TextField("", text: $name)
        }
    }
}
```

We have a [SwiftUI: properties](https://flaviocopes.com/swiftui-properties/) that we prefaced with the `@State` *property wrapper*.

Run the code. You can see an empty text field. You can tap on it:

![Xcode showing SwiftUI TextField code with iOS simulator displaying an empty text field in a form](https://flaviocopes.com/images/swiftui-forms-textfield/Screen_Shot_2021-09-23_at_19.24.04.png)

And you can enter any text inside it:

![iOS simulator showing the text field with user input text displaying the word test](https://flaviocopes.com/images/swiftui-forms-textfield/Screen_Shot_2021-09-23_at_19.24.10.png)

The first argument of `TextField` is a string that's visualized when the field is empty. You can fill it with any text you want, like this:

```swift
TextField("Your name", text: $name)
```

![iOS simulator displaying a text field with Your name placeholder text visible](https://flaviocopes.com/images/swiftui-forms-textfield/Screen_Shot_2021-09-23_at_19.24.44.png)
