- 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
Using HTML ISMAP
The isMap Attribute
The HTML isMap is a boolean attribute which is used with images to specify that the image being used is a server-side image map. Here, the image map is an image having one or more clickable areas. However, it is important to note that the ismap attribute will work only if the <img> element is a descendant of an <a> element with a valid href attribute.
How to use isMap attribute in HTML?
To use an image with ismap attribute, we simply put the required image inside a hyperlink and use ismap attribute which makes it a special image and when the user clicks some place within the image, the browser passes the coordinates of the mouse pointer along with the URL specified in the <a> tag to the web server. The server uses the mouse-pointer coordinates to determine which document to deliver back to the browser.
When ismap is used, the href attribute of the containing <a> tag must contain the URL of a server application like a cgi or PHP script to process the incoming request based on the passed coordinates.
The coordinates of the mouse position are screen pixels counted from the upper-left corner of the image, beginning with (0,0). The coordinates, preceded by a question mark, are added to the end of the URL.
Example
Let's look at an example −
<!DOCTYPE html> <html> <head> <title>ISMAP Hyperlink Example</title> </head> <body> <p>Click on the Image to get its coordinates. </p> <a href = "/cgi-bin/ismap.cgi" target="_self"> <img ismap src="/images/logo.png" alt="Tutorials Point" border="0"/> </a> </body> </html>
If you execute the above example it will display the "tutorialspoint" logo and if the user clicks 62 pixels over and 32 pixels down from the upper-left corner of the following image, it will redirect us to a new page where we can see the coordinates inside the address bar. Then the browser sends the following search parameters to the web server −
/cgi-bin/ismap.cgi?20,30
Now, these passed coordinates can be processed in either of the following two ways −
- Using a CGI (or PHP file if you are not using CGI file)
- Using a map file
A CGI or PHP file
Following is the perl code for ismap.cgi script which is being used in the above example −
#!/usr/bin/perl local ($buffer, $x, $y); # Read in text $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; if ($ENV{'REQUEST_METHOD'} eq "GET") { $buffer = $ENV{'QUERY_STRING'}; } # Split information into name/value pairs ($x, $y) = split(/,/, $buffer); print "Content-type:text/html\r\n\r\n"; print "<html>"; print "<head>"; print "<title>ISMAP</title>"; print "</head>"; print "<body>"; print "<h2>Passed Parameters are : X = $x, Y = $y </h2>"; print "</body>"; print "</html>"; 1;
Because we are able to parse passed coordinates, we can put a list of if conditions to check passed coordinates and send the appropriate linked document back to the browser.
A map file
A map file can be used to store the location of HTML files that we want the reader to be taken to when the area between the identified coordinates is "clicked".
We will redirect the users to ismap.map file which holds the location of various tutorials available on the Tutorialspoint. The content of this file is shown below −
default http://www.tutorialspoint.com rect http://www.tutorialspoint.com/html 5,5 64,141 rect http://www.tutorialspoint.com/css 91,5 127,196 circle http://www.tutorialspoint.com/javscript 154,150,59
So let's rewrite the above example using ismap.map file:
<!DOCTYPE html> <html> <head> <title>ISMAP Hyperlink Example</title> </head> <body> <p>Click following link</p> <a href = "/html/ismap.map" target="_self"> <img ismap src = "/images/logo.png" alt="Tutorials Point" border="0"/> </a> </body> </html>