<!--
{
  "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/View/badge(_:)-6k2u9",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE5badgeyQrAA4TextVSgF"
  },
  "title" : "badge(_:)"
}
-->

# badge(_:)

Generates a badge for the view from a text view.

```
nonisolated func badge(_ label: Text?) -> some View
```

## Parameters

`label`

An optional `Text` view to display as a badge.
Set the value to `nil` to hide the badge.

## Discussion

Use a badge to convey optional, supplementary information about a
view. Keep the contents of the badge as short as possible. Badges
appear in list rows, tab bars, toolbar items, and menus.

Use this initializer when you want to style a `Text` view for use as a
badge. The following example customizes the badge with the
`Text/monospacedDigit()`, `Text/foregroundColor(_:)`, and
`Text/bold()` modifiers.

```
var body: some View {
    let badgeView = Text("\(recentItems.count)")
        .monospacedDigit()
        .foregroundColor(.red)
        .bold()

    List {
        Text("Recents")
            .badge(badgeView)
        Text("Favorites")
    }
}
```

![A table with two rows, titled Recents and Favorites. The first row](images/com.apple.SwiftUI/View-badge-2@2x.png)

Styling the text view has no effect when the badge appears in
a `TabView`.

---

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)