<!--
{
  "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/AttributeScopes/SwiftUIAttributes/BackgroundColorAttribute",
  "metadataVersion" : "0.1.0",
  "role" : "Enumeration",
  "symbol" : {
    "kind" : "Enumeration",
    "modules" : [
      "Foundation",
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:10Foundation15AttributeScopesO7SwiftUIE0D12UIAttributesV015BackgroundColorB0O"
  },
  "title" : "AttributeScopes.SwiftUIAttributes.BackgroundColorAttribute"
}
-->

# AttributeScopes.SwiftUIAttributes.BackgroundColorAttribute

A key for the color that fills the area behind a run of attributed text.

```
@frozen enum BackgroundColorAttribute
```

## Overview

Set this key to highlight part of a string, such as the way a search
result marks the term someone typed:

```
var line = AttributedString("No matches for swift")
if let match = line.range(of: "swift") {
    line[match].backgroundColor = .yellow
}

Text(line)
```

## Relationships

### Conforms To

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

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

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

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

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

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

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

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

---

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)