<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/ScrollViewReader",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI16ScrollViewReaderV"
  },
  "title" : "ScrollViewReader"
}
-->

# ScrollViewReader

A view that provides programmatic scrolling, by working with a proxy
to scroll to known child views.

```
@frozen nonisolated struct ScrollViewReader<Content> where Content : View
```

## Overview

The scroll view reader’s content content builder receives a [`ScrollViewProxy`](/documentation/SwiftUI/ScrollViewProxy)
instance; you use the proxy’s [`scrollTo(_:anchor:)`](/documentation/SwiftUI/ScrollViewProxy/scrollTo(_:anchor:)) to
perform scrolling.

The following example creates a [`ScrollView`](/documentation/SwiftUI/ScrollView) containing 100 views that
together display a color gradient. It also contains two buttons, one each
at the top and bottom. The top button tells the [`ScrollViewProxy`](/documentation/SwiftUI/ScrollViewProxy) to
scroll to the bottom button, and vice versa.

```
@Namespace var topID
@Namespace var bottomID

var body: some View {
    ScrollViewReader { proxy in
        ScrollView {
            Button("Scroll to Bottom") {
                withAnimation {
                    proxy.scrollTo(bottomID)
                }
            }
            .id(topID)

            VStack(spacing: 0) {
                ForEach(0..<100) { i in
                    color(fraction: Double(i) / 100)
                        .frame(height: 32)
                }
            }

            Button("Top") {
                withAnimation {
                    proxy.scrollTo(topID)
                }
            }
            .id(bottomID)
        }
    }
}

func color(fraction: Double) -> Color {
    Color(red: fraction, green: 1 - fraction, blue: 0.5)
}
```

![A scroll view, with a button labeled “Scroll to Bottom” at top.](images/com.apple.SwiftUI/SwiftUI-ScrollViewReader-scroll-to-bottom-button@2x.png)

> Important: You may not use the ``doc://com.apple.SwiftUI/documentation/SwiftUI/ScrollViewProxy``
> during execution of the `content` content builder; doing so results in a
> runtime error. Instead, only actions created within `content` can call
> the proxy, such as gesture handlers or a view’s `onChange(of:perform:)`
> method.

## Topics

### Creating a scroll view reader

[`init(content:)`](/documentation/SwiftUI/ScrollViewReader/init(content:))

Creates an instance that can perform programmatic scrolling of its
child scroll views.

### Configuring a scroll view reader

[`content`](/documentation/SwiftUI/ScrollViewReader/content)

The content builder that creates the reader’s content.



---

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)