<!--
{
  "documentType" : "article",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/html-attributes",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "HTML attributes"
}
-->

# HTML attributes

Documentwide attributes that provide control over the form of generated HTML.

## Discussion

You use these attributes only for writing HTML. [`excludedElements`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/excludedElements) allows control over the tags used. The recognized values in the [`excludedElements`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/excludedElements) array are (case-insensitive) HTML tags, plus DOCTYPE (representing a doctype declaration) and XML (representing an XML declaration). By default, if this attribute is not present, the excluded elements will be those deprecated in HTML 4 (APPLET, BASEFONT, CENTER, DIR, FONT, ISINDEX, MENU, S, STRIKE, and U) plus XML. If XML is on the list, HTML forms are used; if XML is not on the list, XHTML forms are used where there is a distinction. Either [`characterEncoding`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/characterEncoding) or [`textEncodingName`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/textEncodingName) may be used to control the encoding used for generated HTML; character entities are used for characters not representable in the specified encoding. [`prefixSpaces`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/prefixSpaces) allows some control over formatting.

## Topics

### Getting the attributes

[`static let excludedElements: NSAttributedString.DocumentAttributeKey`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/excludedElements)

The HTML elements to exclude in generated HTML.

[`static let textEncodingName: NSAttributedString.DocumentAttributeKey`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/textEncodingName)

The name of the text encoding to use.

[`static let prefixSpaces: NSAttributedString.DocumentAttributeKey`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/prefixSpaces)

The number of spaces for indenting nested HTML elements.



---

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)