How do I create a multiline TextField in SwiftUI?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In current SwiftUI, you have two good options for multiline text input. Use TextField with axis: .vertical when you want a field that can grow to a few lines, and use TextEditor when you want a true large text area for notes, comments, or message composition.
Use TextField with a vertical axis
Modern SwiftUI supports an expanding text field directly:
This is the closest thing to a multiline TextField. The field starts compact, expands vertically as the user types, and can be constrained with lineLimit.
This approach is a good fit when:
- you still conceptually want a field, not a large editor
- the content is expected to stay fairly short
- you want standard
TextFieldbehavior such as submit handling
Use TextEditor for true long-form input
If the content might be paragraphs long, TextEditor is usually the better control:
TextEditor behaves more like UITextView from UIKit. It is designed for multiline editing first, not as an enhanced single-line field.
That makes it the better choice for:
- notes
- descriptions
- feedback forms
- chat drafts
- any input that may grow beyond a few lines
Add placeholder behavior when using TextEditor
One difference is that TextEditor does not have a built-in placeholder the way TextField does. A common SwiftUI pattern is to layer placeholder text behind the editor:
This is often enough for production UI, especially when paired with validation and character-count feedback.
Decide between the two controls intentionally
The question is not just "how do I make it multiline?" It is also "what editing experience do I want?"
Use TextField(axis: .vertical) when you want a compact field that can stretch a bit. Think message subjects, short comments, or reply boxes with limited expected length.
Use TextEditor when you want a dedicated editing surface. Think descriptions, notes, or any content the user may scroll through and revise more heavily.
That distinction matters because the control choice affects selection behavior, placeholder handling, scrolling, and overall feel.
Focus and keyboard handling
Both controls work with SwiftUI focus APIs. Here is a simple example with TextEditor:
That makes it easier to control first-responder behavior in forms or compose screens.
Common Pitfalls
The biggest mistake is assuming old advice that "TextField is single-line only" is still the whole story. That was broadly true before SwiftUI gained the vertical-axis initializer, but not for current releases.
Another common issue is forcing TextEditor into a field-shaped UI without accounting for placeholder behavior and height management.
People also choose TextField(axis: .vertical) for very long content, then run into awkward scrolling or editing limits. At that point, TextEditor is usually the better control.
Finally, styling can be misleading. TextEditor does not automatically look like a standard TextField, so you often need to add borders or background styling yourself.
Summary
- Use
TextField(..., axis: .vertical)for a field that can grow across a few lines. - Use
TextEditorfor true multiline, long-form text entry. - Add your own placeholder layer when using
TextEditor. - Pick the control based on editing behavior, not just visual appearance.
- Use SwiftUI focus APIs to manage keyboard and first-responder behavior cleanly.

