<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/ShapeStyle/selection",
  "metadataVersion" : "0.1.0",
  "role" : "Type Property",
  "symbol" : {
    "kind" : "Type Property",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI10ShapeStylePA2A09SelectioncD0VRszrlE9selectionAEvpZ"
  },
  "title" : "selection"
}
-->

# selection

A style used to visually indicate selection following platform conventional
colors and behaviors.

```
@export(implementation) static var selection: SelectionShapeStyle { get }
```

## Discussion

For example:

```
ForEach(items) {
   ItemView(value: item, isSelected: item.id == selectedID)
}

struct ItemView {
    var value: item
    var isSelected: Bool

    var body: some View {
        // construct the actual cell content
            .background(isSelected
                ? AnyShapeStyle(.selection)
                    : AnyShapeStyle(.fill.quaternary),
                in: .rect(cornerRadius: 6))
    }
}
```

On macOS and iPadOS this automatically reflects window key state and focus
state, where the emphasized appearance will be used only when the window is
key and the nearest focusable element is actually focused. On iPhone, this
will always fill with the environment’s accent color.

When applied as a background of another view, it will automatically
set the `EnvironmentValues.backgroundProminence` for the environment
of that view to match the current prominence of the selection.

For information about how to use shape styles, see [`ShapeStyle`](/documentation/SwiftUI/ShapeStyle).

---

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)