<!--
{
  "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/HStack",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI6HStackV"
  },
  "title" : "HStack"
}
-->

# HStack

A view that arranges its subviews in a horizontal line.

```
@frozen nonisolated struct HStack<Content> where Content : View
```

## Overview

Unlike [`LazyHStack`](/documentation/SwiftUI/LazyHStack), which only renders the views when your app needs to
display them onscreen, an `HStack` renders the views all at once, regardless
of whether they are on- or offscreen. Use the regular `HStack` when you have
a small number of subviews or don’t want the delayed rendering behavior
of the “lazy” version.

The following example shows a simple horizontal stack of five text views:

```
var body: some View {
    HStack(
        alignment: .top,
        spacing: 10
    ) {
        ForEach(
            1...5,
            id: \.self
        ) {
            Text("Item \($0)")
        }
    }
}
```

![Five text views, named Item 1 through Item 5, arranged in a](images/com.apple.SwiftUI/SwiftUI-HStack-simple@2x.png)

> Note: If you need a horizontal stack that conforms to the ``doc://com.apple.SwiftUI/documentation/SwiftUI/Layout``
> protocol, like when you want to create a conditional layout using
> ``doc://com.apple.SwiftUI/documentation/SwiftUI/AnyLayout``, use ``doc://com.apple.SwiftUI/documentation/SwiftUI/HStackLayout`` instead.

## Topics

### Creating a stack

[`init(alignment:spacing:content:)`](/documentation/SwiftUI/HStack/init(alignment:spacing:content:))

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



---

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)