A CSS Image Gallery is a layout where multiple images are displayed in a clean, organized grid or flexible row/column arrangement using HTML and CSS only. With Flexbox or Grid, you can easily create responsive galleries that look good on mobiles, tablets, and large screens.
You can enhance the gallery with hover effects, spacing, rounded corners, and smooth transitions to make it feel more interactive and modern.
transform and transition.The gallery usually has a wrapper (like .gallery) that uses Flexbox or Grid. Each <img> inside gets a fixed size, rounded corners, and a hover effect.
/* Flexbox-based responsive image gallery */
.gallery {
display: flex;
flex-wrap: wrap;
gap: 10px;
justify-content: center;
}
/* Individual gallery images with fixed size */
.gallery img {
width: 200px;
height: 150px;
object-fit: cover;
border-radius: 8px;
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
/* Simple hover zoom effect */
.gallery img:hover {
transform: scale(1.05);
box-shadow: 0 8px 16px rgba(15, 23, 42, 0.25);
}
Here, flex-wrap: wrap; lets images move to a new line when there isn’t enough horizontal space. object-fit: cover; makes sure each image fills its box without being distorted.
The HTML is just a wrapper <div class="gallery"> that contains multiple <img> tags.
<!-- Basic image gallery markup -->
<div class="gallery">
<img src="https://via.placeholder.com/200x150" alt="Gallery image 1">
<img src="https://via.placeholder.com/200x150" alt="Gallery image 2">
<img src="https://via.placeholder.com/200x150" alt="Gallery image 3">
<img src="https://via.placeholder.com/200x150" alt="Gallery image 4">
<img src="https://via.placeholder.com/200x150" alt="Gallery image 5">
</div>
Below is a simple gallery using real images. Resize the browser window to see how the images wrap automatically because of Flexbox and flex-wrap: wrap;.

Each image has the same width and height, so the gallery looks uniform. When the screen is narrow, images move to the next line instead of overflowing horizontally.
Common CSS properties you’ll use when building an image gallery:
| Property | Description | Example Value |
|---|---|---|
display |
Sets the gallery layout. | flex, grid |
flex-wrap |
Allows wrapping of images to new lines. | wrap |
gap |
Space between images. | 10px |
object-fit |
Makes image fit its box nicely. | cover |
transition |
Controls animation smoothness on hover. | transform 0.3s ease |
border-radius |
Adds rounded corners to images. | 8px |
object-fit: cover so all images look uniform even if their original sizes differ.transition and :hover for zoom or shadow effects.alt text for accessibility and SEO.transform: scale(1.1); plus a smooth transition.border and box-shadow to style each image as a neat card.