<!--
{
  "documentType" : "article",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/instantiating-attributed-strings-with-markdown-syntax",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Instantiating Attributed Strings with Markdown Syntax"
}
-->

# Instantiating Attributed Strings with Markdown Syntax

Use a Markdown-syntax string to iniitalize an attributed string with standard or custom attributes.

## Discussion

You can use familiar Markdown syntax to initialize an attributed string with both its initial text and attributes for things like inline styles and links. In many cases, this produces easier-to-read code than manually setting attributes on ranges of an existing attributed string.

```swift
if let attString = try? AttributedString(
    markdown: "See the *latest* news at [our website](https://example.com)."),
    let websiteRange = attString.range(of: "our website"),
    let link = attString[websiteRange].link {
    print("\(link)") // Prints "https://example.com".
}
```

In this example, `attString` contains five runs, with attributes parsed from the syntax in the `markdown` parameter:

- `“See the “`, with no attributes.
- `“latest”`, with an [`AttributeScopes.FoundationAttributes.InlinePresentationIntentAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/InlinePresentationIntentAttribute) whose value is [`emphasized`](/documentation/Foundation/InlinePresentationIntent/emphasized).
- `“ news at “`, with no attributes.
- `“our website”`, with an [`AttributeScopes.FoundationAttributes.LinkAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/LinkAttribute) whose value is a [`URL`](/documentation/Foundation/URL).
- `“.”`, with no attributes.

You can also use custom attributes defined with the [`MarkdownDecodableAttributedStringKey`](/documentation/Foundation/MarkdownDecodableAttributedStringKey) protocol in the Markdown string. To do this, use Apple’s Markdown extension syntax: `^[text](attribute1: value1, attribute2: value2, …)`.

When using attributes beyond those provided by the system, be sure to use initializers that take a `scope` parameter, and provide the scope that defines the custom attributes.

> Tip:
> The ``doc://com.apple.foundation/documentation/Foundation/AttributedString`` initializers that take a `localized` parameter can also use Markdown syntax. These initializers allow you to use Markdown in your app’s strings files.

## Topics

### Initializing from Markdown Strings

[`init(markdown:options:baseURL:)`](/documentation/Foundation/AttributedString/init(markdown:options:baseURL:)-52n3u)

Creates an attributed string from a Markdown-formatted string using the provided options.

[`init(markdown:including:options:baseURL:)`](/documentation/Foundation/AttributedString/init(markdown:including:options:baseURL:)-4m51b)

Creates an attributed string from a Markdown-formatted string using the provided options and attribute scope.

[`init(markdown:including:options:baseURL:)`](/documentation/Foundation/AttributedString/init(markdown:including:options:baseURL:)-89e48)

Creates an attributed string from a Markdown-formatted string using the provided options and attribute scope that a key path identifies.

### Initializing from Markdown Data

[`init(markdown:options:baseURL:)`](/documentation/Foundation/AttributedString/init(markdown:options:baseURL:)-2sg1o)

Creates an attributed string from Markdown-formatted data using the provided options.

[`init(markdown:including:options:baseURL:)`](/documentation/Foundation/AttributedString/init(markdown:including:options:baseURL:)-4co46)

Creates an attributed string from Markdown-formatted data using the provided options and attribute scope.

[`init(markdown:including:options:baseURL:)`](/documentation/Foundation/AttributedString/init(markdown:including:options:baseURL:)-5nap7)

Creates an attributed string from Markdown-formatted data using the provided options and attribute scope that a key path identifies.

### Initializing with Markdown from URL Contents

[`init(contentsOf:options:baseURL:)`](/documentation/Foundation/AttributedString/init(contentsOf:options:baseURL:))

Creates an attributed string from the contents of a specified URL that contains Markdown-formatted data, using the provided options.

[`init(contentsOf:including:options:baseURL:)`](/documentation/Foundation/AttributedString/init(contentsOf:including:options:baseURL:)-1x6fz)

Creates an attributed string from the contents of a specified URL that contains Markdown-formatted data, using the provided options and attribute scope.

[`init(contentsOf:including:options:baseURL:)`](/documentation/Foundation/AttributedString/init(contentsOf:including:options:baseURL:)-1fcpy)

Creates an attributed string from the contents of a specified Markdown URL, using the provided options and attribute scope that a key path identifies.

### Specifying Markdown Parsing Options

[`AttributedString.MarkdownParsingOptions`](/documentation/Foundation/AttributedString/MarkdownParsingOptions)

Options that affect the parsing of Markdown content into an attributed string.



---

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)