HTML Image Tutorials
1. HTML Image
HTML img tag is used to display image on the web page. HTML img tag is an empty tag that contains attributes only, closing tags are not used in HTML image element.
Let's see an example of HTML image.
<h2>HTML Image Example</h2>
<img src="good_morning.jpg" alt="Good Morning Friends"/>
Good Morning Friends
3. Attributes of HTML img tag
The src and alt are important attributes of HTML img tag. All attributes of HTML image tag are given below.
It is a necessary attribute that describes the source or path of the image. It instructs the browser where to look for the image on the server.
The location of image may be on the same directory or another server.
The alt attribute defines an alternate text for the image, if it can't be displayed. The value of the alt attribute describe the image in words. The alt attribute is considered good for SEO prospective.
It is an optional attribute which is used to specify the width to display the image. It is not recommended now. You should apply CSS in place of width attribute.
It h3 the height of the image. The HTML height attribute also supports iframe, image and object elements. It is not recommended now. You should apply CSS in place of height attribute.
8. Use of height and width attribute with img tag
You have learnt about how to insert an image in your web page, now if we want to give some height and width to display image according to our requirement, then we can set it with height and width attributes of image.
9. Example :
<img src="animal.jpg" height="500" width="700" alt="animal image">
10. Output :
11. Use of alt attribute
We can use alt attribute with tag. It will display an alternative text in case if image cannot be displayed on browser. Following is the example for alt attribute:
<img src="animal.png" height="500" width="700" alt="animal image">
13. How to get image from another directory/folder?
To insert an image in your web, that image must be present in your same folder where you have put the HTML file. But if in some case image is available in some other directory then you can access the image like this:
<img src="D:/images/animal.png" height="500" width="700" alt="animal image">
In the above statement we have put the image in local disk D------>images folder------>animal.png.
We can also link an image with other page or we can use an image as a link. To do this, put <img> tag inside the <a> tag.
<a href="https://www.samtpoint.com/what-is-AI"><img src="AI.jpg" height="100" width="100"></a>
17. Supporting Browsers