HTML Images Tutorial
The <img> tag is used to display images on a webpage. In this tutorial, you'll learn how to add images, resize them, add borders, captions, and more.
1. Basic Image Tag
The simplest way to add an image is by using the src and alt attributes.
<img src="image.jpg" alt="My Image">
Attributes:
- src → Image URL
- alt → Text shown if image fails to load
2. Image Size (width & height)
You can resize an image using width or height.
<img src="photo.jpg" width="300" height="200">
3. Responsive Images
Responsive images automatically adjust to device size.
<img src="photo.jpg" style="width:100%;max-width:400px;">
4. Add Border to Images
<img src="file.jpg" style="border:3px solid #333;">
5. Rounded & Circular Images
<img src="profile.jpg" style="border-radius:50%;">
6. Add Caption with <figure> and <figcaption>
<figure>
<img src="image.jpg" alt="Sample">
<figcaption>This is a caption.</figcaption>
</figure>
7. Clickable Images (Image as a Link)
<a href="https://example.com">
<img src="image.jpg" width="200">
</a>
8. Lazy Loading Images (Improves Speed)
<img src="big-image.jpg" loading="lazy">
loading="lazy" means the image loads only when user scrolls near it.
9. Using GIFs
<img src="funny.gif" alt="Funny Animation">
10. Add Hover Effect to Images
<style>
.img-hover:hover {
transform: scale(1.1);
transition: 0.3s;
}
</style>
<img src="image.jpg" class="img-hover">
Conclusion
Images make your website more attractive and informative. You learned how to add, style, resize, animate, and improve images using HTML.

Comments
Post a Comment