Window scrollBy() Method

## JavaScript Reference

Overview

## JavaScript Objects

JS Array JS Boolean JS Date JS Math JS Number JS String JS RegExp JS Global

## Browser Objects

Window Navigator Screen History Location

## HTML DOM Objects

DOM Document DOM Elements DOM Attributes DOM Events

## HTML Objects

DOM Anchor DOM Area DOM Base DOM Body DOM Button DOM Form DOM Frame/IFrame DOM Frameset DOM Image DOM Input Button DOM Input Checkbox DOM Input File DOM Input Hidden DOM Input Password DOM Input Radio DOM Input Reset DOM Input Submit DOM Input Text DOM Link DOM Meta DOM Object DOM Option DOM Select DOM Style DOM Table DOM td / th DOM tr DOM Textarea

# Window scrollBy() Method

Window Object

## Example

Scroll the content by 100px horizontally:

window.scrollBy(100,0);
Try it yourself »

## Definition and Usage

The scrollBy() method scrolls the content by the specified number of pixels.

Note: For this method to work, the visible property of the window's scrollbar must be set to true!

## Browser Support

The scrollBy() method is supported in all major browsers.

## Syntax

window.scrollBy(xnum,ynum)

## Parameter Values

Parameter | Description
--- | ---
xnum | Required. How many pixels to scroll by, along the x-axis (horizontal). Positive values will scroll to the left, while negative values will scroll to the left
ynum | Required. How many pixels to scroll by, along the y-axis (vertical). Positive values will scroll up, while negative values scroll down

## Return Value

No return value.

## More Examples

## Example

Scroll the content by 100px vertically:

window.scrollBy(0,100);
Try it yourself »

## Example

Scroll the content horizontally and vertically:

<button onclick="scrollWin(0,100)">Scroll down</button>
<button onclick="scrollWin(0,-100)">Scroll up</button>
<button onclick="scrollWin(100,0)">Scroll right</button>
<button onclick="scrollWin(-100,0)">Scroll left</button>
<script>
function scrollWin(x,y)
{
window.scrollBy(x,y);
}
</script>
Try it yourself »

Window Object

## Your suggestion:

Your E-mail (optional):

Page address:

Description:

Close [X]

## Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

## WEB HOSTING

Best Web Hosting UK Reseller Hosting Wow! $5 SSD Hosting

## WEB BUILDING

Download XML Editor
FREE Website BUILDER FREE Website Creator

## WEB RESOURCES

Web Statistics Web Validation

## SHARE THIS PAGE