HTML DOM scrollLeft Property Use Cases

To get the scroll position of an element, use scrollLeft and scrollTop properties. To set scroll position, assign desired values to these properties dynamically via JavaScript.

To get the position of the scrollbar in JavaScript, use the scrollLeft property for horizontal scroll position and the scrollTop property for vertical scroll position of an element.

HTML DOM scrollLeft Property

HTML DOM scrollLeft property is used to return or set the number of pixels an element i.e. scrolled horizontally. If the content of the element doesn’t generate a scroll bar, then its scrollLeft value is 0; 

Syntax:

  • It returns the scrollLeft property.
element.scrollLeft
  • It is used to set the scrollLeft property.
element.scrollLeft = value

Where value specifies the number of pixels the element’s content is scrolled horizontally. 

Note: 

  • Its value can’t be negative.
  • If the value specified is greater than the maximum scroll amount, the value is set to a maximum number.

Similar Reads

HTML DOM scrollLeft Property Examples

Example: In this example, we will use the scrollLeft property....

HTML DOM scrollLeft Property Use Cases

...

HTML DOM scrollLeft Property Supported Browsers

...