Are you looking to build a stunning Masonry Grid Image Gallery using just HTML & CSS? ๐ธโจ In this tutorial, weโll guide you through creating a fully responsive, stylish, and easy-to-implement image gallery that beautifully arranges images in a masonry layoutโno JavaScript needed!
๐ Why Choose a Masonry Grid Layout?
A masonry grid is perfect for showcasing images, whether you’re building a portfolio, photography website, or an e-commerce store. Unlike traditional grids, masonry layouts dynamically arrange images in a visually appealing way, making use of available space efficiently.
โ Features of This Image Gallery:
โ Fully Responsive Design โ Works on all devices ๐ฑ๐ป
โ Uses CSS Grid & Flexbox โ No JavaScript required
โ Perfect for Portfolios & Photography Websites ๐ท
โ Easy to Customize & Implement ๐จ
๐ฅ Step-by-Step Guide to Creating a Masonry Grid Gallery
1๏ธโฃ Setting Up the HTML Structure
Start by creating a simple HTML file and adding a container for your images:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Masonry Grid Gallery</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="gallery">
<img src="1.jpg" alt="Image 1">
<img src="2.jpg" alt="Image 2">
<img src="3.jpg" alt="Image 3">
<img src="4.jpg" alt="Image 4">
<img src="5.jpg" alt="Image 5">
<img src="6.jpg" alt="Image 6">
</div>
</body>
</html>
2๏ธโฃ Styling the Gallery with CSS Grid
Now, letโs add CSS to create the masonry effect:
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
}
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
grid-auto-rows: 10px;
gap: 10px;
max-width: 800px;
padding: 10px;
}
.gallery img {
width: 100%;
border-radius: 5px;
object-fit: cover;
grid-row: span 20;
transition: transform 0.3s ease-in-out;
}
.gallery img:hover {
transform: scale(1.05);
}
๐ฏ How It Works
- CSS Grid dynamically arranges images in columns and rows.
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));ensures images fit different screen sizes.grid-auto-rows: 10px;creates the masonry effect by making row heights flexible.grid-row: span 20;ensures images span different rows based on content.- Hover effect adds a slight zoom when you hover over an image.
๐ Final Thoughts
With just HTML & CSS, youโve built a beautiful, responsive masonry grid gallery! ๐ This layout is perfect for showcasing portfolios, blogs, and photography collections without relying on JavaScript.
Want to learn more? Check out our video tutorial:
๐ฅ Watch the Full Guide on YouTube:
๐ป Get the Source Code on GitHub:
๐ Madras Academy GitHub Repo
๐ฅ Follow for More Web Development Tutorials!
๐ Donโt forget to LIKE ๐, SHARE ๐ & SUBSCRIBE ๐ for more awesome web design content.
Happy Coding! ๐๐ป
