<!--
{
  "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:)-5ybst",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE17toolbarBackground_3forQrqd___AA16ToolbarPlacementVdtAA10ShapeStyleRd__lF"
  },
  "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
`ToolbarPlacement/automatic` if empty.

## Discussion

The preferred style flows up to the nearest container that
renders a bar. This could be a `NavigationView` or `TabView`
in iOS, or the root view of a `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` 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`, the specified style will be
preferred while the tab is currently active. You can use a `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)