<!--
{
  "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" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/ButtonStyleConfiguration/role",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI24ButtonStyleConfigurationV4roleAA0C4RoleVSgvp"
  },
  "title" : "role"
}
-->

# role

An optional semantic role that describes the button’s purpose.

```
let role: ButtonRole?
```

## Discussion

A value of `nil` means that the Button doesn’t have an assigned role. If
the button does have a role, use it to make adjustments to the button’s
appearance. The following example shows a custom style that uses
bold text when the role is [`cancel`](/documentation/SwiftUI/ButtonRole/cancel),
[`red`](/documentation/SwiftUI/ShapeStyle/red) text when the role is [`destructive`](/documentation/SwiftUI/ButtonRole/destructive),
and adds no special styling otherwise:

```
struct MyButtonStyle: ButtonStyle {
    func makeBody(configuration: Configuration) -> some View {
        configuration.label
            .font(
                configuration.role == .cancel ? .title2.bold() : .title2)
            .foregroundColor(
                configuration.role == .destructive ? Color.red : nil)
    }
}
```

You can create one of each button using this style to see the effect:

```
VStack(spacing: 20) {
    Button("Cancel", role: .cancel) {}
    Button("Delete", role: .destructive) {}
    Button("Continue") {}
}
.buttonStyle(MyButtonStyle())
```

![A screenshot of three buttons stacked vertically. The first says](images/com.apple.SwiftUI/ButtonStyleConfiguration-role-1@2x.png)

---

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)