<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/badge(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE5badgeyQr10Foundation23LocalizedStringResourceVSgF::OverloadGroup"
  },
  "title" : "badge(_:)"
}
-->

# badge(_:)

Generates a badge for the view from a localized string resource.

```
@export(implementation) nonisolated func badge(_ resource: LocalizedStringResource?) -> some View
```

## Parameters

`resource`

An optional string resource 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`](/documentation/SwiftUI/Text) view on your behalf. For
more information about localizing strings, see [`Text`](/documentation/SwiftUI/Text). 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.isDefault ? "Default" : nil)
    }
    .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)