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

# toolbarBackground(_:for:)

Specifies the preferred shape style of the background of a bar managed
by SwiftUI.

```
nonisolated func toolbarBackground<S>(_ style: S, for bars: ToolbarPlacement...) -> some View where S : ShapeStyle
```

## Parameters

`style`

The style to display as the background of the bar.

`bars`

The bars to use the style for or
[`automatic`](/documentation/SwiftUI/ToolbarPlacement/automatic) if empty.

## Discussion

The preferred style flows up to the nearest container that
renders a bar. This could be a [`NavigationView`](/documentation/SwiftUI/NavigationView) or [`TabView`](/documentation/SwiftUI/TabView)
in iOS, or the root view of a [`WindowGroup`](/documentation/SwiftUI/WindowGroup) in macOS. This example
shows a view that renders the navigation bar with a blue background
and dark color scheme.

```
NavigationView {
    ContentView()
        .toolbarBackground(.white)
        .toolbarColorScheme(.dark)
}
```

You can provide multiple [`ToolbarPlacement`](/documentation/SwiftUI/ToolbarPlacement) instances to customize
multiple bars at once.

```
TabView {
    NavigationView {
        ContentView()
            .toolbarBackground(
                .blue, for: .navigationBar, .tabBar)
            .toolbarColorScheme(
                .dark, for: .navigationBar, .tabBar)
    }
}
```

When used within a [`TabView`](/documentation/SwiftUI/TabView), the specified style will be
preferred while the tab is currently active. You can use a [`Group`](/documentation/SwiftUI/Group)
to specify the same preferred background for every tab.

```
TabView {
    Group {
        MainView()
        SettingsView()
    }
    .toolbarBackground(.blue, for: .tabBar)
}
```

Depending on the specified bars, the requested style may not be able to
be fullfilled.

---

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)