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:
- You define an image using the
<img>
tag and reference a<map>
element that contains the clickable regions using theusemap
attribute. - 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:
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.
coords
: Specifies the coordinates of the area. The value and number of coordinates depend on theshape
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).
- For
href
: Specifies the URL that the clickable area will link to.alt
: Provides alternative text for the area, used for accessibility and when images are disabled in the browser.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 theworldmap
defined by the<map>
element using theusemap
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.