# What is the role of pageYOffset property?

HTMLProgramming ScriptsJavascript

If you want to get the pixels of the document scrolled to from the upper left corner of the window, then use the pageXoffset and pageYoffset property. Use pageYoffset for vertical pixels.

## Example

You can try to run the following code to learn how to work with pageYOffset property in JavaScript.

Live Demo

<!DOCTYPE html>
<html>
<style>
div {
background-color: green;
height: 1500px;
width: 1500px;
}
</style>
<body>
<script>
function scrollFunc() {
window.scrollBy(200, 200);
alert("Vertical: " + window.pageYOffset);
}
</script>
<button onclick="scrollFunc()" style="position:fixed;">Scroll</button>
<br><br><br>
<div>
</div>
</body>
</html>
Updated on 19-May-2020 10:59:13