HTML Area alt
Property: Alternative Text for Image Map Areas
The HTML <area>
tag, used within <map>
to define clickable regions in an image map, includes the alt
attribute. This attribute provides alternative text for each defined area. This text is displayed if the image cannot be shown, is used by screen readers to describe the area to visually impaired users, and is also helpful for search engine optimization (SEO).
What is the alt
Property?
The alt
(alternative text) attribute specifies a text alternative for the area. This text should describe the destination or function of the link associated with the area. Itβs a crucial attribute for accessibility, ensuring that all users, regardless of their visual abilities, can understand the purpose of the image map areas.
Purpose of the alt
Property
The primary purposes of the alt
property are to:
- Accessibility: Provide a text equivalent for users who cannot see the image, such as those using screen readers.
- Usability: Display alternative text if the image fails to load, ensuring users still understand the context.
- SEO: Help search engines understand the content and purpose of the linked area.
Syntax
The syntax for using the alt
property within an <area>
tag is:
<area shape="shape_value" coords="coordinates" href="url" alt="alternative text">
Attribute | Value | Description |
---|---|---|
`alt` | Text | Specifies an alternative text for the area. This text should describe the destination or function of the link associated with the area. |
Examples
Let’s explore several examples demonstrating the use of the alt
property in different scenarios.
Basic Example
This basic example demonstrates the use of the alt
attribute to describe a clickable area in an image map.
<img src="planets.gif" alt="Planets" usemap="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun">
<area shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury">
<area shape="circle" coords="124,58,8" href="venus.htm" alt="Venus">
</map>
In this case, if the image doesn’t load, or for screen reader users, “Sun”, “Mercury”, and “Venus” will be shown or read for each respective area.
Detailed Descriptions
Providing more detailed descriptions can enhance usability, especially for complex image maps.
<img src="complex_map.png" alt="Interactive Map" usemap="#complexmap">
<map name="complexmap">
<area shape="poly" coords="100,50,150,75,200,50,150,25" href="region1.htm" alt="Detailed description of Region 1">
<area shape="rect" coords="250,50,350,100" href="region2.htm" alt="Information about Region 2">
</map>
Here, the alt
attributes provide more context about the areas, beneficial for accessibility and SEO.
Empty alt
Attribute for Decorative Images
If an image map is purely decorative, the alt
attribute should still be present but left empty (alt=""
).
<img src="decorative.png" alt="" usemap="#decorativemap">
<map name="decorativemap">
<area shape="rect" coords="0,0,50,50" href="link1.htm" alt="">
<area shape="rect" coords="50,0,100,50" href="link2.htm" alt="">
</map>
This indicates to screen readers that the image and its areas should be ignored.
Advanced Example: Interactive Canvas with Image Map
Combining the Canvas API with image maps can create interactive graphics. In this example, an image map overlays a canvas element, with the alt
attribute providing descriptions for each area.
<canvas id="interactiveCanvas" width="300" height="200" style="border:1px solid #d3d3d3; position: relative;">
Your browser does not support the HTML5 canvas tag.
</canvas>
<img src="overlay_map.png" alt="Interactive Overlay" usemap="#canvasmap" style="position: absolute; top: 0; left: 0; width: 300px; height: 200px;">
<map name="canvasmap">
<area shape="rect" coords="0,0,100,100" href="#" alt="Description for Area 1" onclick="area1Function()">
<area shape="rect" coords="100,0,200,100" href="#" alt="Description for Area 2" onclick="area2Function()">
<area shape="rect" coords="200,0,300,100" href="#" alt="Description for Area 3" onclick="area3Function()">
<area shape="rect" coords="0,100,100,200" href="#" alt="Description for Area 4" onclick="area4Function()">
<area shape="rect" coords="100,100,200,200" href="#" alt="Description for Area 5" onclick="area5Function()">
<area shape="rect" coords="200,100,300,200" href="#" alt="Description for Area 6" onclick="area6Function()">
</map>
<script>
function area1Function() { alert('Area 1 Clicked'); }
function area2Function() { alert('Area 2 Clicked'); }
function area3Function() { alert('Area 3 Clicked'); }
function area4Function() { alert('Area 4 Clicked'); }
function area5Function() { alert('Area 5 Clicked'); }
function area6Function() { alert('Area 6 Clicked'); }
</script>
In this setup:
- A canvas element with
id="interactiveCanvas"
provides the visual layer. - An image with an image map (
usemap="#canvasmap"
) is positioned absolutely over the canvas to create clickable areas. - Each
<area>
tag includes thealt
attribute for accessibility andonclick
event handlers for interactivity.
Note: The above example requires a placeholder image (overlay_map.png
) and is for demonstration purposes. Replace the placeholder with your actual image.
Tips and Best Practices
- Be Descriptive: Write
alt
text that clearly describes the function or destination of the link. - Keep it Concise: Aim for brevity while still conveying the necessary information.
- Avoid Redundancy: Don’t repeat the same text in multiple
alt
attributes if the areas serve different purposes. - Context Matters: Tailor the
alt
text to the context of the image map and its surrounding content. - Test with Screen Readers: Use screen readers to ensure your
alt
text provides an adequate experience for visually impaired users. - Decorative Images: Use
alt=""
for decorative images to ensure screen readers ignore them. - Use alt attribute for every area element! π¨ This is essential for accessibility.
Accessibility Considerations
Providing meaningful alt
text is essential for web accessibility. Screen readers rely on this text to convey the purpose of the image map areas to users with visual impairments. A well-crafted alt
attribute ensures that all users have an equal opportunity to understand and interact with the content.
Browser Support
The alt
attribute for the <area>
tag is supported by all major browsers, ensuring consistent behavior across different platforms.
Conclusion
The alt
property of the HTML <area>
tag is crucial for creating accessible and user-friendly image maps. By providing descriptive alternative text, you enhance the usability of your website for all users, improve SEO, and adhere to web accessibility standards. Always use the alt
attribute thoughtfully to ensure a positive and inclusive user experience. π