📸 HTML Image Gallery Tutorial for Beginners
Image galleries make your website more beautiful and professional. In this tutorial, you will learn how to create different types of image galleries using HTML and CSS.
📌 1. Simple HTML Image Gallery
This is the most basic gallery layout.
<div>
<img src="image1.jpg" width="200">
<img src="image2.jpg" width="200">
<img src="image3.jpg" width="200">
</div>
✔ Explanation
- All images are inside a <div>
- Each image has the same width
- They appear in a row
📌 2. Responsive Image Gallery (CSS Grid)
This gallery automatically adjusts on mobile and PC.
<style>
.gallery {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
}
.gallery img {
width: 100%;
border-radius: 10px;
}
</style>
<div class="gallery">
<img src="image1.jpg">
<img src="image2.jpg">
<img src="image3.jpg">
<img src="image4.jpg">
</div>
✔ Why This Is Good
- Fully responsive
- Automatically adjusts number of columns
- Perfect for modern websites
📌 3. Hover Effect Gallery
Add zoom effect on mouse hover.
<style>
.gallery img {
width: 100%;
border-radius: 10px;
transition: 0.3s;
}
.gallery img:hover {
transform: scale(1.05);
box-shadow: 0 0 10px rgba(0,0,0,0.4);
}
</style>
<div class="gallery">
<img src="img1.jpg">
<img src="img2.jpg">
<img src="img3.jpg">
</div>
📌 4. Image Gallery with Captions
Useful when you want to label images.
<style>
.gallery-item {
text-align: center;
}
.gallery-item img {
width: 100%;
border-radius: 10px;
}
.caption {
margin-top: 5px;
font-weight: bold;
}
</style>
<div class="gallery">
<div class="gallery-item">
<img src="img1.jpg">
<div class="caption">Beautiful Sunset</div>
</div>
<div class="gallery-item">
<img src="img2.jpg">
<div class="caption">Mountain View</div>
</div>
</div>
📌 5. Click-to-Open Large Image (Lightbox)
Clicking an image opens a bigger view — without JavaScript!
<style>
.lightbox img {
width: 100%;
border-radius: 10px;
cursor: pointer;
}
.lightbox:target {
position: fixed;
top: 0; left: 0;
width: 100%; height: 100%;
background: rgba(0,0,0,0.9);
display: flex;
justify-content: center;
align-items: center;
}
.lightbox:target img {
width: 90%;
max-width: 600px;
}
</style>
<a href="#img1" class="thumb">
<img src="photo1.jpg" width="200">
</a>
<div id="img1" class="lightbox">
<a href="#">
<img src="photo1.jpg">
</a>
</div>
📌 6. Best Practices for Image Galleries
- Use WEBP format for fast loading
- Compress images for speed
- Use same aspect ratio for cleaner look
- Always add ALT text for SEO
- Host images inside Blogger for best performance
🎉 Final Words
Now you know how to create:
- Simple gallery
- Responsive gallery
- Hover animation gallery
- Gallery with captions
- Lightbox image viewer
This is perfect for portfolios, wallpapers, products, or image blogs.

Comments
Post a Comment