HTML: Image Map Basics

By Xah Lee. Date: . Last updated: .

Sometimes you want a image to have sensitive areas that will have different behavior. This is done with HTML Image map.

Here's a example.

Horrow Show
comics
comics by Nicholas Gurewitch

Move your mouse over the big eye, then a alert box will popup.

How It Works

First, you define a “map” of the image with the “map” tag and “area” tag, like this:

<map name="map1">
<area href="javascript:void(0);"
 onmouseover="alert('Horror Show!');"
 alt="Horrow Show"
 shape="circle" coords="569,75,20">
</map>

Then, in your image tag, use the usemap attribute to call your map, like this:

<img usemap="#map1" src="funnyPic.png" alt="comics">

The key to do this is by the map tag, and inside it you can have several area tags, which can have attributes of “shape”, one of {circle, rect, poly}. Each shape has coords attribute to specify its boundary.

You can also define other shapes. Here's example:

<map name="…">

<area href="…" alt="…" shape="circle" coords="‹x›,‹y›,‹radius›" />

<area href="…" alt="…" shape="rect" coords="‹upper left corner x›, ‹upper left corner y›, ‹lower right coner x›, ‹lower right coner y›" />

<area href="…" alt="…" shape="poly" coords="‹at least 6 numbers, or more, must be even count›" />

</map>

HTML Basics

  1. HTML Basics
  2. HTML5 Tags
  3. Case Sensitivity
  4. Allowed Characters
  5. Charset and Encoding
  6. Self-Closing Tags
  7. Multiple Class Value
  8. HTML Entity List

HTML Table

  1. HTML Table Examples
  2. HTML Table, thead, tbody, tfoot
  3. HTML Table, colgroup, col
  4. Styling HTML Table with CSS
  5. CSS: 3 Columns Page Layout
  6. Pure CSS Table

Misc

  1. Viewport Meta
  2. the Root Element
  3. iframe
  4. video
  5. audio
  6. figure
  7. dl, dt, dd
  8. s strike del
  9. time
  10. meter
  11. progress
  12. q
  13. address
  14. canvas
  15. ruby
  16. HTML5 Custom Data Attribute
  17. Big Tag
  18. Image Maps
  19. Marquee, Scrolling Text
  20. How to Markup Subtitle
  21. Meta Language Tag Obsolete
  22. Browser Auto Refresh

HTML4 Frameset

  1. HTML: Split Windows; Frameset
  2. HTML Nested Frameset
Like it? Help me by telling your friends. Or, Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. CSS
  3. JavaScript
  4. JS Obj Ref
  5. DOM
  6. SVG
  7. Blog