How it works
AutomaticGlassBackgroundEffect is the glass background style SwiftUI applies when you ask the system to decide for you, letting the platform choose whether a translucent glass material is drawn behind a view and how prominently it appears. Rather than committing a view to an always-on or always-off glass treatment, the automatic effect defers to the surrounding context — the platform, the ornament or container the view lives in, and the current rendering environment — so the same view reads correctly wherever it's placed. Reach for it when you want a view to participate in the system's glass language without hard-coding a fixed appearance, which keeps the result consistent as Apple tunes the material across releases.
Apply the effect with glassBackgroundEffect(displayMode:)
The effect is attached as a view modifier rather than constructed directly. Calling
.glassBackgroundEffect(displayMode:)on a view places a glass material behind its content; here it wraps theVStackof theImageand twoTextviews so the whole card sits on glass.Select automatic behavior via .automatic
Passing
displayMode: .automaticis what selectsAutomaticGlassBackgroundEffect. The.automaticcase hands the decision back to SwiftUI, which resolves an appropriate glass appearance for the current context instead of forcing it visible or hidden the way an explicit mode would.Pad the content before the glass is drawn
Because the modifier reads the view it's applied to, the glass shape follows that view's bounds. The
.padding(24)placed before.glassBackgroundEffect(displayMode:)insets the content so the glass material extends around it, while the trailing.padding()adds breathing room outside the glass card.Let the effect adapt to its container
The defining trait of the automatic effect is that it adjusts to where the view is hosted — the surrounding
Text("Adapts to its context")names exactly this behavior. The sameglassBackgroundEffect(displayMode: .automatic)call can render differently depending on the platform and the ornament or surface it appears within.
.glassBackgroundEffect(displayMode: .automatic) to .glassBackgroundEffect(displayMode: .always) and compare the card's background — the automatic mode may suppress or soften the glass in contexts where .always keeps it fully drawn.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct AutomaticGlassBackgroundEffectDemo: View {
var body: some View {
VStack(spacing: 8) {
Image(systemName: "sparkles")
.font(.largeTitle)
Text("Glass Card")
.font(.headline)
Text("Adapts to its context")
.font(.caption)
.foregroundStyle(.secondary)
}
.padding(24)
.glassBackgroundEffect(displayMode: .automatic)
.padding()
}
}