<!--
{
  "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/GridRow/init(alignment:content:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI7GridRowV9alignment7contentACyxGAA17VerticalAlignmentVSg_xyXEtcfc"
  },
  "title" : "init(alignment:content:)"
}
-->

# init(alignment:content:)

Creates a horizontal row of child views in a grid.

```
nonisolated init(alignment: VerticalAlignment? = nil, @ContentBuilder content: () -> Content)
```

## Parameters

`alignment`

An optional [`VerticalAlignment`](/documentation/SwiftUI/VerticalAlignment) for the row. If you
don’t specify a value, the row uses the vertical alignment component
of the [`Alignment`](/documentation/SwiftUI/Alignment) parameter that you specify in the grid’s
[`init(alignment:horizontalSpacing:verticalSpacing:content:)`](/documentation/SwiftUI/Grid/init(alignment:horizontalSpacing:verticalSpacing:content:))
initializer, which is [`center`](/documentation/SwiftUI/VerticalAlignment/center) by default.

`content`

The builder closure that contains the child views. Each
view in the closure implicitly maps to a cell in the grid.

## Discussion

Use this initializer to create a [`GridRow`](/documentation/SwiftUI/GridRow) inside of a [`Grid`](/documentation/SwiftUI/Grid).
Provide a content closure that defines the cells of the row, and
optionally customize the vertical alignment of content within each cell.
The following example customizes the vertical alignment of the cells
in the first and third rows:

```
Grid(alignment: .trailing) {
    GridRow(alignment: .top) { // Use top vertical alignment.
        Text("Top")
        Color.red.frame(width: 1, height: 50)
        Color.blue.frame(width: 50, height: 1)
    }
    GridRow { // Use the default (center) alignment.
        Text("Center")
        Color.red.frame(width: 1, height: 50)
        Color.blue.frame(width: 50, height: 1)
    }
    GridRow(alignment: .bottom) { // Use bottom vertical alignment.
        Text("Bottom")
        Color.red.frame(width: 1, height: 50)
        Color.blue.frame(width: 50, height: 1)
    }
}
```

The example above specifies [`trailing`](/documentation/SwiftUI/Alignment/trailing) alignment for the
grid, which is composed of [`center`](/documentation/SwiftUI/VerticalAlignment/center) vertical
alignment and [`trailing`](/documentation/SwiftUI/HorizontalAlignment/trailing) horizontal alignment.
The middle row relies on the center vertical alignment, but the
other two rows specify custom vertical alignments:

![A grid with three rows and three columns. Scanning from top to bottom,](images/com.apple.SwiftUI/GridRow-init-1-iOS@2x.png)

> Important: A grid row behaves like a ``doc://com.apple.SwiftUI/documentation/SwiftUI/Group`` if you create it
> outside of a grid.

To override column alignment, use [`gridColumnAlignment(_:)`](/documentation/SwiftUI/View/gridColumnAlignment(_:)). To
override alignment for a single cell, use [`gridCellAnchor(_:)`](/documentation/SwiftUI/View/gridCellAnchor(_:)).

---

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)