As you know, a special HTML markup language (Hypertext Markup Language) is used to create web pages and even entire sites, but without photographs and various images, each site would be simply structured and boring text. That is why a special code is used to add images to the site, which is extremely easy to use and allows you to insert a picture in HTML at a specific place on the page or use it as a background.
Where to begin?
In order to write code, you need to decide in which program to do this. Now there are a huge number of them, one of the most famous is NotePad ++. It has a number of functions that are very useful when writing code, allows you to identify errors and not get confused in tags. However, if you do not have the opportunity to resort to the help of specialized programs, you can use a simple notebook, the code will not change.
Which tag do we need
Having decided on a program for writing code, you need to understand what to write in it, how to insert a picture in HTML in notepad or any other program. You should start with the <img /> tag. This tag announces the image in the HTML document, it is single and does not require closing.
What's next?
We declared in the code that we were going to use the image, but we did not specify it yet. So how to insert a picture in HTML? To do this, we need the src attribute, which is used with our tag. This attribute sets the location of our image, regardless of whether it is on any site or on our computer.
- If the image will be located on a third-party site, then our code will look like this:
<img src="//coder-booster.ru/images/main-logo.png" />
- If the image is in the same folder as our HTML file, the code will look like this:
<img src=" .jpg" />
Alternative text
The <img /> tag has another attribute - alt. Use it so that the description of the image is visible in the browser if, for any reason, the image itself cannot be loaded. Its presence is also desirable so that visually impaired people can know what kind of image is on the site, because the text in the value of this attribute is voiced by screen readers. The resulting code with src and alt attributes would look like this:
<img src=" .jpg" alt=" " />
Tooltips
Among other things, the <img /> tag has another title attribute. Thanks to this attribute, when you hover over an image, alternative text will be displayed in a tooltip. However, this function is only supported by Internet Explorer, so that such prompts pop up in other browsers, special plugins will be required. Tooltips are used together with the alt attribute, they are optional, but when using them, the code will look like this:
<img src=" .jpg" alt=" " title=" " />
Image size
We figured out how to insert a picture into text with HTML. But what if we want to make the image a little bigger or smaller? For this, HTML provides special attributes: width (width) and height (height). The values ββof these attributes can be either in percent or in pixels. If you set the width in pixels and the height in percent, then the code will take the following form:
<img src=" .jpg" width="100px" height="25%" />
If you specify only one of the size attributes, the second will be calculated automatically, but in such a way as to keep the aspect ratio of the image. When specifying both parameters, it is important to remember that if the sizes exceed the original, the picture will stretch, and if the sizes are smaller, it will shrink.
Picture as background
But what if we want to use an image not in text, but to insert a picture on the background in HTML, how to do it? To do this, we need the <body> tag, without which no HTML document can do. It is in it that all the visible contents of the document are enclosed, and its attributes can specify the size, font color, including the background. Inserting a picture in HTML as a background image is very simple, for this we will need to use the background attribute. This code will look like this:
<body background=" .jpg"> ... </body>
When forming the background of a web page, it is better to use such images with which you can achieve interesting visual effects, but which would not interfere with the normal perception of the text. However, keep in mind that you may need to change the size and color of your font to make it easier to read.
Text Wrap
Sometimes it is necessary that the picture is next to the text that would bend around it in one way or another. But if you insert the picture just inside the line, then graphically it will look ugly, the text will be broken inaccurately. So how to insert a picture in HTML so that the image fits organically into the page design? To do this, we need the align attribute of the <img /> tag. This attribute can take two values: left and right.
When using the left value, the image will be placed to the left of the text, and when using the right attribute, respectively, to the right. This code will look like this:
<img src=" .jpg" align="left" /> <img src=" .jpg" align="right" />
If we need to have the text located between two images, the code will look like this:
<img src=" .jpg" align="left" /> <img src=" .jpg" align="right" />
And after this code will be located the text that needs to be enclosed between these two pictures.
Images allow you to diversify the site, make it brighter, more attractive and more memorable, but do not forget that too many pictures will slow down the loading of the site and will distract from the text.