0Pricing
SwiftUI Academy · Lesson

Stacking Views Vertically

Group views top to bottom with VStack.

Stacking Views Vertically is a free SwiftUI Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the SwiftUI Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why You Need Stacks

A SwiftUI body can return only one view. To show several views together, you wrap them in a container that arranges them for you. 📦

Meet VStack

A VStack stacks its child views vertically, top to bottom. It is your go-to container for column-style layouts like a title above a subtitle.

Your First VStack

Place views inside the VStack braces and they appear in order, each on its own line. The first child sits at the top.

VStack {
    Text("Hello")
    Text("World")
}

Order Matters

Children render in the exact order you write them. Swap two lines of code and the views swap places on screen. Top of the code is top of the column.

Centered by Default

By default a VStack centers its children horizontally and shrinks to fit its content, like a tidy little column hugging its views.

Mixing View Types

A VStack does not care what kind of views it holds. You can freely mix a Text, an Image, and a Button in the same vertical stack.

VStack {
    Image(systemName: "star")
    Text("Favorite")
}

How Many Views Fit?

A stack can hold up to ten direct children at once. That is plenty for most screens, and you can always nest stacks for more.

Nesting Stacks

You can put a VStack inside another VStack to build richer layouts. Nesting lets you group related views so they move together.

VStack {
    Text("Title")
    VStack {
        Text("Line 1")
        Text("Line 2")
    }
}

Stacks Are Views Too

A VStack is itself a view, so you can apply modifiers like padding or background to the whole stack at once. The group acts as one unit.

Returning a VStack from body

Since body needs a single view, returning a VStack is the classic way to show many views. The stack becomes that one returned view.

var body: some View {
    VStack {
        Text("One")
        Text("Two")
    }
}

When to Reach for VStack

Use a VStack whenever items should read top to bottom: a heading over body text, a label over a value, or a form laid out in rows.

Quick Check

Let's make sure VStack ordering is clear.

Recap: Vertical Stacking

Nice work! A VStack arranges views top to bottom in code order, centers them by default, and acts as one view you can style or nest. 🎉

Frequently asked questions

Is the “Stacking Views Vertically” lesson free?

Yes — the full text of “Stacking Views Vertically” is free to read here on the web, and the SwiftUI Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the SwiftUI Academy course, upgrade to CoddyKit PRO.

What will I learn in “Stacking Views Vertically”?

Group views top to bottom with VStack. You practise SwiftUI Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start SwiftUI Academy?

No prior experience is required. SwiftUI Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Stacking Views Vertically” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this SwiftUI Academy lesson?

Yes. Every SwiftUI Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Stacking Views Vertically
  2. Rows with HStack
  3. Layering with ZStack
  4. Spacing & Alignment in Stacks
← Back to SwiftUI Academy