How to use the img tag of html
This article mainly introduces the html img tag how to use the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this html img tag how to use the article will have a harvest, let's take a look.
The img tag of html can be used to display an image on a web page. It is an empty tag that contains only attributes and no closing tag.
Attributes of the img tag
The img tag can contain: src attribute, height and width attribute, alt attribute. The src attribute and the alt attribute are important attributes of the HTML img tag.
Let's take a look at these attributes of the img tag in detail:
1. Src attribute
The src property is a necessary property that describes the source or path of the image, indicating where the browser looks for the image on the server.
So get the image? There are two situations:
1) get the images in the same folder
When the HTML file and the image are in the same folder, like this:
We can enter the image name directly in the src attribute, such as:
one
two
three
four
Img tag
Effect picture:
2), in another directory / folder, such as:
You can access the image like this:
one
two
three
four
Img tag
The effect picture is like the picture above.
If it's more complicated, when we put the image of 1.jpg in the local disk E-> img folder, we can display the picture like this:
one
< img src="E:/img/1.jpg">2. Height and width properties
The height and width attributes of the img tag can be used to set the height and width of the image, for example:
one
Effect picture:
The height and width of the img tag image can also be set through css, for example:
one
two
three
four
Img {
Width:450px
Height:300px
}
3. Alt attribute
When the image cannot be displayed on the browser, you can use the alt property to display alternate text.
Ex.: I want to display 1.jpg pictures, but there is no one in the folder
one
two
Img tag
Effect picture:
This is the end of the article on "how to use the img tag of html". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to use the img tag of html". If you want to learn more, you are welcome to follow the industry information channel.