<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/mask(alignment:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE4mask9alignment_QrAA9AlignmentV_qd__yXEtAaBRd__lF"
  },
  "title" : "mask(alignment:_:)"
}
-->

# mask(alignment:_:)

Masks this view using the alpha channel of the given view.

```
nonisolated func mask<Mask>(alignment: Alignment = .center, @ContentBuilder _ mask: () -> Mask) -> some View where Mask : View
```

## Parameters

`alignment`

The alignment for `mask` in relation to this view.

`mask`

The view whose alpha the rendering system applies to
the specified view.

## Discussion

Use `mask(_:)` when you want to apply the alpha (opacity) value of
another view to the current view.

This example shows an image masked by rectangle with a 10% opacity:

```
Image(systemName: "envelope.badge.fill")
    .foregroundColor(Color.blue)
    .font(.system(size: 128, weight: .regular))
    .mask {
        Rectangle().opacity(0.1)
    }
```

![A screenshot of a view masked by a rectangle with 10%](images/com.apple.SwiftUI/SwiftUI-View-mask@2x.png)

---

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)