<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/multilineTextAlignment(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE22multilineTextAlignmentyQrAA0eF0OF"
  },
  "title" : "multilineTextAlignment(_:)"
}
-->

# multilineTextAlignment(_:)

Sets the alignment of a text view that contains multiple lines of text.

```
nonisolated func multilineTextAlignment(_ alignment: TextAlignment) -> some View
```

## Parameters

`alignment`

A value that you use to align multiple lines of
text within a view.

## Return Value

A view that aligns the lines of multiline [`Text`](/documentation/SwiftUI/Text) instances
it contains.

## Discussion

Use this modifier to set an alignment for a multiline block of text.
For example, the modifier centers the contents of the following
[`Text`](/documentation/SwiftUI/Text) view:

```
Text("This is a block of text that shows up in a text element as multiple lines.\("\n") Here we have chosen to center this text.")
    .frame(width: 200)
    .multilineTextAlignment(.center)
```

The text in the above example spans more than one line because:

- The newline character introduces a line break.
- The frame modifier limits the space available to the text view, and
  by default a text view wraps lines that don’t fit in the available
  width. As a result, the text before the explicit line break wraps to
  three lines, and the text after uses two lines.

The modifier applies the alignment to the all the lines of text in
the view, regardless of why wrapping occurs:

![A block of text that spans 5 lines. The lines of text are center-aligned.](images/com.apple.SwiftUI/View-multilineTextAlignment-1-iOS@2x.png)

The modifier has no effect on a [`Text`](/documentation/SwiftUI/Text) view that contains only one
line of text, because a text view has a width that exactly matches the
width of its widest line. If you want to align an entire text view
rather than its contents, set the aligment of its container, like a
[`VStack`](/documentation/SwiftUI/VStack) or a frame that you create with the
[`frame(minWidth:idealWidth:maxWidth:minHeight:idealHeight:maxHeight:alignment:)`](/documentation/SwiftUI/View/frame(minWidth:idealWidth:maxWidth:minHeight:idealHeight:maxHeight:alignment:))
modifier.

> Note: You can use this modifier to control the alignment of a ``doc://com.apple.SwiftUI/documentation/SwiftUI/Text``
> view that you create with the ``doc://com.apple.SwiftUI/documentation/SwiftUI/Text/init(_:style:)`` initializer
> to display localized dates and times, including when the view uses
> only a single line, but only when that view appears in a widget.

The modifier also affects the content alignment of other text container
types, like [`TextEditor`](/documentation/SwiftUI/TextEditor) and [`TextField`](/documentation/SwiftUI/TextField). In those cases, the
modifier sets the alignment even when the view contains only a single
line because view’s width isn’t dictated by the width of the text it
contains.

The modifier operates by setting the
[`multilineTextAlignment`](/documentation/SwiftUI/EnvironmentValues/multilineTextAlignment) value in the environment,
so it affects all the text containers in the modified view hierarchy.
For example, you can apply the modifier to a [`VStack`](/documentation/SwiftUI/VStack) to
configure all the text views inside the stack.

---

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)