HTML coords Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 5 Examples
Interactive Images

Introduction

The coords attribute is used in HTML to define the coordinates of clickable areas within an image map. It belongs on the <area> element and works together with the shape attribute to describe where each hotspot sits on the associated image.

What You’ll Learn

01

rect coords

Four corner values.

02

circle coords

Center + radius.

03

poly coords

Vertex pairs.

04

area + map

Image map setup.

05

area.coords

JS updates.

06

A11y alt

Describe hotspots.

Purpose of coords

The primary purpose of the coords attribute is to provide the position and size of a clickable region within an image. This is essential when creating image maps, where different parts of one image link to different destinations.

💡
Used with shape and usemap

coords alone is not enough. Each <area> needs a shape value, and the parent <img> must reference the <map> with usemap="#map-name".

📝 Syntax

Place coords on an <area> inside a <map>:

coords.html
<img src="diagram.png" alt="Site map" usemap="#site-map">

<map name="site-map">

  <area shape="rect" coords="0,0,100,100" href="/home" alt="Home">

</map>

Syntax Rules

  • Values are comma-separated numbers in pixels relative to the image (no units in the attribute).
  • Always pair coords with a matching shape attribute on the same <area>.
  • Spaces after commas are optional: 10,10,100,100 and 10, 10, 100, 100 both work.
  • Include a descriptive alt on every <area> for accessibility.

💎 Values

The coords format depends on the shape of the clickable area:

Rectangular area (shape="rect")

Use four values — x1, y1, x2, y2 — for the top-left and bottom-right corners of the rectangle:

rect-coords.html
<area shape="rect" coords="left, top, right, bottom" href="destination.html" alt="Description">

Circular area (shape="circle")

Use three values — x, y, radius — for the center point and radius:

circle-coords.html
<area shape="circle" coords="x, y, radius" href="destination.html" alt="Description">

Polygonal area (shape="poly")

Provide pairs of x, y values for each vertex. You need at least three points to form a polygon:

poly-coords.html
<area shape="poly" coords="x1, y1, x2, y2, x3, y3, ..." href="destination.html" alt="Description">

⚡ Quick Reference

shapecoords formatMeaning
rectx1,y1,x2,y2Top-left and bottom-right corners
circlex,y,rCenter x, center y, radius
polyx1,y1,x2,y2,...Each vertex of the polygon
JavaScriptarea.coords = "150,80,50"Update hotspot at runtime
Related attrsshape, href, altRequired companions on area
Image linkusemap="#map-name"On img, references map

Applicable Elements

ElementSupported?Notes
<area>YesPrimary element for coords
<map>ContainerGroups <area> elements; no coords here
<img>RelatedUses usemap, not coords
<div>, <a>NoUse CSS or normal links instead

coords and shape work together

AttributeRoleExample
shapeDeclares geometry typerect, circle, poly
coordsNumbers for that shape0,0,100,100 for rect
hrefDestination URL/about
altHotspot descriptionAbout page

Examples Gallery

Full image map with multiple shapes and a JavaScript coords update.

👀 Live Preview

Click the HTML or CSS regions on this navigation diagram:

HTML and CSS navigation map — click a labeled regionLearn HTMLLearn CSS

Example

Here’s an example of using the coords attribute within an image map with rect, circle, and poly shapes:

coords.html
<img src="diagram.png" alt="Clickable Image" usemap="#imageMap">

<map name="imageMap">

  <area shape="rect" coords="10, 10, 100, 100" href="destination1.html" alt="Area 1">

  <area shape="circle" coords="150, 80, 50" href="destination2.html" alt="Area 2">

  <area shape="poly" coords="220, 30, 300, 80, 250, 150" href="destination3.html" alt="Area 3">

</map>
Try It Yourself

How It Works

In this example, three clickable areas are defined within the image using different shape values and matching coords formats. Each area also needs an href and descriptive alt text.

Dynamic Values with JavaScript

You can dynamically set the coords attribute using JavaScript. This is useful when you need to adjust clickable areas based on responsive layouts or user interactions:

dynamic-coords.html
<area id="dynamicArea" shape="circle" href="/about" alt="About">



<script>

  // Dynamically set coords for a circular area

  document.getElementById("dynamicArea").coords = "200, 120, 80";

</script>
Try It Yourself

How It Works

In this script, the coords property is set on an <area> with id dynamicArea, defining a circle with center (200, 120) and radius 80. Assign a comma-separated string; the browser parses it according to the area’s shape.

♿ Accessibility

  • alt on every area — Describe what each hotspot does so screen reader users understand the link purpose.
  • Meaningful img alt — The image itself should describe the overall diagram, not just “image map.”
  • Keyboard navigation — Image maps are focusable links; test Tab order through hotspots.
  • Don’t rely on color alone — Label regions visibly; coords define invisible hit areas.
  • Consider alternatives — For complex UIs, a list of text links may be easier for some users than a dense image map.

🧠 How coords Works

1

Link image to map

Add usemap="#name" on the img element.

usemap
2

Define area shapes

Set shape and coords on each area inside map.

Markup
3

Browser maps pixels

Clicks inside coords regions activate the area href.

Hit test
=

Interactive image map

One image links to many destinations through precise hotspots.

Browser Support

The coords attribute on <area> elements is supported in all modern browsers. Image maps have been part of HTML for decades.

HTML · Fully supported

Universal image map coordinates

All major browsers honor rect, circle, and poly coords on area elements.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
coords attribute 99% supported

Bottom line: Image maps with coords work reliably; test hotspot alignment if the image is scaled with CSS.

💡 Best Practices

✅ Do

  • Match coords to actual pixel positions on the image
  • Always set shape alongside coords on each area
  • Provide descriptive alt text for every hotspot
  • Test image maps in multiple browsers
  • Use image map tools or editors to find coordinates accurately

❌ Don’t

  • Put coords on img instead of area elements
  • Forget usemap on the image
  • Use coords outside the image dimensions
  • Overlap hotspots without clear alt labels
  • Scale images with CSS without recalculating coords
  • Ensure that the coordinates provided match the actual dimensions and positions within the image to create accurate clickable areas.
  • Test your image maps across different browsers to ensure consistent behavior.
  • Consider accessibility by providing descriptive alternative text (alt attribute) for each clickable area.

Conclusion

The coords attribute plays a crucial role in creating interactive image maps in HTML. By understanding how coordinate formats differ for rect, circle, and poly shapes, you can enhance the interactivity and navigation of your web pages.

For simple diagrams and navigation graphics, image maps remain a lightweight option. For highly responsive layouts, consider whether SVG or positioned links better suit your design — but when you use <map> and <area>, coords is how you define each clickable region.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about coords

Bookmark these before building an image map.

5
Core concepts
▢️ 02

rect / circle / poly

Three formats.

Shapes
🔗 03

usemap + map

Link image.

Setup
⚙️ 04

area.coords

JS string.

Script
05

alt Required

Describe links.

A11y

❓ Frequently Asked Questions

It defines the pixel coordinates of a clickable hotspot on an image map. The number format depends on whether the area is a rectangle, circle, or polygon.
coords is used on <area> elements inside a <map>. The image links to the map with usemap, not with coords directly.
Four numbers: x1,y1,x2,y2 — the top-left corner and bottom-right corner of the rectangle in pixels from the image origin.
Circle uses x,y,radius. Poly uses alternating x,y pairs for each vertex, with at least three points.
Yes. Set areaElement.coords = "150,80,50" to change the hotspot. The browser interprets the string based on the area’s shape.
Browsers scale hit areas with the displayed image size in most cases, but extreme CSS scaling can misalign hotspots. Test after responsive layout changes.

Build clickable image maps

Practice rect, circle, poly, and JavaScript coords examples in the Try It editor.

Try rect coords example →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful