November 20, 2026
What is the HTML <img /> tag used for?
In web design, images are usually found in webpages. It enhances webpage’s view and quality. So if you want to include images in a website you can use <img /> tag. <img /> tag does not require its closing tag because it is an empty tag.
For including any particular image in a website, you must include URL of the image in "src" attribute of <img /> tag. URL is a path of any image or file, which provides information about the address of a file (src="http://www.abc.com/images /jjjjjj.gif").
Syntax
<img src="URL" />
In above mentioned code img is a tag name and "src" is an attribute of img tag, which stands for source for this attribute you will have to provide the URL of the image you want to open.
Alt Attribute
The alt attribute stands for alternative text. It provides a description of an image if it fails to load and helps screen readers describe the image to visually impaired users. In this attribute you can specify text which will be display when your image unable to get display in webpage for some reason (image not found, invalid URL, user disabled image files in browser etc).
Code
<img src="http://eae.com/images/jjjjj.gif" alt="Unable to open image" />
In above example if image does not found then text message which described in alt attribute "Unable to open image" will be appeared in the webpage instead of image.
Manage image size (Height and Width Attribute)
You can manage image size with the help of height and width attribute of img tag. Through these attribute you can increase and decrease image size.
Code
<img src="http://eae.com/images/jjjjj.gif" width="304" height="228" />
Alignment of image
You can control the position of an image on a webpage using alignment properties. Horizontal alignment determines whether an image appears on the left, right, or center of the page, while vertical alignment determines how the image is positioned relative to the surrounding text or other elements.
- align (Horizontal)
- valign (Vertical)
Code
<img src="http://eae.com/images/jjjjj.gif" align="left" />
<img src="http://eae.com/images/jjjjj.gif" align="right" />
<img src="http://eae.com/images/jjjjj.gif" align="center" />
<img src="http://eae.com/images/jjjjj.gif" align="top" />
<img src="http://eae.com/images/jjjjj.gif" align="middle" />
<img src="http://eae.com/images/jjjjj.gif" align="bottom" />
Make image as links
If you want to make image as link so for it you can write image tag between <a></a> tags, image will become a link.
Code
<a href="http://www.abc.com/" />
<img src="jjjjj.gif">
</a>
Border
The border attribute is used to add a border around an image and specify its thickness. This helps make the image stand out and gives it a clear outline.
Code
<img src="jjjjj.gif" border="5" />
Space Around
You can easily give space over and under your images on your webpage with the help of Vspace attribute. In the same method you can provide space to left and right side of the image using the Hspace attribute. Below is an example present which explain these attributes:
<img src="jjjjj.gif" Hspace="30" Vspace="10" />
As you can see that, these settings provide spacing around your image.
FAQ
1. Is the <img /> tag an empty tag?
Yes, the <img /> tag is an empty or void element. It does not require a closing tag.
2. What is the purpose of the src attribute in an image tag?
The src attribute specifies the URL or path of the image that you want to display on a webpage.
3. What is the alt attribute in the HTML image tag?
The alt attribute stands for alternative text. It provides a description of an image if it cannot be displayed and helps screen readers describe the image.