HTML <area> id Attribute

The id attribute on an <area> tag assigns an identifier to the area element. The identifier must be unique across the page.



Three <area> tags, each one with a unique id.

Computer Screen Keyboard Mouse
<img src="/img/html/computer-map.png" alt="Computer" usemap="#computermap" />

<map name="computermap">
  <area id="monitor" shape="rect" coords="253,142,16,2" 
        alt="Screen" href="javascript:alert('Screen was clicked');">
  <area id="keyboard" shape="rect" coords="262,218,0,156" 
        alt="Keyboard" href="javascript:alert('Keyboard was clicked');">
  <area id="mouse" shape="circle" coords="267,234,22" 
        alt="Mouse" href="javascript:alert('Mouse was clicked');">

Using id

The id attribute assigns an identifier to the <area> element.

The identifier must be unique across the page.

The id allows programmatic access to the <area> element.

Tip:  id is a global attribute that can be applied to any HTML element.


<area id="identifier" />



Value Description
identifier A unique alphanumeric string. The id value must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.).

More Examples

An <area> with a unique id.
Clicking the button will display the area coordinates.

Computer monitor

<img src="/img/html/computer-map.png" alt="Computer" usemap="#computermap">

<map name="computermap">
  <area id="myarea" shape="rect" coords="253,142,16,2"
        href="javascript:alert('Screen was clicked')"
        alt="monitor" type="image/png">

<button onclick="show();">Show coordinates</button>

  let show = () => {
     let element = document.getElementById("myarea");
     alert("Coordinates = " + element.coords);

Code explanation

The id attribute assigns a unique identifier for the <area>.

Clicking the button calls JavaScript which locates the <area> through the id.

Finally, the coordinates of the area are displayed in an alert box.

Browser support

Here is when id support started for each browser:

1.0 Sep 2008
1.0 Sep 2002
1.0 Aug 1995
1.0 Jan 2006
1.0 Jan 2003

You may also like

 Back to <area>