Last Updated: 17th August 2026
Images play a very important role while designing a website. Sometimes we add different types of images on a single web page. We embed multiple images in a single image (this method is called image sprite) to save load time of the web page. Finding the precise X and Y coordinates of an image in the stack using mouse click or mouse Move, eliminates guesswork.We can find the X and Y coordinates using jQuery pageX and pageY events to locate the mouse position on the image or any element to be precise. We can get the location of the mouse either by hovering it over the image or by clicking the image.
  To view image metadata such as GPS location, camera details, copyright, date and time, and more, try our EXIF Metadata Viewer  .
We will add a Sprite image in our web page, which has three small images embedded together in a single image file. We will also add a DIV element, which will show us the coordinates when we move, hover or click on the image.
<html>
<head>
<title>X, Y Coordinates using jQuery</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div style="width:300px;">
<div><img src="sprite.png" alt="" /></div>
<div style="padding-top:20px;">
<div id="coord"></div>
</div>
</div>
</body>
</html>To get the precise X, Y coordinates of the image we will use jQuery offset() method to remove spaces between the window and image container. The DIV is acting as a container to the image. This way even if we add a little padding to the container, the coordinates of the image is precise.
<script>
$(document).ready(function() {
$('img').click(function(e) {
var offset = $(this).offset();
var X = (e.pageX - offset.left);
var Y = (e.pageY - offset.top);
$('#coord').text('X: ' + X + ', Y: ' + Y);
});
});
</script>👉 Click the below icons
  Need to inspect an image's metadata, such as its EXIF data? Use our EXIF Metadata Viewer   to view the information embedded in your image.
<script>
$(document).ready(function() {
$('img').on("mousemove", function(e) {
var offset = $(this).offset();
var X = (e.pageX - offset.left);
var Y = (e.pageY - offset.top);
$('#coord').text('X: ' + X + ', Y: ' + Y);
});
});
</script>Demo - Hover the Mouse over the images
What Can You Do With Image X/Y Coordinates?
Once you know the exact position where a user clicks or moves the mouse over an image, you can use those coordinates for much more than simply displaying two numbers.
For example, image coordinates can be used to build:
- Image annotation — let users place notes, labels, or markers at specific locations.
- Clickable regions — make particular areas of an image interactive.
- mage maps — create links or actions associated with different areas of an image.
- Point selection — allow users to click an image and select a specific location.
- Drawing markers — place pins, dots, or other visual indicators where the user clicks.
- Crop and selection interfaces — determine the position of a user's selection within an image.
- Coordinate-based games — use mouse positions to determine where a player clicks or interacts.
- Floor plans and maps — allow users to select rooms, buildings, locations, or other areas.
- Image labeling — allow users to identify and label objects within an image.
Free Photo Editor: Add Watermark to an Image Without Uploading.
We have seen how x, y coordinates can be located in an image inside another image, in fact these properties are not confined to images only, you can try with other HTML elements like DIV or P.
Sprite images are a collection of multiple image bundled together in a single image. Learn more about Image Sprite.
