Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • BS5 Tutorial
  • BS5 Interview Questions
  • BS5 Layout
  • BS5 Content
  • BS5 Components
  • BS5 Helpers
  • BS5 Utilities
  • BS4 Tutorial
  • BS Tutorial
  • Bootstrap Cheatsheet
  • Tailwind
  • CSS Frameworks
  • HTML Formatter
Open In App
Next Article:
How to Create a Responsive Image Gallery in Bootstrap ?
Next article icon

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 Bootstrap

  • First, 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:

z247
Output

Next Article
How to Create a Responsive Image Gallery in Bootstrap ?

S

skaftafh
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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences