<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Preview(_:immersionStyle:traits:body:)",
  "metadataVersion" : "0.1.0",
  "role" : "Macro",
  "symbol" : {
    "kind" : "Macro",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI7Preview_14immersionStyle6traits4bodyySSSg_x21DeveloperToolsSupport0C5TraitVyAgBV10ViewTraitsOGdAA0L0_pyScMYcctcAA09ImmersionE0Rzlufm"
  },
  "title" : "Preview(_:immersionStyle:traits:body:)"
}
-->

# Preview(_:immersionStyle:traits:body:)

Creates a preview of a SwiftUI view in an immersive space.

```
@freestanding(declaration) macro Preview<Style>(_ name: String? = nil, immersionStyle: Style, traits: PreviewTrait<Preview.ViewTraits>..., @ContentBuilder body: @escaping @MainActor () -> any View) where Style : ImmersionStyle
```

## Parameters

`name`

An optional display name for the preview. If you don’t specify a
name, the canvas labels the preview using the line number where the
preview appears in source.

`immersionStyle`

The [`ImmersionStyle`](/documentation/SwiftUI/ImmersionStyle) to use for the preview. Use this
input to display the view as if it appears in an immersive space
that has the specified style.

`traits`

An optional list of
<doc://com.apple.documentation/documentation/DeveloperToolsSupport/PreviewTrait>
instances that customize the appearance of the preview.

`body`

A [`ContentBuilder`](/documentation/SwiftUI/ContentBuilder) that produces a SwiftUI view to preview. You
typically specify one of your app’s custom views and optionally any
inputs, model data, modifiers, and enclosing views that the custom
view needs for normal operation.

## Overview

This preview macro behaves like [`Preview(_:traits:_:body:)`](/documentation/SwiftUI/Preview(_:traits:_:body:)), except
that it also enables you to define a scene context for the view.
Specifically, it places the view in an immersive space with the
specified immersion style, like the [`mixed`](/documentation/SwiftUI/ImmersionStyle/mixed) style:

```
#Preview("Mixed immersive space", immersionStyle: .mixed) {
   ContentView()
}
```

Use this preview macro when the view needs scene context to
behave as it would during normal operation of your app.

Other preview macros provide different customization options. For example,
if you want to see how the view appears in a window rather than an immersive
space, you can use [`Preview(_:windowStyle:traits:body:)`](/documentation/SwiftUI/Preview(_:windowStyle:traits:body:)). If you want to
add custom, fixed viewpoints to an immersive space preview, use
[`Preview(_:immersionStyle:traits:body:cameras:)`](/documentation/SwiftUI/Preview(_:immersionStyle:traits:body:cameras:)).

---

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)