---
title: "containerBackground(for:alignment:content:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/containerbackground(for:alignment:content:)"
---

# containerBackground(for:alignment:content:)

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

## Declaration

```swift
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 doc://com.apple.SwiftUI/documentation/SwiftUI/ZStack that groups the background views. The default is doc://com.apple.SwiftUI/documentation/SwiftUI/Alignment/center.
- `content`: The view to use as the background of the container.

## Discussion

Discussion The following example uses a custom 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:) modifier by automatically filling an entire parent container. ContainerBackgroundPlacement describes the available containers.

## See Also

### Layering views

- [Adding a background to your view](swiftui/adding-a-background-to-your-view.md)
- [ZStack](swiftui/zstack.md)
- [zIndex(_:)](swiftui/view/zindex(_:).md)
- [background(alignment:content:)](swiftui/view/background(alignment:content:).md)
- [background(_:ignoresSafeAreaEdges:)](swiftui/view/background(_:ignoressafeareaedges:).md)
- [background(ignoresSafeAreaEdges:)](swiftui/view/background(ignoressafeareaedges:).md)
- [background(_:in:fillStyle:)](swiftui/view/background(_:in:fillstyle:).md)
- [background(in:fillStyle:)](swiftui/view/background(in:fillstyle:).md)
- [overlay(alignment:content:)](swiftui/view/overlay(alignment:content:).md)
- [overlay(_:ignoresSafeAreaEdges:)](swiftui/view/overlay(_:ignoressafeareaedges:).md)
- [overlay(_:in:fillStyle:)](swiftui/view/overlay(_:in:fillstyle:).md)
- [backgroundMaterial](swiftui/environmentvalues/backgroundmaterial.md)
- [containerBackground(_:for:)](swiftui/view/containerbackground(_:for:).md)
- [ContainerBackgroundPlacement](swiftui/containerbackgroundplacement.md)
