- 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
HTML - coords Attribute
The HTML coords attribute is used to set the coordinates of an area in an image map. It is used together with the shape attribute to specify the size, shape, and placement of an area. The coordinates of the top-left corner of an area are (0,0).
The coords attribute is not used within the <area> element if the shape is set to default.
How to get coordinates of an image
Following are steps to get coordinates of an image −
- Open any image on the Paint app.
- Click on resize and change resize unit from percentage to pixel.
- Give the same pixel width and Height to your image in HTML.
- Highlight the top-left corner of that part of the image, and you will see the coordinates in your paint application's bottom left corner in px(x1, y1).
- Highlight the bottom-right corner of that part of the image, and you will see the coordinates in your paint application's bottom left corner in px(x2, y2).
Syntax
Following is the syntax for HTML 'coords’ attribute −
<area coords = "coordinates_values">
Following are the values and descriptions of the coords attribute −
Sr.No | coords Attribute & Descriptions |
---|---|
1 | X1, y1, x2, y2 Specifies the coordinates of the top-left and bottom-right corners of the rectangle (shape = "rect"). |
2 | X, y, radius Specifies the coordinates of the circle and the radius (shape = "circle"). |
Example
In the following example, we are using the HTML ‘coords’ attribute within the image <area> element to set coordinates of an area in an image.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'coords' attribute</title> </head> <body> <p>Click on the HTML, CSS and JavaScript Logo to redirect on different page.</p> <img src="images (1).png" usemap="#mymap" width="700" height="231"> <map name="mymap"> <area shape="rect" coords="7, 38, 142, 281" href="html logo.html" alt="HTML"> <area shape="rect" coords="280, 48, 416, 223" href="css logo.html" alt="CSS"> <area shape="rect" coords="562, 50, 694, 222" href="js log.html" alt="JS"> </map> </body> </html>
html logo.html
<!DOCTYPE html> <html lang="en"> <head> <title>HTML</title> </head> <body> <img src="html logo.jpg" alt="HTML logo"> </body> </html>
css logo.html
<!DOCTYPE html> <html lang="en"> <head> <title>CSS</title> </head> <body> <img src="css logo.png" alt="Css Logo"> </body> </html>
Js logo.html
<!DOCTYPE html> <html lang="en"> <head> <title>Js</title> </head> <body> <img src="js logo.png" alt="javaScript logo"> </body> </html>
On running the above code, it will generate an output consisting of the images displayed on the webpage. when the user clicks on the individuals images it further open to open single image.
To Continue Learning Please Login
Login with Google