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

# badge(_:)

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

```
@export(implementation) nonisolated func badge(_ resource: LocalizedStringResource) -> some TabContent<Self.TabValue>
```

## Parameters

`resource`

A string resource to display as a badge.

## Discussion

Use a badge to convey optional, supplementary information about a
view. Keep the contents of the badge as short as possible. The string
provided will appear as an indicator on the given tab.

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 tab that has a “New Alerts” badge
when there are new alerts.

```
var body: some View {
    TabView {
        Tab("Home", systemImage: "house") {
            HomeView()
        }
        Tab("Alerts", systemImage: "bell") {
            AlertsView()
        }
        .badge("New Alerts")
    }
}
```

---

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)