<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/TextEditor",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI10TextEditorV"
  },
  "title" : "TextEditor"
}
-->

# TextEditor

A view that can display and edit long-form text.

```
nonisolated struct TextEditor
```

## Overview

A text editor view allows you to display and edit multiline, scrollable
text in your app’s user interface. By default, the text editor view styles
the text using characteristics inherited from the environment, like
[`font(_:)`](/documentation/SwiftUI/View/font(_:)), [`foregroundColor(_:)`](/documentation/SwiftUI/View/foregroundColor(_:)), and
[`multilineTextAlignment(_:)`](/documentation/SwiftUI/View/multilineTextAlignment(_:)). The text editor view supports
attributed text formatting when initialized with
[`init(text:selection:)`](/documentation/SwiftUI/TextEditor/init(text:selection:)-11r0a).

You create a text editor by adding a `TextEditor` instance to the
body of your view, and initialize it by passing in a
[`Binding`](/documentation/SwiftUI/Binding) to a string variable in your app:

```
struct TextEditingView: View {
    @State private var fullText: String = "This is some editable text..."

    var body: some View {
        TextEditor(text: $fullText)
    }
}
```

To style the text, use the standard view modifiers to configure a system
font, set a custom font, or change the color of the view’s text.

In this example, the view renders the editor’s text in gray with a
custom font:

```
struct TextEditingView: View {
    @State private var fullText: String = "This is some editable text..."

    var body: some View {
        TextEditor(text: $fullText)
            .foregroundColor(Color.gray)
            .font(.custom("HelveticaNeue", size: 13))
    }
}
```

If you want to change the spacing or font scaling aspects of the text, you
can use modifiers like [`lineLimit(_:)`](/documentation/SwiftUI/View/lineLimit(_:)),
[`lineSpacing(_:)`](/documentation/SwiftUI/View/lineSpacing(_:)), and [`minimumScaleFactor(_:)`](/documentation/SwiftUI/View/minimumScaleFactor(_:)) to configure
how the view displays text depending on the space constraints. For example,
here the [`lineSpacing(_:)`](/documentation/SwiftUI/View/lineSpacing(_:)) modifier sets the spacing between lines
to 5 points:

```
struct TextEditingView: View {
    @State private var fullText: String = "This is some editable text..."

    var body: some View {
        TextEditor(text: $fullText)
            .foregroundColor(Color.gray)
            .font(.custom("HelveticaNeue", size: 13))
            .lineSpacing(5)
    }
}
```

### Text formatting

When initialized with [`init(text:selection:)`](/documentation/SwiftUI/TextEditor/init(text:selection:)-11r0a),
`TextEditor` supports editing and formatting styled text.

By default, `TextEditor` shows system text formatting controls in the
context menu and in the keyboard toolbar on iOS.
Use [`textInputFormattingControlVisibility(_:for:)`](/documentation/SwiftUI/View/textInputFormattingControlVisibility(_:for:)) to configure
visibility of system text formatting controls.

For more information on formatting attributed text with `TextEditor`, see
[`init(text:selection:)`](/documentation/SwiftUI/TextEditor/init(text:selection:)-11r0a).

## Topics

### Creating a text editor

[`init(text:)`](/documentation/SwiftUI/TextEditor/init(text:))

Creates a plain text editor.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)