To understand how to insert an image in HTML, you have to fix in mind a key concept: the images you see on the Web pages of the sites you visit, blogs and forums are not incorporated into the latter but are called from external locations. This means that each photo has a unique address, which allows it to be tracked and viewed.
The address of an image is composed as follows: at the beginning there is the address of the Web space on which the file is hosted (eg. https://www.configurehow.com/) and then there is the name of the image complete with extension (eg. image.jpg). The direct address of an image on the web, therefore, must have a composition of the type https://www.[site domain]/[image name and extension], in the case of our example https://www.configurehow.com/immagine.jpg.
At this point, you may be wondering how to recall the address of an image on a web page, in order to make the photo visible to the public? Nothing simpler! Just use the tag img followed by the attribute src = followed byaddress of the image to be inserted in the page enclosed in quotation marks. Continuing with the example above, to insert an image into a web page, you should use the following formatting.
If you want, you can also add the tag alt to the image, so as to configure the alternative text (a kind of Description of the uploaded file) to be shown in the event that this is not available (for example due to errors in connection to the server or deletion of the photo from its original position), which also favors indexing of the image by the search engines search (as I have already explained to you in another tutorial). The alt tag is inserted immediately after the img element, as in the example below.
As you may have noticed, in the examples I just gave you I didn't close the img tag with the tag : the reason is that there is no need to do this, as img is an "empty" tag. However, it might be practical to insert one space it's one slash / before the symbol major>, so as to make the image also compatible with the XHTML, the markup language that associates some properties of XML with characteristics of HTML.
Now that you are familiar with the use of the img tag, you will surely be interested in knowing how to move it right, left and center. In the next few lines I'll show you just that: how to align an image to the center, left, right, top or bottom of the page that contains it, and also how to resize it.
To align the images, all you have to do is use the formatting we saw in the previous lines and add the variable to it align =, followed by the type of arrangement you want the photo to adopt: center, to align the image in the center; left, to align it to the left; right, to align it to the right; bottom, to arrange the photo on the lower right part of the first line of text; middle, to arrange the photo on the central part to the right of the first line of text; top, to arrange it on the top right of the first line of text.
As mentioned above, through the HTML code it is also possible to resize images (only visually, without changing the size of the original file) and specify the spacing they must have with respect to the other elements that make up the Web page in which they are inserted.
To indicate the size that an image must have, variables must be used width ed height specifying the values in pixels, while for the spacing it is necessary to use the voice hspace to indicate horizontal spacing e vspace to indicate the vertical one. Below I give you the example of a photo of 300 x 200 pixels with a vertical and horizontal spacing of 20 pixels.
Did you see how simple it was to align and resize images in HTML? As I said, it is an operation that is anything but complicated, you just need to know the tags to use and use the variables you prefer to make the uploaded photo assume the desired position.
Insert an image in HTML as a background
want insert an image in HTML and use it as a background of the page? This is also possible, but to proceed you will not have to resort to the img tag, but to the tag body followed by the attribute background and from path of the image enclosed between quotation marks. I guarantee you that there is nothing complicated in carrying out this operation: the example below can prove it to you.
Since the image inserted as a background on the Web page will be repeated both horizontally and vertically, I recommend that you adopt this technique only if you have images that, even if repeated, allow you to obtain a pleasant aesthetic result, to understand a sort of mosaic effect.
Let's conclude this guide by discovering together how associate a link to an image in HTML, so that clicking on it will redirect you to a specific web page. To add an Internet link to an image, all you have to do is prepend the tag a href = followed byaddress of the site to link to the image code. Here is an example where the image we have used so far in this tutorial links to the address www.sitodesample.it:
I would say that's it with that! Now you know all the basic rules for inserting an HTML image into blogs and websites. It takes very little to learn, did you notice? And starting from here you can deepen the topic by discovering many other functions that can be exploited using the HTML language. Have fun!How to insert an image in HTML