<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/HStackLayout/init(alignment:spacing:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI12HStackLayoutV9alignment7spacingAcA17VerticalAlignmentV_14CoreFoundation7CGFloatVSgtcfc"
  },
  "title" : "init(alignment:spacing:)"
}
-->

# init(alignment:spacing:)

Creates a horizontal stack with the specified spacing and vertical
alignment.

```
init(alignment: VerticalAlignment = .center, spacing: CGFloat? = nil)
```

## Parameters

`alignment`

The guide for aligning the subviews in this stack. It
has the same vertical screen coordinate for all subviews.

`spacing`

The distance between adjacent subviews. Set this value
to `nil` to use default distances between subviews.

---

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)