api-member

Element.scrollBy — CSS reference

Moves relative to the current scroll offsets. This example starts at zero and applies two increments.

Formal Syntax & Structure

css syntaxcss
element.scrollBy({top,left,behavior})

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>Element.scrollBy</title><style>body{margin:0;font:16px system-ui}#a{box-sizing:content-box;width:120px;height:60px;padding:8px;border:3px solid #475569;overflow:auto}#output{white-space:pre-wrap}#a{overflow:hidden}</style><body><div id="a"><div style="width:240px;height:200px">Content</div></div><pre id="output" aria-live="polite"></pre><script>const a=document.getElementById("a"); window.demoResult=(async()=>{a.scrollBy({top:20,behavior:"instant"});a.scrollBy({top:15,behavior:"instant"});return a.scrollTop;})();window.demoResult.then(v=>document.getElementById("output").textContent=JSON.stringify(v),e=>document.getElementById("output").textContent=String(e));</script></body></html>
CSS Reference