With HTML image maps, you can create clickable areas on an image.
Image Maps
Sep 02, 2019 Creating the Image Map. First, we'll add an image to a topic. Place your cursor where you want to insert the image. Click Insert Image to insert the desired image into the topic. Right-click the image and select Image Map to open the Image Map Editor. Next, we'll need to mark each of the areas of the image map to be hyperlinked. An image-map is an image with clickable areas. The required name attribute of the map element is associated with the 's usemap attribute and creates a relationship between the image and the map. The map element contains a number of elements, that defines the clickable areas in the image map. Place your cursor where you want to insert the image. Click Insert Image to insert the desired image into the topic. Right-click the image and select Image Map to open the Image Map Editor. Next, we'll need to mark each of the areas of the image map to be hyperlinked.
The HTML tag defines an image map. An image map is an image with clickable areas. The areas are defined with one or more
tags.
Try to click on the computer, phone, or the cup of coffee in the image below:
Example
Here is the HTML source code for the image map above:
How Does it Work?
The idea behind an image map is that you should be able to perform different actions depending on where in the image you click.
To create an image map you need an image, and some HTML code that describes the clickable areas.
The Image
The image is inserted using the tag. The only difference from other images is that you must add a
usemap
attribute:
The usemap
value starts with a hash tag #
followed by the name of the image map, and is used to create a relationship between the image and the image map.
Create Image Map
Then, add a element.
Macbook expansion drive. The element is used to create an image map, and is linked to the image by using the required
name
attribute:
The name
attribute must have the same value as the 's
usemap
attribute .
The Areas
Then, add the clickable areas.
A clickable area is defined using an element.
Shape
You must define the shape of the clickable area, and you can choose one of these values:
rect
- defines a rectangular regioncircle
- defines a circular regionpoly
- defines a polygonal regiondefault
- defines the entire region
What is the grab app on mac. You must also define some coordinates to be able to place the clickable area onto the image.
Shape='rect'
The coordinates for shape='rect'
come in pairs, one for the x-axis and one for the y-axis.
So, the coordinates 34,44
is located 34 pixels from the left margin and 44 pixels from the top:
The coordinates 270,350
is located 270 pixels from the left margin and 350 pixels from the top:
Now we have enough data to create a clickable rectangular area:
Example
This is the area that becomes clickable and will send the user to the page 'computer.htm':
Shape='circle'
To add a circle area, first locate the coordinates of the center of the circle:
337,300
Then specify the radius of the circle:
44
pixels
Now you have enough data to create a clickable circular area:
Example
This is the area that becomes clickable and will send the user to the page 'coffee.htm':
Shape='poly'
The shape='poly'
contains several coordinate points, which creates a shape formed with straight lines (a polygon).
This can be used to create any shape.
Like maybe a croissant shape!
How can we make the croissant in the image below become a clickable link?
We have to find the x and y coordinates for all edges of the croissant:
List making software mac. The coordinates come in pairs, one for the x-axis and one for the y-axis: Crossing date line patch.
Example
This is the area that becomes clickable and will send the user to the page 'croissant.htm':
Image Map and JavaScript
A clickable area can also trigger a JavaScript function.
Add a click
event to the element to execute a JavaScript function:
Example
Here, we use the onclick attribute to execute a JavaScript function when the area is clicked:
<br>function myFunction() {<br> alert('You clicked the coffee cup!');<br>}<br>
Chapter Summary
- Use the HTML
element to define an image map
- Use the HTML
element to define the clickable areas in the image map
- Use the HTML
usemap
attribute of theelement to point to an image map
HTML Image Tags
Tag | Description |
---|---|
Defines an image | |
Defines an image map | |
Defines a clickable area inside an image map | |
Defines a container for multiple image resources |
Djay pro 2 award winning dj software 2 1. For a complete list of all available HTML tags, visit our HTML Tag Reference.