<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/containerBackground(for:alignment:content:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE19containerBackground3for9alignment7contentQrAA09ContainerE9PlacementV_AA9AlignmentVqd__yXEtAaBRd__lF"
  },
  "title" : "containerBackground(for:alignment:content:)"
}
-->

# containerBackground(for:alignment:content:)

Sets the container background of the enclosing container using a view.

```
nonisolated func containerBackground<V>(for container: ContainerBackgroundPlacement, alignment: Alignment = .center, @ContentBuilder content: () -> V) -> some View where V : View
```

## Parameters

`container`

The container that will use the background.

`alignment`

The alignment that the modifier uses to position the
implicit [`ZStack`](/documentation/SwiftUI/ZStack) that groups the background views. The default is
[`center`](/documentation/SwiftUI/Alignment/center).

`content`

The view to use as the background of the container.

## Discussion

The following example uses a custom [`View`](/documentation/SwiftUI/View) as a background:

```
struct ContentView: View {
    var body: some View {
        NavigationStack {
            List {
                NavigationLink("Image") {
                    Text("Image")
                    .containerBackground(for: .navigation) {
                        Image(name: "ImageAsset")
                    }
                }
            }
        }
    }
}
```

The `.containerBackground(for:alignment:content:)` modifier differs from
the [`background(_:ignoresSafeAreaEdges:)`](/documentation/SwiftUI/View/background(_:ignoresSafeAreaEdges:)) modifier by
automatically filling an entire parent container.
[`ContainerBackgroundPlacement`](/documentation/SwiftUI/ContainerBackgroundPlacement) describes the available containers.

---

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)