<!--
{
  "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/Text",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4TextV"
  },
  "title" : "Text"
}
-->

# Text

A view that displays one or more lines of read-only text.

```
@frozen struct Text
```

## Overview

A text view draws a string in your app’s user interface using a
[`body`](/documentation/SwiftUI/Font/body) font that’s appropriate for the current platform. You can
choose a different standard font, like [`title`](/documentation/SwiftUI/Font/title) or [`caption`](/documentation/SwiftUI/Font/caption),
using the [`font(_:)`](/documentation/SwiftUI/View/font(_:)) view modifier.

```
Text("Hamlet")
    .font(.title)
```

![A text view showing the name “Hamlet” in a title](images/com.apple.SwiftUI/SwiftUI-Text-title@2x.png)

If you need finer control over the styling of the text, you can use the same
modifier to configure a system font or choose a custom font. You can also
apply view modifiers like [`bold()`](/documentation/SwiftUI/Text/bold()) or [`italic()`](/documentation/SwiftUI/Text/italic()) to further
adjust the formatting.

```
Text("by William Shakespeare")
    .font(.system(size: 12, weight: .light, design: .serif))
    .italic()
```

![A text view showing by William Shakespeare in a 12 point, light, italic,](images/com.apple.SwiftUI/SwiftUI-Text-font@2x.png)

To apply styling within specific portions of the text, you can create
the text view from an
<doc://com.apple.documentation/documentation/Foundation/AttributedString>,
which in turn allows you to use Markdown to style runs of text. You can
mix string attributes and SwiftUI modifiers, with the string attributes
taking priority.

```
let attributedString = try! AttributedString(
    markdown: "_Hamlet_ by William Shakespeare")

var body: some View {
    Text(attributedString)
        .font(.system(size: 12, weight: .light, design: .serif))
}
```

![A text view showing Hamlet by William Shakespeare in a 12 point, light,](images/com.apple.SwiftUI/SwiftUI-Text-attributed@2x.png)

A text view always uses exactly the amount of space it needs to display its
rendered contents, but you can affect the view’s layout. For example, you
can use the [`frame(width:height:alignment:)`](/documentation/SwiftUI/View/frame(width:height:alignment:)) modifier to propose
specific dimensions to the view. If the view accepts the proposal but the
text doesn’t fit into the available space, the view uses a combination of
wrapping, tightening, scaling, and truncation to make it fit. With a width
of `100` points but no constraint on the height, a text view might wrap a
long string:

```
Text("To be, or not to be, that is the question:")
    .frame(width: 100)
```

![A text view showing a quote from Hamlet split over three](images/com.apple.SwiftUI/SwiftUI-Text-split@2x.png)

Use modifiers like [`lineLimit(_:)`](/documentation/SwiftUI/View/lineLimit(_:)), [`allowsTightening(_:)`](/documentation/SwiftUI/View/allowsTightening(_:)),
[`minimumScaleFactor(_:)`](/documentation/SwiftUI/View/minimumScaleFactor(_:)), and [`truncationMode(_:)`](/documentation/SwiftUI/View/truncationMode(_:)) to
configure how the view handles space constraints. For example, combining a
fixed width and a line limit of `1` results in truncation for text that
doesn’t fit in that space:

```
Text("Brevity is the soul of wit.")
    .frame(width: 100)
    .lineLimit(1)
```

![A text view showing a truncated quote from Hamlet starting Brevity is t](images/com.apple.SwiftUI/SwiftUI-Text-truncated@2x.png)

### Localizing strings

If you initialize a text view with a string literal, the view uses the
[`init(_:tableName:bundle:comment:)`](/documentation/SwiftUI/Text/init(_:tableName:bundle:comment:)) initializer, which interprets the
string as a localization key and searches for the key in the table you
specify, or in the default table if you don’t specify one.

```
Text("pencil") // Searches the default table in the main bundle.
```

For an app localized in both English and Spanish, the above view displays
“pencil” and “lápiz” for English and Spanish users, respectively. If the
view can’t perform localization, it displays the key instead. For example,
if the same app lacks Danish localization, the view displays “pencil” for
users in that locale. Similarly, an app that lacks any localization
information displays “pencil” in any locale.

To explicitly bypass localization for a string literal, use the
[`init(verbatim:)`](/documentation/SwiftUI/Text/init(verbatim:)) initializer.

```
Text(verbatim: "pencil") // Displays the string "pencil" in any locale.
```

If you initialize a text view with a variable value, the view uses the
[`init(_:)`](/documentation/SwiftUI/Text/init(_:)-9d1g4) initializer, which doesn’t localize the string. However,
you can request localization by creating a [`LocalizedStringKey`](/documentation/SwiftUI/LocalizedStringKey) instance
first, which triggers the [`init(_:tableName:bundle:comment:)`](/documentation/SwiftUI/Text/init(_:tableName:bundle:comment:))
initializer instead:

```
// Don't localize a string variable...
Text(writingImplement)

// ...unless you explicitly convert it to a localized string key.
Text(LocalizedStringKey(writingImplement))
```

When localizing a string variable, you can use the default table by omitting
the optional initialization parameters — as in the above example — just like
you might for a string literal.

When composing a complex string, where there is a need to assemble multiple
pieces of text, use string interpolation:

```
let name: String = //…
Text("Hello, \(name)")
```

This would look up the `"Hello, %@"` localization key in the localized
string file and replace the format specifier `%@` with the value of `name`
before rendering the text on screen.

Using string interpolation ensures that the text in your app can be localized
correctly in all locales, especially in right-to-left languages.

If you desire to style only parts of interpolated text while ensuring that
the content can still be localized correctly, interpolate `Text` or
<doc://com.apple.documentation/documentation/Foundation/AttributedString>:

```
let name = Text(person.name).bold()
Text("Hello, \(name)")
```

The example above uses [`appendInterpolation(_:)`](/documentation/SwiftUI/LocalizedStringKey/StringInterpolation/appendInterpolation(_:)-4qyfo)
and will look up the `"Hello, %@"` in the localized string file and
interpolate a bold text rendering the value of  `name`.

Using [`appendInterpolation(_:)`](/documentation/SwiftUI/LocalizedStringKey/StringInterpolation/appendInterpolation(_:)-5m52e)
you can interpolate [`Image`](/documentation/SwiftUI/Image) in text.

## Topics

### Creating a text view

[`init(_:tableName:bundle:comment:)`](/documentation/SwiftUI/Text/init(_:tableName:bundle:comment:))

Creates a text view that displays localized content identified by a key.

[`init(_:)`](/documentation/SwiftUI/Text/init(_:))

Creates a text view that displays styled attributed content.

[`init(verbatim:)`](/documentation/SwiftUI/Text/init(verbatim:))

Creates a text view that displays a string literal without localization.

[`init(_:style:)`](/documentation/SwiftUI/Text/init(_:style:))

Creates an instance that displays localized dates and times using a specific style.

[`init(_:format:)`](/documentation/SwiftUI/Text/init(_:format:))

Creates a text view that displays the formatted representation
of a nonstring type supported by a corresponding format style.

[`init(_:formatter:)`](/documentation/SwiftUI/Text/init(_:formatter:))

Creates a text view that displays the formatted representation
of a Foundation object.

[`init(timerInterval:pauseTime:countsDown:showsHours:)`](/documentation/SwiftUI/Text/init(timerInterval:pauseTime:countsDown:showsHours:))

Creates an instance that displays a timer counting within the provided
interval.

### Choosing a font

[`font(_:)`](/documentation/SwiftUI/Text/font(_:))

Sets the default font for text in the view.

[`fontWeight(_:)`](/documentation/SwiftUI/Text/fontWeight(_:))

Sets the font weight of the text.

[`fontDesign(_:)`](/documentation/SwiftUI/Text/fontDesign(_:))

Sets the font design of the text.

[`fontWidth(_:)`](/documentation/SwiftUI/Text/fontWidth(_:))

Sets the font width of the text.

### Styling the view’s text

[`foregroundStyle(_:)`](/documentation/SwiftUI/Text/foregroundStyle(_:))

Sets the style of the text displayed by this view.

[`bold()`](/documentation/SwiftUI/Text/bold())

Applies a bold or emphasized treatment to the fonts of the text.

[`bold(_:)`](/documentation/SwiftUI/Text/bold(_:))

Applies a bold font weight to the text.

[`italic()`](/documentation/SwiftUI/Text/italic())

Applies italics to the text.

[`italic(_:)`](/documentation/SwiftUI/Text/italic(_:))

Applies italics to the text.

[`strikethrough(_:color:)`](/documentation/SwiftUI/Text/strikethrough(_:color:))

Applies a strikethrough to the text.

[`strikethrough(_:pattern:color:)`](/documentation/SwiftUI/Text/strikethrough(_:pattern:color:))

Applies a strikethrough to the text.

[`underline(_:color:)`](/documentation/SwiftUI/Text/underline(_:color:))

Applies an underline to the text.

[`underline(_:pattern:color:)`](/documentation/SwiftUI/Text/underline(_:pattern:color:))

Applies an underline to the text.

[`monospaced(_:)`](/documentation/SwiftUI/Text/monospaced(_:))

Modifies the font of the text to use the fixed-width variant
of the current font, if possible.

[`monospacedDigit()`](/documentation/SwiftUI/Text/monospacedDigit())

Modifies the text view’s font to use fixed-width digits, while leaving
other characters proportionally spaced.

[`kerning(_:)`](/documentation/SwiftUI/Text/kerning(_:))

Sets the spacing, or kerning, between characters.

[`tracking(_:)`](/documentation/SwiftUI/Text/tracking(_:))

Sets the tracking for the text.

[`baselineOffset(_:)`](/documentation/SwiftUI/Text/baselineOffset(_:))

Sets the vertical offset for the text relative to its baseline.

[`Text.Case`](/documentation/SwiftUI/Text/Case)

A scheme for transforming the capitalization of characters within text.

[`Text.DateStyle`](/documentation/SwiftUI/Text/DateStyle)

A predefined style used to display a `Date`.

[`Text.LineStyle`](/documentation/SwiftUI/Text/LineStyle)

Description of the style used to draw the line for `StrikethroughStyleAttribute`
and `UnderlineStyleAttribute`.

### Fitting text into available space

[`textScale(_:isEnabled:)`](/documentation/SwiftUI/Text/textScale(_:isEnabled:))

Applies a text scale to the text.

[`Text.Scale`](/documentation/SwiftUI/Text/Scale)

Defines text scales

[`Text.TruncationMode`](/documentation/SwiftUI/Text/TruncationMode)

The type of truncation to apply to a line of text when it’s too long to
fit in the available space.

### Localizing text

[`typesettingLanguage(_:isEnabled:)`](/documentation/SwiftUI/Text/typesettingLanguage(_:isEnabled:))

Specifies the language for typesetting.

### Configuring voiceover

[`speechAdjustedPitch(_:)`](/documentation/SwiftUI/Text/speechAdjustedPitch(_:))

Raises or lowers the pitch of spoken text.

[`speechAlwaysIncludesPunctuation(_:)`](/documentation/SwiftUI/Text/speechAlwaysIncludesPunctuation(_:))

Sets whether VoiceOver should always speak all punctuation in the text
view.

[`speechAnnouncementsQueued(_:)`](/documentation/SwiftUI/Text/speechAnnouncementsQueued(_:))

Controls whether to queue pending announcements behind existing speech
rather than interrupting speech in progress.

[`speechSpellsOutCharacters(_:)`](/documentation/SwiftUI/Text/speechSpellsOutCharacters(_:))

Sets whether VoiceOver should speak the contents of the text view
character by character.

### Providing accessibility information

[`accessibilityHeading(_:)`](/documentation/SwiftUI/Text/accessibilityHeading(_:))

Sets the accessibility level of this heading.

[`accessibilityLabel(_:)`](/documentation/SwiftUI/Text/accessibilityLabel(_:))

Adds a label to the view that describes its contents.

[`accessibilityTextContentType(_:)`](/documentation/SwiftUI/Text/accessibilityTextContentType(_:))

Sets an accessibility text content type.

### Combining text views

[`+(_:_:)`](/documentation/SwiftUI/Text/+(_:_:))

Concatenates the text in two text views in a new text view.

### Deprecated symbols

[`foregroundColor(_:)`](/documentation/SwiftUI/Text/foregroundColor(_:))

Sets the color of the text displayed by this view.



---

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)