HTML <area> Area tag


The <area> tag in HTML is used to define clickable areas within an image map. An image map is an image with different regions that act as links. Each <area> element within a <map> element specifies a specific clickable region, such as a rectangle, circle, or polygon, and associates it with a hyperlink.

Syntax:

<area shape="rect|circle|poly" coords="coordinates" href="URL" alt="description">

How It Works:

  1. You define an image using the <img> tag and reference a <map> element that contains the clickable regions using the usemap attribute.
  2. Inside the <map> element, the <area> tag is used to define the clickable regions on the image. Each region has its own shape, coordinates, and associated link.

Attributes of the <area> Tag:

  1. shape: Specifies the shape of the clickable area. The values can be:

    • rect: Defines a rectangular area.
    • circle: Defines a circular area.
    • poly: Defines a polygonal (multi-sided) area.
    • default: Specifies the entire image as a clickable area.
  2. coords: Specifies the coordinates of the area. The value and number of coordinates depend on the shape attribute:

    • For rect, it requires four coordinates: x1, y1, x2, y2 (top-left and bottom-right corners).
    • For circle, it requires three coordinates: x, y, radius (center and radius of the circle).
    • For poly, it requires multiple coordinates: x1, y1, x2, y2, x3, y3, ... (each pair represents a vertex of the polygon).
  3. href: Specifies the URL that the clickable area will link to.

  4. alt: Provides alternative text for the area, used for accessibility and when images are disabled in the browser.

  5. target: Specifies where to open the linked document, similar to the anchor (<a>) tag (e.g., _blank, _self).

Example of an Image Map with the <area> Tag:

<img src="world-map.jpg" usemap="#worldmap" alt="World Map"> <map name="worldmap"> <!-- Rectangular area linking to a page about North America --> <area shape="rect" coords="10,10,100,100" href="north-america.html" alt="North America"> <!-- Circular area linking to a page about Europe --> <area shape="circle" coords="200,150,50" href="europe.html" alt="Europe"> <!-- Polygonal area linking to a page about Africa --> <area shape="poly" coords="300,200,320,220,310,250,290,260" href="africa.html" alt="Africa"> </map>

Explanation:

  • The image (world-map.jpg) references the worldmap defined by the <map> element using the usemap attribute.
  • Inside the <map> element, three different <area> tags define clickable regions on the image:
    • A rectangular area for North America.
    • A circular area for Europe.
    • A polygonal area for Africa.
  • Each region links to a different webpage when clicked.

Accessibility:

  • The alt attribute is crucial for accessibility, as it provides descriptive text for users who rely on screen readers or have images disabled in their browsers.
  • Without proper alt text, image maps may be less usable for people with disabilities.