---
title: "glassBackgroundEffect(_:displayMode:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/glassbackgroundeffect(_:displaymode:)"
---

# glassBackgroundEffect(_:displayMode:)

Fills the view’s background with a custom glass background effect and container-relative rounded rectangle shape.

## Declaration

```swift
nonisolated func glassBackgroundEffect<S>(_ effect: S, displayMode: GlassBackgroundDisplayMode = .always) -> some View where S : GlassBackgroundEffect

```

## Parameters

- `effect`: A doc://com.apple.SwiftUI/documentation/SwiftUI/GlassBackgroundEffect instance that SwiftUI uses to draw a background of the modified view.
- `displayMode`: When to display the glass background. The default is doc://com.apple.SwiftUI/documentation/SwiftUI/GlassBackgroundDisplayMode/always.

## Return Value

Return Value A view with a glass background.

## Discussion

Discussion Use this modifier to add a glass material that may include thickness, specularity, glass blur, shadows, and other effects. Because of its physical depth, the background influences z-axis layout. For different effect, the background may influences x-axis and y-axis layout. To ensure that the effect renders properly when you add it to a collection of views in a ZStack, add the modifier to the stack rather to one of the views in the stack. This includes when you create an implicit stack with view modifiers like overlay(alignment:content:) or background(alignment:content:). In those cases, you might need to create an explicit ZStack inside the content closure to have a place to add the background modifier. Non closed shapes will be rendered as their convex hull.

## See Also

### Background elements

- [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)
- [alternatingRowBackgrounds(_:)](swiftui/view/alternatingrowbackgrounds(_:).md)
- [listRowBackground(_:)](swiftui/view/listrowbackground(_:).md)
- [scrollContentBackground(_:)](swiftui/view/scrollcontentbackground(_:).md)
- [containerBackground(_:for:)](swiftui/view/containerbackground(_:for:).md)
- [containerBackground(for:alignment:content:)](swiftui/view/containerbackground(for:alignment:content:).md)
- [glassBackgroundEffect(displayMode:)](swiftui/view/glassbackgroundeffect(displaymode:).md)
- [glassBackgroundEffect(in:displayMode:)](swiftui/view/glassbackgroundeffect(in:displaymode:).md)
- [glassBackgroundEffect(_:in:displayMode:)](swiftui/view/glassbackgroundeffect(_:in:displaymode:).md)
- [backgroundExtensionEffect()](swiftui/view/backgroundextensioneffect().md)
- [backgroundExtensionEffect(isEnabled:)](swiftui/view/backgroundextensioneffect(isenabled:).md)
