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
  • jQuery Tutorial
  • jQuery Selectors
  • jQuery Events
  • jQuery Effects
  • jQuery Traversing
  • jQuery HTML & CSS
  • jQuery AJAX
  • jQuery Properties
  • jQuery Examples
  • jQuery Interview Questions
  • jQuery Plugins
  • jQuery Cheat Sheet
  • jQuery UI
  • jQuery Mobile
  • jQWidgets
  • Easy UI
  • Web Technology
Open In App
Next Article:
How to create responsive image gallery using HTML, CSS, jQuery and Bootstrap?
Next article icon

How to create responsive image gallery using HTML, CSS, jQuery and Bootstrap?

Last Updated : 05 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

 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 images
  • Responsive Grid System
  • Image viewer
web10
Responsive image gallery

Prerequisites: Basic knowledge of HTML, CSS, JavaScript, jQuery, and Bootstrap. Also, the user should be aware of how the grid system in Bootstrap works. We will divide the complete solution into three different sections in the first section we will create the structure for the gallery. In the second section, we will design the gallery by using CSS. And in the last section will make it available to respond to the user's interactions. Creating structure: Initialize HTML layout and responsive images, but we will attach the images by jQuery, in an array format.

Bootstrap code: We will use a bootstrap modal as an image viewer and modify it according to our requirements accordingly. We will render all unnecessary components of the modal transparent. Remember, we are appending the image in the modal, so we need to use on() method to attach functionalities for such selectors. 

jQuery code: Below is the script for appending in this manner. We'll be supposing that we are getting the images from the server (as an array of image URLs in JavaScript). Now we will append the image accordingly in the content panel of our page. Below is the implementation for the same 

html
<!DOCTYPE html> <html> <meta charset="utf-8">  <head>     <link rel="stylesheet"            href= "https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">     <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">     </script>     <script src= "https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js">     </script> </head>  <body>     <br>     <br>     <center>         <h1 class="text text-success">GeeksforGeeks</h1>         <b>Responsive image gallery</b>     </center>     <br>     <br>     <div class="container-fluid">         <center>             <div id=gallery>                  <!-- Content is appended here -->             </div>         </center>          <!-- Modal -->         <div class="modal fade" id="myModal" role="dialog">             <div class="modal-dialog">                  <!-- Modal content-->                 <div class="modal-content">                     <div class="modal-header">                         <button type="button" class="close"                                  data-dismiss="modal">                             ×                         </button>                      </div>                     <div class="modal-body">                     </div>                     <div class="modal-footer">                      </div>                 </div>             </div>         </div>     </div>  </body>  </html> 
CSS
img {     border-radius: 8px; }  .container-fluid {     margin-left: 12px;     margin-right: 12px }  .contain {     padding-top: 8px;     padding-bottom: 8px; } 
CSS
/* For overriding box-shadow and other default     effects of modal and it's children */ .modal, .modal-content, .modal-header, .modal-footer {     background-color: transparent;     border: 0px;     color: white;      /* Disable box shadow for different browsers */     -webkit-box-shadow: 0px 0px 0px 0px rgba(255, 255, 255, 1);     -moz-box-shadow: 0px 0px 0px 0px rgba(255, 255, 255, 1);     box-shadow: 0px 0px 0px 0px rgba(255, 255, 255, 1); }  .modal-dialog {     width: 100%;     height: 50%;     margin-top: 8px; }  .close {     color: white;     opacity: 0.8; }  .modal-body {     height: 75%; } 
JavaScript
// Taking Array of Image Addresses // Suppose it as information from the server // Modify this for different address a = [ 'https://www.geeksforgeeks.org/wp-content/uploads/javascript.png', 'https://www.geeksforgeeks.org/wp-content/uploads/jquery-banner.png', 'https://www.geeksforgeeks.org/wp-content/uploads/html-768x256.png', 'https://www.geeksforgeeks.org/wp-content/uploads/CSS-768x256.png', 'https://www.geeksforgeeks.org/wp-content/uploads/php-1-768x256.png', 'https://media.geeksforgeeks.org/wp-content/uploads/20200130114942/bootstrap4.png' ]; let x = 0; for (let i = 0; x < a.length; i++) {     let append = "<div class='row'>";     for (let j = 0; j < 6 && x < a.length; j++) {         append += `             <div class="contain col-sm-6 col-md-2">                 <img class="img-responsive" src=` + a[x++] + `>             </div>             `;     }     append += '</div>';     appender(append); }  // Function to append the data function appender(x) {     $('#gallery').html(function (i, original_html) {         return (original_html + x);     }); }  // For Image Modal $(document).on('click', 'img', function () {     imgAddr = $(this).attr('src');     data = "<center><img src=" + imgAddr + " width='50%'>";     $('#myModal').find('.modal-body').html(data);     $('#myModal').modal(); }); 

Output:

 


Next Article
How to create responsive image gallery using HTML, CSS, jQuery and Bootstrap?

D

devproductify
Improve
Article Tags :
  • Web Technologies
  • Bootstrap
  • JQuery
  • Technical Scripter 2019
  • jQuery-Projects

Similar Reads

    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 Image Gallery in Bootstrap ?
    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 s
    3 min read
    How to Create a Responsive Image Grid using CSS?
    A responsive image grid is a layout technique used to display images in a grid-like structure that adjusts dynamically based on the screen size to ensure that the grid looks good and functions well across various devices and screen resolutions. Below are the approaches to creat a responsive image gr
    3 min read
    How to Create Image Lightbox Gallery using HTML CSS and JavaScript ?
    A lightbox gallery is basically used to view the gallery images in detail specifically. You can code the JavaScript to do so but also we can use some downloaded JS and CSS. In this article, we will download the lightbox and attach the JS and CSS files into our code. For our own design satisfaction,
    3 min read
    Creating Responsive Grid Vanilla using HTML,CSS and Bootstrap
    Many modern websites use a grid system to display chunks of data on their home-page as well as other pages. To much extent grid resembles a table, however, it is much more visually appealing and most often displays sibling elements. A grid must be responsive, i.e. it should adjust to the screen size
    5 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