The cords attribute of the <area> element is used to set the coordinates of area in image map. Use the attribute with shape attribute and set the size & shape of an area.
Following is the syntax
<area coords="value">
Under the value above, you can set the following coordinates with different parameters −
x1,y1,x2,y2 | Coordinates of the top-left and bottom-right corner of the rectangle (shape="rect") |
x,y,radius | Coordinates of the circle center and the radius (shape="circle") |
x1,y1,x2,y2,..,xn,yn | Coordinates of the edges of the polygon. |
Let us now see an example to implement the cords attribute of the <area> element −
Example
<!DOCTYPE html> <html> <body> <h2>Learning</h2> <p>Learn these technologies with ease....</p> <img src = /images/usemap.gif alt = "usemap" border = "0" usemap = "#tutorials"/> <map name = "tutorials"> <area shape = "poly" coords = "74,0,113,29,98,72,52,72,38,27" href = "/perl/index.htm" alt = "Perl Tutorial" target = "_blank" /> <area shape = "rect" coords = "22,83,126,125" alt = "HTML Tutorial" href = "/html/index.htm" target = "_blank" /> <area shape = "circle" coords = "73,168,32" alt = "PHP Tutorial" href = "/php/index.htm" target = "_blank" /> </map> </body> </html>
Output
In the above example, we have set the map on the following image −
<img src = /images/usemap.gif alt = "usemap" border = "0" usemap = "#tutorials"/>
Now, we have set the map and area within it for shape −
<map name = "tutorials"> <area shape = "poly" coords = "74,0,113,29,98,72,52,72,38,27" href = "/perl/index.htm" alt = "Perl Tutorial" target = "_blank" /> <area shape = "rect" coords = "22,83,126,125" alt = "HTML Tutorial" href = "/html/index.htm" target = "_blank" /> <area shape = "circle" coords = "73,168,32" alt = "PHP Tutorial" href = "/php/index.htm" target = "_blank" /> </map>
While setting the area, we have set the coordinates of the area with the cords attribute −
<area shape = "rect" coords = "22,83,126,125" alt = "HTML Tutorial" href = "/html/index.htm" target = "_blank" />