
What is the <area>
Tag?
The <area>
HTML tag is used in conjunction with the <map>
tag to define clickable areas on an image, known as an image map. These interactive hotspots enable users to click on different parts of an image to navigate to specific links, making them ideal for geographical maps, diagrams, or any visual element with multiple clickable regions.
Basic Syntax of the <area>
Tag
<img src="worldmap.jpg" usemap="#worldmap" alt="World Map">
<map name="worldmap">
<area shape="rect" coords="34,44,270,350" alt="North America" href="north-america.html">
<area shape="circle" coords="477,300,100" alt="Europe" href="europe.html">
</map>
In this example, the usemap
attribute in the <img>
tag links the image to the <map>
element with the name worldmap
. The <area>
tags define specific regions of the image, each with coordinates, shape, and links.
Attributes of the <area>
Tag
The <area>
tag includes several important attributes for defining and styling clickable regions:
shape
: Specifies the shape of the clickable area. Common values includerect
(rectangle),circle
, andpoly
(polygon).coords
: Defines the coordinates for the clickable region. These values vary based on the shape specified.href
: Sets the URL the user is directed to when clicking the region.alt
: Provides alternate text for accessibility, describing each area for users who cannot see the image.target
: Specifies where to open the linked URL (e.g.,_blank
for a new tab).
Using shape
and coords
Attributes
Understanding the shape
and coords
attributes is crucial for defining areas accurately:
- Rectangle (
rect
): Two pairs of x,y coordinates. Example:coords="34,44,270,350"
. - Circle (
circle
): The center's x,y coordinates followed by the radius. Example:coords="477,300,100"
. - Polygon (
poly
): Multiple x,y coordinates defining each point of the polygon. Example:coords="130,150,220,210,190,280"
.
Best Practices for Creating Interactive Image Maps
- Use Descriptive Alt Text: Each
<area>
tag should have analt
attribute to improve accessibility for screen readers. - Limit Complexity: Keep image maps simple and avoid too many clickable areas to prevent overwhelming users.
- Test Across Devices: Ensure image maps are responsive and user-friendly on mobile devices.
Conclusion
The <area>
tag, when paired with <map>
, is a powerful tool for creating interactive and engaging images on web pages. By defining clickable regions with <area>
tags, you can enhance navigation and provide an enriched user experience.
0 Comments