You are here: Reference > JavaScript > client-side > HTML DOM > methods > scroll (window)

scroll method (window)

Browser support:
Scrolls the contents of the document window to the specified horizontal and vertical positions.
This method has been replaced by the scrollTo method, use that instead.
  • If you want to scroll the document by a specified number of pixels, use the scrollBy method.
  • The position of the document's scrollbars can be retrieved with the scrollLeft and scrollTop properties. These properties can be used to specify or retrieve the position of the scrollbars of an element and the document.
  • To get the maximum scrolling positions, use the scrollWidth, scrollHeight and clientWidth, clientHeight properties.
  • If you want to scroll an element into the visible area, you can use the scrollIntoView method.


object.scroll (X, Y);
You can find the related objects in the Supported by objects section below.


Required. Integer that specifies the horizontal position.
Required. Integer that specifies the vertical position.

Return value:

This method has no return value.

Example HTML code 1:

This example shows how to scroll the document window to a specified position:
        .blue {
            position: absolute;
            left: 100px;
            top: 400px;
            width: 200px;
            height: 200px;
            background-color: #0000a0;
            color: yellow;
    <script type="text/javascript">
        function ScrollToBlue () {
            window.scroll (0, 400);
    <button onclick="ScrollToBlue ()">Scroll the document to the blue field!</button>
    <div style="height:1000px; background-color:#ffffff;"></div>
    <div class="blue">
        After you clicked on the button, the top of this field 
        must be aligned to the top of the client area.
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content