<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Text/init(_:)-1a4oh",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4TextVyAC10Foundation16AttributedStringVcfc"
  },
  "title" : "init(_:)"
}
-->

# init(_:)

Creates a text view that displays styled attributed content.

```
init(_ attributedContent: AttributedString)
```

## Parameters

`attributedContent`

An attributed string to style and display,
in accordance with its attributes.

## Discussion

### Format text by combining attributes and view modifiers

Use this initializer to style text according to attributes found in the specified
<doc://com.apple.documentation/documentation/Foundation/AttributedString>.
Attributes in the attributed string take precedence over styles added by
view modifiers. For example, the attributed text in the following
example appears in blue, despite the use of the `View/foregroundColor(_:)`
modifier to use red throughout the enclosing `VStack`:

```
var content: AttributedString {
    var attributedString = AttributedString("Blue text")
    attributedString.foregroundColor = .blue
    return attributedString
}

var body: some View {
    VStack {
        Text(content)
        Text("Red text")
    }
    .foregroundColor(.red)
}
```

![A vertical stack of two text views, the top labeled Blue Text with a](images/com.apple.SwiftUI/SwiftUI-Text-init-attributed@2x.png)

SwiftUI combines text attributes with SwiftUI modifiers whenever
possible. For example, the following listing creates text that is
both bold and red:

```
var content: AttributedString {
    var content = AttributedString("Some text")
    content.inlinePresentationIntent = .stronglyEmphasized
    return content
}

var body: some View {
    Text(content).foregroundColor(Color.red)
}
```

### Supported Foundation attributes

A SwiftUI `Text` view renders most of the styles defined by the
Foundation attribute
<doc://com.apple.documentation/documentation/Foundation/AttributeScopes/FoundationAttributes/inlinePresentationIntent>, like the
<doc://com.apple.documentation/documentation/Foundation/InlinePresentationIntent/stronglyEmphasized>
value, which SwiftUI presents as bold text.

> Important: ``Text`` uses only a subset of the attributes defined in
> <doc://com.apple.documentation/documentation/Foundation/AttributeScopes/FoundationAttributes>.
> `Text` renders all
> <doc://com.apple.documentation/documentation/Foundation/InlinePresentationIntent>
> attributes except for
> <doc://com.apple.documentation/documentation/Foundation/InlinePresentationIntent/lineBreak> and
> <doc://com.apple.documentation/documentation/Foundation/InlinePresentationIntent/softBreak>.
> It also respects <doc://com.apple.documentation/documentation/Foundation/AttributeScopes/FoundationAttributes/writingDirection>
> and renders the
> <doc://com.apple.documentation/documentation/Foundation/AttributeScopes/FoundationAttributes/link>
> attribute as a clickable link. `Text` ignores any other
> Foundation-defined attributes in an attributed string.

### SwiftUI attributes

SwiftUI also defines additional attributes in the attribute scope
<doc://com.apple.documentation/documentation/Foundation/AttributeScopes/SwiftUIAttributes>
which you can access from an attributed string’s
<doc://com.apple.documentation/documentation/Foundation/AttributeScopes/swiftUI>
property. SwiftUI attributes take precedence over equivalent attributes
from other frameworks, such as
<doc://com.apple.documentation/documentation/Foundation/AttributeScopes/UIKitAttributes> and
<doc://com.apple.documentation/documentation/Foundation/AttributeScopes/AppKitAttributes>.

### Markdown support

You can create an `AttributedString` with Markdown syntax, which allows
you to style distinct runs within a `Text` view:

```
let content = try! AttributedString(
    markdown: "**Thank You!** Please visit our [website](http://example.com).")

var body: some View {
    Text(content)
}
```

The `**` syntax around “Thank You!” applies an
<doc://com.apple.documentation/documentation/Foundation/AttributeScopes/FoundationAttributes/inlinePresentationIntent>
attribute with the value
<doc://com.apple.documentation/documentation/Foundation/InlinePresentationIntent/stronglyEmphasized>.
SwiftUI renders this as
bold text, as described earlier. The link syntax around “website”
creates a
<doc://com.apple.documentation/documentation/Foundation/AttributeScopes/FoundationAttributes/link>
attribute, which `Text` styles to indicate it’s a link; by default,
clicking or tapping the link opens the linked URL in the user’s default
browser. Alternatively, you can perform custom link handling by putting
an `OpenURLAction` in the text view’s environment.

![A text view that says Thank you. Please visit our website. The text](images/com.apple.SwiftUI/SwiftUI-Text-init-markdown@2x.png)

You can also use Markdown syntax in localized string keys, which means
you can write the above example without needing to explicitly create
an `AttributedString`:

```
var body: some View {
    Text("**Thank You!** Please visit our [website](https://example.com).")
}
```

In your app’s strings files, use Markdown syntax to apply styling
to the app’s localized strings. You also use this approach when you want
to perform automatic grammar agreement on localized strings, with
the `^[text](inflect:true)` syntax.

For details about Markdown syntax support in SwiftUI, see
`Text/init(_:tableName:bundle:comment:)`.

### Applying a custom text formatting definition

Use the `View/attributedTextFormattingDefinition(_:)-(D)` modifier to
apply a custom `AttributedTextFormattingDefinition` to text created
using this initializer. This will result in the text only applying
attributes in the definition’s attribute scope and constraining
attributes according to the definition’s value constraints prior to
display.

Custom attributes listed in the definition’s
`AttributedTextFormattingDefinition/Scope`, where the
<doc://com.apple.documentation/documentation/Foundation/AttributedStringKey/Value>
conforms to the `TextAttribute` protocol, can be read when observing
the text’s layout using `Text/Layout/Run/subscript(key:)->T?`, just
as text attributes applied using the `Text/customAttribute(_:)`
modifier.

---

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)