glassEffect

Applies a glass effect to this view.

View ModifieriOS 26.0+macOS 26.0+tvOS 26.0+watchOS 26.0+glassEffect(_:in:) in SwiftUI

Declaration

React
compose().glassEffect(
  glass?: SwiftUI.Glass,
  options?: {
    in?: SwiftUI.Shape;
  }
)
Swift
nonisolated func glassEffect(
    _ glass: Glass = .regular,
    in shape: some Shape = DefaultGlassEffectShape()
) -> some View

Parameters

Discussion

When you use a glass effect, the platform:

  • Renders a shape anchored behind this view filled with the physical glass material
  • Applies the foreground effects of the glass over this view.

For example, you could add a glass effect to a Label:

Label("Flag", systemImage: "flag.fill")
    .padding()
    .glassEffect()

SwiftUI uses the Glass.regular variant by default along with a Capsule shape.

SwiftUI anchors the glass to the view's bounds. For the example above, the physical glass material fills the entirety of the label's frame, which includes the padding.

You typically use this modifier with a GlassEffectContainer to combine multiple glass shapes into a single shape that can morph shapes into one another.

See also

More in Visual effects.