How to Create a Responsive Image Gallery in Bootstrap ? Last Updated : 05 Apr, 2024 Comments Improve Suggest changes Like Article Like Report An image gallery is like a digital album where we can put our multiple images to attract user attention. We have used Bootstrap a CSS framework for Creating a Responsive Image Gallery where the layout adjusts automatically based on the screen size, ensuring that it looks good on both large desktop screens and smaller mobile devices. Responsive Image Gallery in BootstrapFirst, create a basic HTML structure and provide a background color using the "bg-success" class.After that create a container using a "container" class which holds the entire gallery.Use Bootstrap's utility classes for layout and positioning, such as "position-relative", "top-50", "start-50", and "translate-middle", to center the captions within the images. Also, use JavaScript to toggle the visibility of the captions on hover.Example: Creating a Responsive Image Gallery in Bootstrap. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Responsive Image Gallery</title> <!-- Bootstrap CSS --> <link rel="stylesheet" href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"> <style> .gallery-item img { transition: transform 0.3s ease; } .gallery-item img:hover { transform: scale(1.05); } </style> </head> <body class="bg-success "> <div class="container"> <h1 class="text-center my-4 text-white"> Responsive Image Gallery </h1> <div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-3"> <div class="col"> <div class="position-relative gallery-item" style="cursor: pointer;"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240322101847/Default_An_illustration_depictin-(2)-660.jpg" alt="Image 1" class="w-100"> <div class="position-absolute top-50 start-50 translate-middle text-center d-none"> <div class="bg-success bg-opacity-70 text-white px-4 py-2"> Coding </div> </div> </div> </div> <div class="col"> <div class="position-relative gallery-item" style="cursor: pointer;"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240308154939/html-(1).jpg" alt="Image 2" class="w-100"> <div class="position-absolute top-50 start-50 translate-middle text-center d-none"> <div class="bg-success bg-opacity-70 text-white px-4 py-2"> HTML </div> </div> </div> </div> <div class="col"> <div class="position-relative gallery-item" style="cursor: pointer;"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240308154940/js-(1).jpg" alt="Image 3" class="w-100 "> <div class="position-absolute top-50 start-50 translate-middle text-center d-none"> <div class="bg-success bg-opacity-70 text-white px-4 py-2"> JavaScript </div> </div> </div> </div> <div class="col"> <div class="position-relative gallery-item" style="cursor: pointer;"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240308154942/web-(1).jpg" alt="Image 4" class="w-100"> <div class="position-absolute top-50 start-50 translate-middle text-center d-none"> <div class="bg-success bg-opacity-70 text-white px-4 py-2"> HTML </div> </div> </div> </div> <div class="col"> <div class="position-relative gallery-item" style="cursor: pointer;"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240308154945/web2-(1).jpg" alt="Image 5" class="w-100"> <div class="position-absolute top-50 start-50 translate-middle text-center d-none"> <div class="bg-success bg-opacity-70 text-white px-4 py-2"> JavaScript </div> </div> </div> </div> <div class="col"> <div class="position-relative gallery-item" style="cursor: pointer;"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240322101847/Default_An_illustration_depictin-(2)-660.jpg" alt="Image 6" class="w-100"> <div class="position-absolute top-50 start-50 translate-middle text-center d-none"> <div class="bg-success bg-opacity-70 text-white px-4 py-2"> HTML </div> </div> </div> </div> </div> </div> <!-- Bootstrap JavaScript --> <script src= "https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"> </script> <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"> </script> <script> // Show caption on hover let position_relative = document.querySelectorAll('.position-relative'); position_relative.forEach(item => { item.addEventListener('mouseover', event => { const caption = item.querySelector('.position-absolute'); caption.classList.remove('d-none'); }); item.addEventListener('mouseleave', event => { const caption = item.querySelector('.position-absolute'); caption.classList.add('d-none'); }); }); </script> </body> </html> Output: Output Comment More infoAdvertise with us Next Article How to Create a Responsive Image Gallery in Bootstrap ? S skaftafh Follow Improve Article Tags : Web Technologies Bootstrap Bootstrap-Questions Similar Reads How to create responsive image gallery using HTML, CSS, jQuery and Bootstrap? With the advent of new frameworks in web technologies, it has become quite easy to design and implement feature-rich and responsive web pages. Here, we are going to design a responsive image gallery using HTML, CSS, jQuery, and Bootstrap. Features or Functionalities to implement:Responsive imagesRes 3 min read How to Create Responsive Divs in Bootstrap ? To create responsive divs in Bootstrap, utilize the grid system with container and row classes. Define columns using col classes and specify breakpoints for different screen sizes. This ensures divs adjust their layout and size responsively across devices. Below are the approaches to creating respon 2 min read How to Create a Responsive Image Gallery using CSS? Creating a responsive image gallery using CSS is a common task in web development. A responsive gallery adjusts to different screen sizes and ensures that images look good on devices ranging from mobile phones to desktop monitors. In this article, we will explore different approaches to creating a r 3 min read How to create a Responsive Sidebar in Bootstrap? A responsive sidebar is a valuable component for web applications and admin panels that allows for efficient navigation while adapting to different screen sizes. To create a responsive sidebar in Bootstrap, use the navbar-expand-* classes along with Bootstrap's grid system to design a collapsible si 3 min read How to make Responsive Carousel in Bootstrap ? Bootstrap Responsive Carousel simplifies the creation of responsive carousels for dynamic content display. Utilize the Carousel component with a suitable HTML structure, ensuring proper sizing and responsive breakpoints for optimal display across devices. ApproachCreate an HTML document with Bootstr 2 min read Like