SwiftUI HStack
Published Oct 10, 2022
Contribute to Docs
The HStack view is a layout container where elements, or subviews, are arranged in a horizontal line (left-to-right).
Syntax
var body: some View {
HStack {
Subviews here
}
}
The HStack view rests within the body of a View.
Example
In the example below, two Text subviews are nested in the HStack:
var body: some View {HStack {Text("Subview 1")Text("Subview 2")}}
This will display the following:

Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn SwiftUI on Codecademy
- Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.
- Includes 7 Courses
- With Certificate
- Beginner Friendly.13 hours
- A powerful programming language developed by Apple for iOS, macOS, and more.
- Beginner Friendly.12 hours