


Khusboo Tayal
Images play a vital role in making websites visually engaging and informative. In HTML, images are added using the <img> tag, which embeds an image into a web page.
The <img> tag is an empty tag, meaning it does not have a closing tag. It uses attributes to define the image source and its properties.
Basic Syntax:
<img src="image.jpg" alt="Description of the image">
Example:
<img src="sunset.jpg" alt="Beautiful sunset over the hills">
Example with dimensions:
<img src="logo.png" alt="Website Logo" width="200" height="100">
You can also use an image hosted on another website:
<img src="https://example.com/image.jpg" alt="External Image">
Be cautious when hotlinking — always ensure you have permission to use externally hosted images.
To make images responsive:
img {
max-width: 100%;
height: auto;
}This ensures that the image scales according to the screen size.
HTML images enhance your webpage by making it more engaging and visually appealing. Using the <img> tag effectively with the right attributes ensures your website is accessible, fast, and search engine friendly.
Q1: What is the purpose of the alt attribute in an image tag?
A: The alt attribute provides a textual description of the image, which helps screen readers for visually impaired users and also serves as fallback text if the image fails to load.
Q2: Can I use SVG files as images in HTML?
A: Yes, SVG files are excellent for vector graphics and icons. They are scalable and maintain quality on all screen sizes.
Q3: Is the <img> tag self-closing?
A: Yes, the <img> tag does not require a closing tag. It is written as a self-contained element.
Q4: How can I center an image on a web page?
A: You can use CSS:
img {
display: block;
margin-left: auto;
margin-right: auto;
}Q5: Can I link an image to another page?
A: Yes, wrap the image in an anchor (<a>) tag:
<a href="about.html"> <img src="about-thumbnail.jpg" alt="About Us"> </a>
Learn how to use AI to build, market and grow your business. Subscribe our newsletter to get AI tips, tools and prompts in your inbox to power your marketing, sales and business.
#html #htmlimages #htmlimgtag #htmltutorial #learnhtml #webdevelopment #htmlforbeginners #imageoptimization