CSE 190m Special Sections

Section #2 - image maps

By Tanner Means. Special guests: Moony, Wormtail, Padfoot and Prongs

Image Map

  1. The Basics
  2. Required Elements
  3. Sample Code
  4. An Example
  5. Other Possibilities

The Basics

Image Mapping allows you to define clickable areas in an image.

da map

Image credit: Webaid, NC state gov

Required Elements: <img> and <map>

Add the usemap attribute to the <img> you want to map.

usemap's value should be:
"#" + the map's name attribute attribute of the <map> element.

<img src="/path/to/img.jpg" id="myid" usemap="#mapname" alt="myimage">

The <map> tag only has the name attribute.

<map name="mapname">
	area tags (next slide)

Required Elements: <area>

Every area tag corresponds to a clickable area in the image

<area shape="rect" coords="0,0,82,126" href="" alt="Wiki" />
Attribute Value Description
shape default
Specifies the shape of an area
coords coordinates Specifies the coordinates of an area
href URL Specifies the hyperlink target for the area

Sample Code

<img src="planets.gif" width="145" height="126" 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" />

Values for the shape and coords attribute:

Value Description Coordinate attribute value
default Specifies the entire region ""
rect Defines a rectangular region "x1,y1,x2,y2"
circle Defines a circular region "x,y,radius"
poly Defines a polygonal region "x1,y1,x2,y2,..,xn,yn"

An Example

Let's map Obama's facial features to pertinent websites

Link to example

Other Possibilities

So what could we do with this?

Here's what I thought of