Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.

HTML <area> id Attribute

An id on an <area> tag assigns an identifier to the area.

The identifier must be unique across the page.

Example

#

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');">
</map>


Using id

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

The identifier must be unique across the page.

The id allows JavaScript to easily access the <area> element.

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


Syntax

<area id="identifier" />

Values

#

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">
</map>

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

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

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:

Chrome
1.0 Sep 2008
Firefox
1.0 Sep 2002
IE/Edge
1.0 Aug 1995
Opera
1.0 Jan 2006
Safari
1.0 Jan 2003

You may also like

 Back to <area>
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.

Guides