<!--
{
  "availability" : [
    "macOS: 10.0.0 -",
    "swift: -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSAttributedString/init(HTML:documentAttributes:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSAttributedString(im)initWithHTML:documentAttributes:"
  },
  "title" : "init(HTML:documentAttributes:)"
}
-->

# init(HTML:documentAttributes:)

Creates an attributed string from the HTML in the specified data object.

```
init?(HTML data: Data, documentAttributes dict: AutoreleasingUnsafeMutablePointer<NSDictionary?>?)
```

## Parameters

`data`

A data object with text in HTML format. The method uses this data to create the attributed string.

`dict`

An in-out dictionary containing document-level attributes. On output, this method updates the dictionary to contain any document-specific keys found in the data. Specify `nil` if you don’t want the document attributes

## Return Value

Returns an initialized object, or `nil` if the data can’t be decoded.

## Discussion

---

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)