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

# depthAlignment(_:)

Sets the depth alignment for this layout.

```
func depthAlignment(_ alignment: DepthAlignment) -> some Layout
```

## Parameters

`alignment`

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

## Discussion

Use `depthAlignment(_:)` 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
   let depthStack = HStackLayout().depthAlignment(.front)
   depthStack {
       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)