<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/luminanceToAlpha()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE16luminanceToAlphaQryF"
  },
  "title" : "luminanceToAlpha()"
}
-->

# luminanceToAlpha()

Adds a luminance to alpha effect to this view.

```
nonisolated func luminanceToAlpha() -> some View
```

## Return Value

A view with the luminance to alpha effect applied.

## Discussion

Use this modifier to create a semitransparent mask, with the opacity of
each part of the modified view controlled by the luminance of the
corresponding part of the original view. Regions of lower luminance
become more transparent, while higher luminance yields greater
opacity.

In particular, the modifier maps the red, green, and blue components of
each input pixel’s color to a grayscale value, and that value becomes
the alpha component of a black pixel in the output. This modifier
produces an effect that’s equivalent to using the `feColorMatrix`
filter primitive with the `luminanceToAlpha` type attribute, as defined
by the [Scalable Vector Graphics (SVG) 2](https://www.w3.org/TR/SVG2/)
specification.

The example below defines a `Palette` view as a series of rectangles,
each composed as a [`Color`](/documentation/SwiftUI/Color) with a particular white value,
and then displays two versions of the palette over a blue background:

```
struct Palette: View {
    var body: some View {
        HStack(spacing: 0) {
            ForEach(0..<10) { index in
                Color(white: Double(index) / Double(9))
                    .frame(width: 20, height: 40)
            }
        }
    }
}

struct LuminanceToAlphaExample: View {
    var body: some View {
        VStack(spacing: 20) {
            Palette()

            Palette()
                .luminanceToAlpha()
        }
        .padding()
        .background(.blue)
    }
}
```

The unmodified version of the palette contains rectangles that range
from solid black to solid white, thus with increasing luminance. The
second version of the palette, which has the `luminanceToAlpha()`
modifier applied, allows the background to show through in an amount
that corresponds inversely to the luminance of the input.

![A screenshot of a blue background with two wide rectangles on it,](images/com.apple.SwiftUI/View-luminanceToAlpha-1-iOS@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)