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

# EncodableAttributedStringKey

A protocol that defines how an attribute key encodes its value.

```
protocol EncodableAttributedStringKey : AttributedStringKey
```

## Overview

Implement this protocol to make an attribute encodable. Encoding an [`AttributedString`](/documentation/Foundation/AttributedString) or [`AttributeContainer`](/documentation/Foundation/AttributeContainer) drops any attributes whose types don’t conform to this protocol.

## Topics

### Encoding Values

[`static func encode(Self.Value, to: any Encoder) throws`](/documentation/Foundation/EncodableAttributedStringKey/encode(_:to:))

Encodes a value to the provided encoder.

## Relationships

### Conforming Types

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

### Inherits From

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

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

---

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)