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

# badge(_:)

Generates a badge for the view from a string.

```
nonisolated func badge<S>(_ label: S?) -> some View where S : StringProtocol
```

## Parameters

`label`

An optional string 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.

This modifier creates a `Text` view on your behalf, and treats the
localized key similar to `Text/init(_:)-9d1g4`. The following
example shows a list with a “Default” badge on one of its rows.

```
NavigationView {
    List(servers) { server in
        Text(server.name)
            .badge(server.defaultString())
    }
    .navigationTitle("Servers")
}
```

![A table with the navigation title Servers and four rows: North 1,](images/com.apple.SwiftUI/View-badge-3@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)