Read local X.offsetX is already relative to the control.
Divide by width.clientWidth is the inner width of the element.
Scale to 0–100. Multiply by 100 and clamp so edges stay in range.
Why it helps. The percentage still makes sense when the control resizes.
Compatibility
Browser Support
MouseEvent.offsetX is Baseline Widely available (MDN: since December 2015). It is not Deprecated, Experimental, or Non-standard.
✓ Baseline · Widely available
MouseEvent.offsetX
Element-local horizontal pointer coordinate from the target’s padding edge — ideal for hit-testing and local drawing.
UniversalWidely available
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
offsetXExcellent
Bottom line: Safe to use in modern browsers. Pair with offsetY for local 2D points, and use clientX/pageX when you need viewport or document space.
Frequently Asked Questions
It is a read-only number: the horizontal offset of the mouse pointer from the padding edge of the event’s target element, measured in CSS pixels.
No. MDN marks MouseEvent.offsetX as Baseline Widely available (since December 2015). It is not Deprecated, Experimental, or Non-standard.
offsetX is measured from the left padding edge of the target node—inside the border, at the start of the padding box. Borders are outside that origin; padding and content are inside.
clientX is relative to the browser viewport. offsetX is relative to the element that received the event (event.target). The same spot on a moved element keeps a similar offsetX, while clientX changes with the window position.
pageX is relative to the whole document (includes scroll). offsetX stays local to the target element’s padding box and does not grow just because the page scrolled.
A double (floating-point) number in pixels. Early versions of the spec defined it as an integer; modern browsers report a double.