The tag is responsible for inserting images into an HTML document.
and its attributes, the main of which can be considered src, which specifies the address of the image. It is required because if you don't specify where to get the image, the browser won't be able to know what to add to the page.
The simplest case of inserting a picture will look like this (the image is called image.png and is located in the same folder as the HTML document):
If you do not specify any additional attributes to the image, it will be displayed in full size, but this is not always necessary. Fortunately, the desired size of the picture can be set using attributes width(indicates the width) and height(determines the height). Dimensions can be recorded either in pixels or percentages. In the second case, the browser will calculate the percentage from the parent element (for example, the paragraph into which the picture is inserted).
We talked about how to make a picture a link in the previous article. However, HTML allows you to set not just one link on one image, but several at once. As a result, the user, clicking on different places in the same picture, will go to different Internet addresses. This feature can be used, for example, to create eye-catching menus, interactive tests, or visual graphic models.
To create an image map (this is the name of the described feature), you will need the following tags and attributes:
To make it clear how to use all of the above, I will give a basic example. There is a drawing map.jpg. It needs to be divided into two active areas. Clicking on the top part (green) will open the Odnoklassniki website, while the bottom part (blue) will lead to VKontakte. Links should open in a new tab. To create a map, follow the following steps.
1. Insert the image onto the page and link it to the future card (it will be called social), for which we write the following code:
2. We determine future active areas in the picture and their corresponding coordinates. This can be done in Paint, Photoshop or any other graphics editor. In our case, everything is elementary: the rectangles are equal in height (114 pixels) and width (384 pixels).
3. Let’s start creating a map: open the tag and write its name in the name attribute, which must match the value of the usemap property of the image itself:
4. Using area tags, we define active areas:
5. Close the card:
The result of the work was a picture, clicking on different parts of which leads to the opening of different social networks, and this is the HTML code: