<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "visionOS: 2.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/glassBackgroundEffect(_:displayMode:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE21glassBackgroundEffect_11displayModeQrqd___AA05Glasse7DisplayH0OtAA0ieF0Rd__lF"
  },
  "title" : "glassBackgroundEffect(_:displayMode:)"
}
-->

# glassBackgroundEffect(_:displayMode:)

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

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

## Parameters

`effect`

A [`GlassBackgroundEffect`](/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
[`GlassBackgroundDisplayMode.always`](/documentation/SwiftUI/GlassBackgroundDisplayMode/always).

## Return Value

A view with a glass background.

## 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`](/documentation/SwiftUI/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:)`](/documentation/SwiftUI/View/overlay(alignment:content:)) or
[`background(alignment:content:)`](/documentation/SwiftUI/View/background(alignment:content:)). In those cases, you might
need to create an explicit [`ZStack`](/documentation/SwiftUI/ZStack) inside the `content` closure
to have a place to add the background modifier.

Non closed shapes will be rendered as their convex hull.

---

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)