<!--
{
  "availability" : [
    "macOS: 10.9.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSStackView/alignment",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSStackView(py)alignment"
  },
  "title" : "alignment"
}
-->

# alignment

The view alignment within the stack view.

```
var alignment: NSLayoutConstraint.Attribute { get set }
```

## Discussion

The default value for this property depends on whether the stack view is horizontal or vertical:

- *Horizontal*: The default value is <doc://com.apple.documentation/documentation/UIKit/NSLayoutConstraint/Attribute/centerY>.
- *Vertical*: The default value is <doc://com.apple.documentation/documentation/UIKit/NSLayoutConstraint/Attribute/centerX>.

These constants are described as part of the <doc://com.apple.documentation/documentation/UIKit/NSLayoutConstraint/Attribute> enumeration in <doc://com.apple.documentation/documentation/UIKit/NSLayoutConstraint>; see that enumeration for the other possible alignment values.

> Note:
> Using certain values in this property can result in unexpected behavior:
> 
> - Specifying the <doc://com.apple.documentation/documentation/UIKit/NSLayoutConstraint/Attribute/notAnAttribute> constant can result in an ambiguous layout.
> - A value inappropriate for the layout direction is ignored; for example, the system ignores a value of <doc://com.apple.documentation/documentation/UIKit/NSLayoutConstraint/Attribute/centerX> for the horizontal layout.

---

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)