Image Gallery is used to store and display collection of pictures. This example create a responsive Image Gallery using HTML and CSS.
Steps 1: Creating a basic gallery structure
- Each gallery contains number of div section.
- Each div section contains an image and its description.
<div class="gallery">
<div class="box">
<div class="image"> Image Added Here </div>
<div class="text"> Text Added Here </div>
</div>
Steps 2: Styling the file using CSS
- Styling the gallery container:
- Set the display property to flex. It means elements within the gallery container will have flex context.
- Set the flex-flow property to row wrap. It sets the flex direction and flex wrap style.
.gallery { width:100%; display:flex; flex-flow: row wrap; } - Styling the box:
.box { flex-basis: 20%; width: 100%; padding: 10px; margin: 8px; // Set the blur shadow box-shadow: 1px 1px 15px 1px green; }
Steps 3: Use @media query to create responsive image gallery.
@media only screen and (max-width: 300px) {
.box {
flex-basis: 100%;
}
Example:
<!DOCTYPE html> <html> <head> <style> /* style to set body of page */ body { width:100%; margin:auto; } .gallery { width:100%; display:flex; flex-flow: row wrap; } .box { flex-basis:20%; width:100%; padding:10px; margin:8px; box-shadow: 1px 1px 1px 1px green; } .text { text-align:center; margin-top:5px; } .image:hover { border: 3px solid green; } /* media query used here */ @media only screen and (max-width: 300px) { .box { flex-basis: 100%; } } @media only screen and (max-width:500px) { .box { flex-basis: 40%; } } </style> </head> <body> <div class = "gallery"> <div class = "box"> <div class = "image"> <a target="_blank" href= <img src = width = "300" height = "300"> </a> </div> <div class = "text"> Geeks Classes Image </div> </div> <div class = "box"> <div class = "image"> <a target="_blank" href= <img src = width = "300" height = "300"> </a> </div> <div class = "text"> GeekforGeeks Image </div> </div> <div class = "box"> <div class = "image"> <a target="_blank" href= <img src = width = "300" height = "300"> </a> </div> <div class = "text"> Geeks Image </div> </div> </body> </html> |
chevron_right
filter_none
Output:

Recommended Posts:
- How to create responsive image gallery using HTML, CSS, jQuery and Bootstrap?
- How to Create Image Lightbox Gallery using HTML CSS and JavaScript ?
- How to Create a Tab Image Gallery ?
- How to create a Portfolio Gallery using HTML and CSS ?
- How to add filter with Portfolio Gallery using HTML, CSS and JavaScript ?
- jQuery | Flipping Gallery Plugin
- JavaScript Gallery Plugin
- Convert an image into grayscale image using HTML/CSS
- How to hide âImage not foundâ icon when source image is not found?
- How to get the new image URL after refreshing the image using JavaScript ?
- How to specify an image as a server-side image-map in HTML ?
- HTML | Responsive full page image using CSS
- How to auto-resize an image to fit a div container using CSS?
- CSS | Image Sprites
- Resize image proportionally with CSS
- CSS | list-style-image Property
- CSS | border-image-slice Property
- How to give text or an image transparent background using CSS?
- CSS | border-image-outset Property
- CSS | border-image-repeat Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

