<!--
{
  "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" : "Foundation",
  "identifier" : "/documentation/Foundation/AttributedStringKey",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation19AttributedStringKeyP"
  },
  "title" : "AttributedStringKey"
}
-->

# AttributedStringKey

A type that defines an attribute’s name and type.

```
protocol AttributedStringKey : SendableMetatype
```

## Overview

You don’t instantiate types that conform to this protocol. Rather, dynamic member lookup uses this type as the basis for looking up key paths on [`AttributedString`](/documentation/Foundation/AttributedString) subtypes when using an [`AttributeScope`](/documentation/Foundation/AttributeScope) type parameter. When it also conforms to [`CodableAttributedStringKey`](/documentation/Foundation/CodableAttributedStringKey), (or [`DecodableAttributedStringKey`](/documentation/Foundation/DecodableAttributedStringKey)/[`EncodableAttributedStringKey`](/documentation/Foundation/EncodableAttributedStringKey) if the type isn’t fully codable), the [`AttributedStringKey`](/documentation/Foundation/AttributedStringKey) describes which attributes of an [`AttributedString`](/documentation/Foundation/AttributedString) support encoding or decoding.

Attribute owners — typically frameworks — declare a key like the following:

```swift
enum OutlineColorAttribute : AttributedStringKey {
    typealias Value = Color
    static let name = "OutlineColor"
}
```

Callers can use these types to get attribute values from attributed strings, but typically you want to reference them by name. Attribute owners enable this by creating one or more structures that conform to [`AttributeScope`](/documentation/Foundation/AttributeScope), in which they provide short names for their attributes that map to the [`AttributedStringKey`](/documentation/Foundation/AttributedStringKey) type. The following example shows how to do this:

```swift
struct MyTextStyleAttributes : AttributeScope {
    let outlineColor : OutlineColorAttribute // OutlineColorAttribute.Value == Color
    let shadowColor : ShadowColorAttribute // ShadowColorAttribute.Value == Color
    // etc.
}
```

After you extend [`AttributeScope`](/documentation/Foundation/AttributeScope) like this, extend [`AttributeDynamicLookup`](/documentation/Foundation/AttributeDynamicLookup) to allow callers to use dynamic member lookup syntax, like `myAttributedString.outlineColor = .red`.

## Topics

### Delcaring Key Properties

[`static var name: String`](/documentation/Foundation/AttributedStringKey/name)

The name of the key.

[`associatedtype Value : Hashable`](/documentation/Foundation/AttributedStringKey/Value)

The type of the key’s value.

### Describing the Key

[`var description: String`](/documentation/Foundation/AttributedStringKey/description)

### Type Properties

[`static var inheritedByAddedText: Bool`](/documentation/Foundation/AttributedStringKey/inheritedByAddedText)

[`static var invalidationConditions: Set<AttributedString.AttributeInvalidationCondition>?`](/documentation/Foundation/AttributedStringKey/invalidationConditions)

[`static var runBoundaries: AttributedString.AttributeRunBoundaries?`](/documentation/Foundation/AttributedStringKey/runBoundaries)

## Relationships

### Conforming Types

[`ByteCountAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/ByteCountAttribute)

[`UnderlineStyleAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/UnderlineStyleAttribute)

[`ExpansionAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/ExpansionAttribute)

[`IPANotationAttribute`](/documentation/Foundation/AttributeScopes/AccessibilityAttributes/IPANotationAttribute)

[`AttachmentAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/AttachmentAttribute)

[`MarkdownSourcePositionAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/MarkdownSourcePositionAttribute)

[`ObliquenessAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/ObliquenessAttribute)

[`TextAlternativesAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/TextAlternativesAttribute)

[`KernAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/KernAttribute)

[`ForegroundColorAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/ForegroundColorAttribute)

[`UnderlineStyleAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/UnderlineStyleAttribute)

[`StrokeColorAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/StrokeColorAttribute)

[`ReplacementIndexAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/ReplacementIndexAttribute)

[`WritingDirectionAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/WritingDirectionAttribute)

[`LineHeightAttribute`](/documentation/Foundation/AttributeScopes/CoreTextAttributes/LineHeightAttribute)

[`GlyphInfoAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/GlyphInfoAttribute)

[`ParagraphStyleAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/ParagraphStyleAttribute)

[`SuperscriptAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/SuperscriptAttribute)

[`TextEffectAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/TextEffectAttribute)

[`BaselineOffsetAttribute`](/documentation/Foundation/AttributeScopes/SwiftUIAttributes/BaselineOffsetAttribute)

[`MeasurementAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/MeasurementAttribute)

[`IncludesPunctuationAttribute`](/documentation/Foundation/AttributeScopes/AccessibilityAttributes/IncludesPunctuationAttribute)

[`MarkedClauseSegmentAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/MarkedClauseSegmentAttribute)

[`NumberPartAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/NumberFormatAttributes/NumberPartAttribute)

[`ToolTipAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/ToolTipAttribute)

[`UnderlineColorAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/UnderlineColorAttribute)

[`LocalizedNumberFormatAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/LocalizedNumberFormatAttribute)

[`TextualContextAttribute`](/documentation/Foundation/AttributeScopes/AccessibilityAttributes/TextualContextAttribute)

[`ExpansionAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/ExpansionAttribute)

[`AgreementConceptAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/AgreementConceptAttribute)

[`AdaptiveImageGlyphAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/AdaptiveImageGlyphAttribute)

[`InflectionAlternativeAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/InflectionAlternativeAttribute)

[`StrokeColorAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/StrokeColorAttribute)

[`FontAttribute`](/documentation/Foundation/AttributeScopes/SwiftUIAttributes/FontAttribute)

[`TrackingAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/TrackingAttribute)

[`ShadowAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/ShadowAttribute)

[`LocalizedNumericArgumentAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/LocalizedStringArgumentAttributes-swift.struct/LocalizedNumericArgumentAttribute)

[`MorphologyAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/MorphologyAttribute)

[`ForegroundColorAttribute`](/documentation/Foundation/AttributeScopes/SwiftUIAttributes/ForegroundColorAttribute)

[`LocalizedURLArgumentAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/LocalizedStringArgumentAttributes-swift.struct/LocalizedURLArgumentAttribute)

[`SymbolAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/NumberFormatAttributes/SymbolAttribute)

[`HeadingLevelAttribute`](/documentation/Foundation/AttributeScopes/AccessibilityAttributes/HeadingLevelAttribute)

[`AdaptiveImageGlyphAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/AdaptiveImageGlyphAttribute)

[`BackgroundColorAttribute`](/documentation/Foundation/AttributeScopes/SwiftUIAttributes/BackgroundColorAttribute)

[`TimeRangeAttribute`](/documentation/Foundation/AttributeScopes/SpeechAttributes/TimeRangeAttribute)

[`AnnouncementPriorityAttribute`](/documentation/Foundation/AttributeScopes/AccessibilityAttributes/AnnouncementPriorityAttribute)

[`SpeechSSMLAttribute`](/documentation/Foundation/AttributeScopes/AccessibilityAttributes/SpeechSSMLAttribute)

[`BaselineOffsetAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/BaselineOffsetAttribute)

[`SkipTranslationAttribute`](/documentation/Foundation/AttributeScopes/TranslationAttributes/SkipTranslationAttribute)

[`StrikethroughStyleAttribute`](/documentation/Foundation/AttributeScopes/SwiftUIAttributes/StrikethroughStyleAttribute)

[`ListItemDelimiterAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/ListItemDelimiterAttribute)

[`AgreementArgumentAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/AgreementArgumentAttribute)

[`ReferentConceptAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/ReferentConceptAttribute)

[`PersonNameComponentAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/PersonNameComponentAttribute)

[`TextItemTagAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/TextItemTagAttribute)

[`StrikethroughStyleAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/StrikethroughStyleAttribute)

[`UnderlineStyleAttribute`](/documentation/Foundation/AttributeScopes/SwiftUIAttributes/UnderlineStyleAttribute)

[`AttachmentAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/AttachmentAttribute)

[`StrokeWidthAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/StrokeWidthAttribute)

[`UnderlineColorAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/UnderlineColorAttribute)

[`PresentationIntentAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/PresentationIntentAttribute)

[`LigatureAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/LigatureAttribute)

[`TextEffectAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/TextEffectAttribute)

[`TrackingAttribute`](/documentation/Foundation/AttributeScopes/SwiftUIAttributes/TrackingAttribute)

[`ImageURLAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/ImageURLAttribute)

[`BackgroundColorAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/BackgroundColorAttribute)

[`InflectionRuleAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/InflectionRuleAttribute)

[`ShadowAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/ShadowAttribute)

[`KernAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/KernAttribute)

[`ParagraphStyleAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/ParagraphStyleAttribute)

[`InlinePresentationIntentAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/InlinePresentationIntentAttribute)

[`LinkAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/LinkAttribute)

[`DurationFieldAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/DurationFieldAttribute)

[`AlternateDescriptionAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/AlternateDescriptionAttribute)

[`FontAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/FontAttribute)

[`KerningAttribute`](/documentation/Foundation/AttributeScopes/SwiftUIAttributes/KerningAttribute)

[`ConfidenceAttribute`](/documentation/Foundation/AttributeScopes/SpeechAttributes/ConfidenceAttribute)

[`StrikethroughStyleAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/StrikethroughStyleAttribute)

[`FontAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/FontAttribute)

[`SpellOutAttribute`](/documentation/Foundation/AttributeScopes/AccessibilityAttributes/SpellOutAttribute)

[`StrikethroughColorAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/StrikethroughColorAttribute)

[`LocalizedDateArgumentAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/LocalizedStringArgumentAttributes-swift.struct/LocalizedDateArgumentAttribute)

[`TextAlignmentAttribute`](/documentation/Foundation/AttributeScopes/CoreTextAttributes/TextAlignmentAttribute)

[`LigatureAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/LigatureAttribute)

[`BaselineOffsetAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/BaselineOffsetAttribute)

[`BackgroundColorAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/BackgroundColorAttribute)

[`AdjustedPitchAttribute`](/documentation/Foundation/AttributeScopes/AccessibilityAttributes/AdjustedPitchAttribute)

[`ObliquenessAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/ObliquenessAttribute)

[`LocalizedDateIntervalArgumentAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/LocalizedStringArgumentAttributes-swift.struct/LocalizedDateIntervalArgumentAttribute)

[`LanguageIdentifierAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/LanguageIdentifierAttribute)

[`StrikethroughColorAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/StrikethroughColorAttribute)

[`CursorAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/CursorAttribute)

[`AdaptiveImageGlyphAttribute`](/documentation/Foundation/AttributeScopes/SwiftUIAttributes/AdaptiveImageGlyphAttribute)

[`QueueAnnouncementAttribute`](/documentation/Foundation/AttributeScopes/AccessibilityAttributes/QueueAnnouncementAttribute)

[`TextCustomAttribute`](/documentation/Foundation/AttributeScopes/AccessibilityAttributes/TextCustomAttribute)

[`StrokeWidthAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/StrokeWidthAttribute)

[`ForegroundColorAttribute`](/documentation/Foundation/AttributeScopes/AppKitAttributes/ForegroundColorAttribute)

[`TrackingAttribute`](/documentation/Foundation/AttributeScopes/UIKitAttributes/TrackingAttribute)

[`DateFieldAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute)

### Inherits From

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

### Inherited By

[`EncodableAttributedStringKey`](/documentation/Foundation/EncodableAttributedStringKey)

[`MarkdownDecodableAttributedStringKey`](/documentation/Foundation/MarkdownDecodableAttributedStringKey)

[`ObjectiveCConvertibleAttributedStringKey`](/documentation/Foundation/ObjectiveCConvertibleAttributedStringKey)

[`DecodableAttributedStringKey`](/documentation/Foundation/DecodableAttributedStringKey)

---

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)