MDN self-hosted library · e01.org

Window: scrollByLines() method

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

html
<button id="scroll-up">Up 5 lines</button>
<button id="scroll-down">Down 5 lines</button>
js
document.getElementById("scroll-up").addEventListener("click", () => {
  window.scrollByLines(-5);
});
document.getElementById("scroll-down").addEventListener("click", () => {
  window.scrollByLines(5);
});