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

# spacing

The minimum spacing, in points, between adjacent views in the stack view.

```
var spacing: CGFloat { get set }
```

## Discussion

A stack view uses this property to define the minimum distance between views within a gravity area and between neighboring views in adjacent gravity areas. The default value for the [`spacing`](/documentation/AppKit/NSStackView/spacing) property is `8.0` points.

The automatically applied Auto Layout constraints for [`spacing`](/documentation/AppKit/NSStackView/spacing) are shown in the table below.

|Constraint                                                                                                            |Value for constraint priority                      |
|----------------------------------------------------------------------------------------------------------------------|---------------------------------------------------|
|inter-view spacing `==` the ``doc://com.apple.appkit/documentation/AppKit/NSStackView/spacing`` property value        |max (NSLayoutPriorityDefaultHigh, hugging priority)|
|inter-gravity-area spacing `==` the ``doc://com.apple.appkit/documentation/AppKit/NSStackView/spacing`` property value|hugging priority                                   |
|inter-view spacing `≥` the ``doc://com.apple.appkit/documentation/AppKit/NSStackView/spacing`` property value         |NSLayoutPriorityRequired                           |

The first row indicates that inter-view spacing is constrained to equal the value of the [`spacing`](/documentation/AppKit/NSStackView/spacing) property with a priority of at least [`defaultHigh`](/documentation/AppKit/NSLayoutConstraint/Priority-swift.struct/defaultHigh); you can increase this by setting a higher stack view hugging priority with the [`setHuggingPriority(_:for:)`](/documentation/AppKit/NSStackView/setHuggingPriority(_:for:)) method.

The second row indicates that the spacing between adjacent views in neighboring gravity areas is constrained to equal the value of the [`spacing`](/documentation/AppKit/NSStackView/spacing) property with the priority of the stack view’s hugging priority.

The third row indicates that inter-view spacing is allowed to grow larger than the value of the [`spacing`](/documentation/AppKit/NSStackView/spacing) property with a priority of NSLayoutPriorityRequired.

In combination, these constraints result in the following typical stack view behavior: In a stack view whose [`hasEqualSpacing`](/documentation/AppKit/NSStackView/hasEqualSpacing) property is set to <doc://com.apple.documentation/documentation/Swift/false> (the default) and whose hugging priority is left at [`defaultLow`](/documentation/AppKit/NSLayoutConstraint/Priority-swift.struct/defaultLow) (the default), views within a gravity area remain a fixed distance from each other (equal to the value of the [`spacing`](/documentation/AppKit/NSStackView/spacing) property), and the distance between gravity areas grows and shrinks as the stack view grows and shrinks along its layout direction axis. If you set the [`hasEqualSpacing`](/documentation/AppKit/NSStackView/hasEqualSpacing) property to <doc://com.apple.documentation/documentation/Swift/true> and use the default hugging priority, then the distance between all adjacent views, including adjacent views in neighboring gravity areas, grows and shrinks as the stack view grows and shrinks.

---

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)