Widely available Supported across all major browsers. Safe to use in production.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
1
12
6
2
18
1

The scrollingElement read-only property of the Document interface returns a reference to the Element that scrolls the document. In standards mode, this is the root element of the document, document.documentElement.

44
12
48
9
44
9

The scroll() method of the Element interface scrolls the element to a particular set of coordinates inside a given element.

61
79
36
10.1
61
10.3

The scroll event fires when an element has been scrolled. To detect when scrolling has completed, see the Element/scrollend_event event of Element.

1
12
6
1.3
18
1
scroll (options behavior parameter)

`options.behavior` parameter

61
79
36
14
61
14
scroll (options left parameter)

`options.left` parameter

61
79
36
10.1
61
10.3
scroll (options top parameter)

`options.top` parameter

61
79
36
10.1
61
10.3

The scrollBy() method of the Element interface scrolls an element by the given amount.

61
79
36
10.1
61
10.3
scrollBy (options behavior parameter)

`options.behavior` parameter

61
79
36
14
61
14
scrollBy (options left parameter)

`options.left` parameter

61
79
36
10.1
61
10.3
scrollBy (options top parameter)

`options.top` parameter

61
79
36
10.1
61
10.3

The scrollHeight read-only property of the Element interface is a measurement of the height of an element's content, including content not visible on the screen due to overflow.

1
12
21
1
18
1

The scrollLeft property of the Element interface gets or sets the number of pixels by which an element's content is scrolled from its left edge. This value is subpixel precise in modern browsers, meaning that it isn't necessarily a whole number.

86
86
1
1
86
1

The scrollTo() method of the Element interface scrolls to a particular set of coordinates inside a given element.

61
79
36
10.1
61
10.3
scrollTo (options behavior parameter)

`options.behavior` parameter

61
79
36
14
61
14
scrollTo (options left parameter)

`options.left` parameter

61
79
36
10.1
61
10.3
scrollTo (options top parameter)

`options.top` parameter

61
79
36
10.1
61
10.3

The scrollTop property of the Element interface gets or sets the number of pixels by which an element's content is scrolled from its top edge. This value is subpixel precise in modern browsers, meaning that it isn't necessarily a whole number.

1
12
1
1
18
1

The scrollWidth read-only property of the Element interface is a measurement of the width of an element's content, including content not visible on the screen due to overflow.

1
12
1
1
18
1

The Window.scroll() method scrolls the window to a particular place in the document.

1
12
1
1
18
1
scroll (options behavior parameter)

`options.behavior` parameter

61
79
36
14
61
14
scroll (options left parameter)

`options.left` parameter

41
79
36
10.1
41
10.3
scroll (options top parameter)

`options.top` parameter

41
79
36
10.1
41
10.3

The Window.scrollBy() method scrolls the document in the window by the given amount.

1
12
1
1
18
1
scrollBy (options behavior parameter)

`options.behavior` parameter

61
79
36
14
61
14
scrollBy (options left parameter)

`options.left` parameter

41
79
36
10.1
41
10.3
scrollBy (options top parameter)

`options.top` parameter

41
79
36
10.1
41
10.3

Window.scrollTo() scrolls to a particular set of coordinates in the document.

1
12
1
1
18
1
scrollTo (options behavior parameter)

`options.behavior` parameter

61
79
36
14
61
14
scrollTo (options left parameter)

`options.left` parameter

41
79
36
10.1
41
10.3
scrollTo (options top parameter)

`options.top` parameter

41
79
36
10.1
41
10.3

The read-only scrollX property of the Window interface returns the number of pixels by which the document is currently scrolled horizontally. This value is subpixel precise in modern browsers, meaning that it isn't necessarily a whole number. You can get the number of pixels the document is scrolled vertically from the Window.scrollY property.

1
12
1
1
18
1
scrollX (subpixel precision)

Subpixel precision

40
≤18
55
40

The read-only scrollY property of the Window interface returns the number of pixels by which the document is currently scrolled vertically. This value is subpixel precise in modern browsers, meaning that it isn't necessarily a whole number. You can get the number of pixels the document is scrolled horizontally from the Window.scrollX property.

1
12
1
1
18
1
scrollY (subpixel precision)

Subpixel precision

40
≤18
55
40
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Notes 3 item(s)
Limitation
  • This browser only partially implements this feature
Removed
  • This feature was removed in a later browser version (21)
Implementation note
  • Before Firefox 21, when an element's content does not generate a vertical scrollbar, then its `scrollHeight` property is equal to its `clientHeight` property. This can mean either the content is too short to require a scrollbar or that the element has a CSS style `overflow` value of `visible` (non-scrollable).
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (86)
Implementation note
  • For right-to-left elements, this property uses 0-100 (most left to most right) instead of negative values. See bug 41319147.
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (86)
Implementation note
  • For right-to-left elements, this property uses 0-100 (most left to most right) instead of negative values. See bug 41319147.
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (86)
Implementation note
  • For right-to-left elements, this property uses 0-100 (most left to most right) instead of negative values. See bug 41319147.
Notes 1 item(s)
Implementation note
  • Safari does not have support for the `smooth` scroll behavior.
Notes 1 item(s)
Implementation note
  • Safari on iOS does not have support for the `smooth` scroll behavior.
Notes 1 item(s)
Implementation note
  • Safari does not have support for the `smooth` scroll behavior.
Notes 1 item(s)
Implementation note
  • Safari on iOS does not have support for the `smooth` scroll behavior.
Notes 1 item(s)
Implementation note
  • Before version 15.4, Safari did not have support for the `smooth` scroll behavior.
Notes 1 item(s)
Implementation note
  • Before version 15.4, Safari on iOS did not have support for the `smooth` scroll behavior.
Notes 1 item(s)
Implementation note
  • Previously available under a different name: pageXOffset (1)
Notes 1 item(s)
Implementation note
  • Previously available under a different name: pageXOffset (12)
Notes 1 item(s)
Implementation note
  • Previously available under a different name: pageXOffset (1)
Notes 1 item(s)
Implementation note
  • Previously available under a different name: pageXOffset (1)
Notes 1 item(s)
Implementation note
  • Previously available under a different name: pageXOffset (18)
Notes 1 item(s)
Implementation note
  • Previously available under a different name: pageXOffset (1)
Notes 1 item(s)
Implementation note
  • Previously available under a different name: pageYOffset (1)
Notes 1 item(s)
Implementation note
  • Previously available under a different name: pageYOffset (12)
Notes 1 item(s)
Implementation note
  • Previously available under a different name: pageYOffset (1)
Notes 1 item(s)
Implementation note
  • Previously available under a different name: pageYOffset (1)
Notes 1 item(s)
Implementation note
  • Previously available under a different name: pageYOffset (18)
Notes 1 item(s)
Implementation note
  • Previously available under a different name: pageYOffset (1)

Syntax

JAVASCRIPT
addEventListener("scroll", (event) => { })

onscroll = (event) => { }

Use cases

  • Using Scroll methods on elements

    The scroll event fires when the document view has been scrolled.

Cautions

  • May not be supported in older browsers.

Implementation notes

  • Some APIs require a secure context (HTTPS) or user activation. Check the requirements before use.