<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/scrollTargetBehavior(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE20scrollTargetBehavioryQrqd__AA06ScrolleF0Rd__lF"
  },
  "title" : "scrollTargetBehavior(_:)"
}
-->

# scrollTargetBehavior(_:)

Sets the scroll behavior of views scrollable in the provided axes.

```
nonisolated func scrollTargetBehavior(_ behavior: some ScrollTargetBehavior) -> some View
```

## Discussion

A scrollable view calculates where scroll gestures should end using its
deceleration rate and the state of its scroll gesture by default. A
scroll behavior allows for customizing this logic. You can provide
your own [`ScrollTargetBehavior`](/documentation/SwiftUI/ScrollTargetBehavior) or use one of the built in behaviors
provided by SwiftUI.

### Paging Behavior

SwiftUI offers a [`PagingScrollTargetBehavior`](/documentation/SwiftUI/PagingScrollTargetBehavior) behavior which uses the
geometry of the scroll view to decide where to allow scrolls to end.

In the following example, every view in the lazy stack is flexible
in both directions and the scroll view will settle to container aligned
boundaries.

```
ScrollView {
    LazyVStack(spacing: 0.0) {
        ForEach(items) { item in
            FullScreenItem(item)
        }
    }
}
.scrollTargetBehavior(.paging)
```

### View Aligned Behavior

SwiftUI offers a [`ViewAlignedScrollTargetBehavior`](/documentation/SwiftUI/ViewAlignedScrollTargetBehavior) scroll behavior
that will always settle on the geometry of individual views.

```
ScrollView(.horizontal) {
    LazyHStack(spacing: 10.0) {
        ForEach(items) { item in
            ItemView(item)
        }
    }
    .scrollTargetLayout()
}
.scrollTargetBehavior(.viewAligned)
.safeAreaPadding(.horizontal, 20.0)
```

You configure which views should be used for settling using the
[`scrollTargetLayout(isEnabled:)`](/documentation/SwiftUI/View/scrollTargetLayout(isEnabled:)) modifier. Apply this modifier to
a layout container like [`LazyVStack`](/documentation/SwiftUI/LazyVStack) or [`HStack`](/documentation/SwiftUI/HStack) and each individual
view in that layout will be considered for alignment.

---

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)