<!--
{
  "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/opacity(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE7opacityyQrSdF"
  },
  "title" : "opacity(_:)"
}
-->

# opacity(_:)

Sets the transparency of this view.

```
nonisolated func opacity(_ opacity: Double) -> some View
```

## Parameters

`opacity`

A value between 0 (fully transparent) and 1 (fully
opaque).

## Return Value

A view that sets the transparency of this view.

## Discussion

Apply opacity to reveal views that are behind another view or to
de-emphasize a view.

When applying the `opacity(_:)` modifier to a view that has already had
its opacity transformed, the modifier multiplies the effect of the
underlying opacity transformation.

The example below shows yellow and red rectangles configured to overlap.
The top yellow rectangle has its opacity set to 50%, allowing the
occluded portion of the bottom rectangle to be visible:

```
struct Opacity: View {
    var body: some View {
        VStack {
            Color.yellow.frame(width: 100, height: 100, alignment: .center)
                .zIndex(1)
                .opacity(0.5)

            Color.red.frame(width: 100, height: 100, alignment: .center)
                .padding(-40)
        }
    }
}
```

![Two overlaid rectangles, where the topmost has its opacity set to 50%,](images/com.apple.SwiftUI/SwiftUI-View-opacity@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)