<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Layout/depthAlignment(_:content:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI6LayoutPAAE14depthAlignment_7contentQrAA05DepthE0V_qd__yXEtAA4ViewRd__lF"
  },
  "title" : "depthAlignment(_:content:)"
}
-->

# depthAlignment(_:content:)

Creates a layout view with the specified depth alignment.

```
nonisolated func depthAlignment<Content>(_ alignment: DepthAlignment, @ContentBuilder content: () -> Content) -> some View where Content : View
```

## Parameters

`alignment`

A [`DepthAlignment`](/documentation/SwiftUI/DepthAlignment) value to use for aligning layout’s
subviews

## Discussion

Use `depthAlignment(_:content:)` to specify a depth guide for aligning
subviews of this layout.

In the example below, the button to play the robot animation is aligned
to the `.front` of the `HStack`.

```swift
   HStackLayout().depthAlignment(.front) {
       RobotModel()
       Button("Play animation") {
           playRobotAnimation()
       }
       .glassBackgroundEffect()
   }
```

---

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)