Read Mouse Coordinates Pointer Position Tutorial

Adam Khoury Published : November 17, 2014
Last Edited : November 24, 2025
Author : Adam Khoury
Learn to sense mouse movement and read the user mouse coordinates on the screen as they move it around. Nice user interfaces and applications can be constructed using the mouse position to adjust elements on the page relative to the mouse position. <!DOCTYPE html> <html> <head> <script> function readMouseMove(e){ var result_x = document.getElementById('x_result'); var result_y = document.getElementById('y_result'); result_x.innerHTML = e.clientX; result_y.innerHTML = e.clientY; } document.onmousemove = readMouseMove; </script> </head> <body> <h1>Document that reads mouse movement</h1> <h2 id="x_result">0</h2> <h2 id="y_result">0</h2> </body> </html>