- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - usemap Attribute
The usemap is an HTML attribute that creates relationships between <img> and <map> by specifying an image or an object with clickable areas.
The usemap attribute is associated with a <map> element’s name or id attribute and creates a relationship between the <img> and the <map>.
Following are the elements where the value attribute can be used −
- <img>
- <object>
Syntax
Following is the syntax of the usemap attribute −
<img usemap-"#mapname">
The "mapname" is used to hold the map name containing the hash (#) character.
Example
In the following example, we are creating an image map with clickable areas by using the usemap attribute, as follows−
<!DOCTYPE html> <html> <body> <h1>The map and area elements</h1> <p>Click on the computer, the phone, or the cup of coffee to go to a new page and read more about the topic:</p> <img src="https://cdn.pixabay.com/photo/2017/11/27/21/31/computer-2982270_640.jpg" alt="Workplace" usemap="#workmap" width="400" height="379"> <map name="workmap"> <area shape="rect" coords="100,50,200,250" alt="Computer" href="https://images.unsplash.com/photo-1499951360447-b19be8fe80f5?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1170&q=80"> <area shape="rect" coords="60,250,150,120" alt="Phone" href="https://images.unsplash.com/photo-1511707171634-5f897ff02aa9?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8bW9iaWxlJTIwcGhvbmV8ZW58MHx8MHx8fDA%3D&w=1000&q=80"> <area shape="circle" coords="40,50,120" alt="Cup of coffee" href="https://img.freepik.com/premium-photo/coffee-cup-old-wooden-table-with-cream_158502-63.jpg"> </map> </body> </html>
On running the above code, the output window will pop up displaying the image on the webpage. when the user clicks on the respective areas of the image it further displays another image.
Example
Considering the another scenario, where we are going to use the usemap attribute with the object element.
<!DOCTYPE html> <html> <body> <h1>The object usemap attribute</h1> <object data="https://img.freepik.com/free-vector/big-animals-set_1284-10911.jpg?w=2000" width="250" height="200" usemap="#animalmap"></object> <map name="animalmap"> <area shape="rect" coords="30,10,100,100" alt="elephant" href="https://media.istockphoto.com/id/479667835/photo/background-elephant.jpg?s=612x612&w=0&k=20&c=DwfinIerTq104FXWcBBwegTWcmw8tf18EGqa5IpEyFk="> </map> <p> <b>Note:</b> The usemap attribute of the object element is not supported in Chrome, Edge, Safari, and Opera. </p> </body> </html>
When we run the above code, it will generate an output consisting of the image along with a text displayed on the webpage.
To Continue Learning Please Login
Login with Google