🌐
W3Schools
w3schools.com › howto › howto_css_modal_images.asp
How To Create Modal Images
Learn how to create responsive Modal Images with CSS and JavaScript. A modal is a dialog box/popup window that is displayed on top of the current page.
🌐
Stack Overflow
stackoverflow.com › questions › 55097205 › popup-modal-with-image-and-text
popupwindow - popup modal with image and text - Stack Overflow
The image popups are correct, however text returned is TEXT1 for whichever I click. Any help would be appreciated. Many thanks Sabs · function onClick(element) { document.getElementById("modal01").style.display = "block"; document.getElementById("img01").src = element.src; document.getElementsByClassName("modal-content").innerHTML = this.alt; }
🌐
DEV Community
dev.to › salehmubashar › create-an-image-modal-with-javascript-2lf3
Create an Image modal with JavaScript! - DEV Community
December 31, 2021 - In this tutorial, we will be creating a popup image modal using javascript. The basic idea is that when a user clicks an image, a larger version should be opened in a modal.
🌐
GeeksforGeeks
geeksforgeeks.org › bootstrap › how-to-fit-the-image-into-modal-popup-using-bootstrap
How to fit the image into modal popup using Bootstrap? - GeeksforGeeks
July 15, 2025 - The "modal-body" div determines the main content of modal popup. By using the <img> tag, an image can be inserted into it.
🌐
W3Schools
w3schools.com › css › css3_images_modal.asp
CSS Responsive Modal Images
A modal image gives a user the ... current page. When a user clicks on a modal image, it shows a popup window that appears on top of the main content of the webpage, often with a semi-transparent background....
🌐
SitePoint
sitepoint.com › javascript
Modal image popup
January 9, 2018 - <script> // Get the modal var modal = document.getElementById('myModal'); // Get the image and insert it inside the modal - use its "alt" text as a caption var img = document.getElementById('myImg'); var modalImg = document.getElementById("img01"); var captionText = document.getElementById("caption"); img.onclick = function () { modal.style.display = "block"; modalImg.src = this.src; captionText.innerHTML = this.alt; } // Get the <span> element that closes the modal var span = document.getElementsByClassName("close")[0]; // When the user clicks on <span> (x), close the modal span.onclick = function () { modal.style.display = "none"; } </script>
🌐
Steemit
steemit.com › utopian-io › @sogata › how-to-pop-up-image-galery-on-modal-using-bootstrap-and-jquery
How to pop-up image galery on modal using bootstrap and jQuery — Steemit
February 7, 2018 - Select the img element in modal. To fill scr value of this element with the img clicked you can use attr() function ... Save the file and run on your browser. Then try to click an image of your galery.
Top answer
1 of 10
158

You can try this code if you are using bootstrap 3:

HTML

<a href="#" id="pop">
    <img id="imageresource" src="http://patyshibuya.com.br/wp-content/uploads/2014/04/04.jpg" style="width: 400px; height: 264px;">
    Click to Enlarge
</a>
    
<!-- Creates the bootstrap modal where the image will appear -->
<div class="modal fade" id="imagemodal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">Image preview</h4>
      </div>
      <div class="modal-body">
        <img src="" id="imagepreview" style="width: 400px; height: 264px;" >
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

JavaScript:

$("#pop").on("click", function() {
   $('#imagepreview').attr('src', $('#imageresource').attr('src')); // here asign the image to the modal when the user click the enlarge link
   $('#imagemodal').modal('show'); // imagemodal is the id attribute assigned to the bootstrap modal, then i use the show function
});

This is the working fiddle.

2 of 10
14

I have change it little bit but still can not do few things.

I added that clicking on it close it - it was easy but very functional.

 <div class="modal-dialog" data-dismiss="modal">

I also need different description under each photo. I added description in footer just to show what I need. It need to change with every photo.

HTML

<div class="modal fade" id="imagemodal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" data-dismiss="modal">
      <div class="modal-content"  >              
        <div class="modal-body">
          <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
             <img src="" class="imagepreview" style="width: 100%;" >
        </div> 
     <div class="modal-footer">
       <div class="col-xs-12">
           <p class="text-left">1. line of description<br>2. line of description <br>3. line of description</p>
       </div>
     </div>         
   </div>
 </div>

JavaScript:

$(function() {
    $('.pop').on('click', function() {
        $('.imagepreview').attr('src', $(this).find('img').attr('src'));
        $('#imagemodal').modal('show');   
    });     
});

Also it would be nice if this window will open only on 100% of screen. Here picture inside with description have more than 100% and in become scrollable... and if screen in much bigger than pictures it shoud stop only on orginal size. for ex. 900 px and no bigger in height.

http://jsfiddle.net/2ve4hbmm/

🌐
Dribbble
dribbble.com › search › modal
Browse thousands of Modal images for design inspiration | Dribbble
Browse modal designs · Related: popup · dialog · pop up · overlay · lightbox · popover · Popular · Popular · New & Noteworthy · Discover · Animation · Branding · Illustration · Mobile · Print · Product Design · Typography · Web Design · Filters · Shot Link View Modal - Plan the activity ·
Find elsewhere
🌐
MDBootstrap
mdbootstrap.com › standard › modal image
Bootstrap Modal image - free examples & tutorial
<!-- Modal gallery --> <section class=""> <!-- Section: Images --> <section class=""> <div class="row"> <div class="col-lg-4 col-md-12 mb-4 mb-lg-0"> <div class="bg-image hover-overlay ripple shadow-1-strong rounded" data-ripple-color="light" > <img src="https://mdbcdn.b-cdn.net/img/screens/yt/screen-video-1.webp" class="w-100" /> <a href="#!" data-mdb-modal-init data-mdb-target="#exampleModal1"> <div class="mask" style="background-color: rgba(251, 251, 251, 0.2);"></div> </a> </div> </div> <div class="col-lg-4 mb-4 mb-lg-0"> <div class="bg-image hover-overlay ripple shadow-1-strong rounded" d
🌐
Jotform
jotform.com › answers › 3485815-how-to-open-a-pop-up-modal-with-image-upon-a-link-click
How to open a pop-up modal with image upon a link click
What I'm trying to do is use a word as a link and when that word is clicked, it will open a popup window of an image. Thanks. Mike · Replied on November 7, 2021 at 2:58 PM · You can add the next HTML code to the source of the Paragraph element: <p><a class="button" href="#open" rel="nofollow">See Example</a></p> <div id="open" class="modalBox"> <div> <p><a class="close" title="Close" href="#close" rel="nofollow">X</a></p> <h2>Example</h2> <p><img style="display: block; margin-left: auto; margin-right: auto;" src="https://www.jotform.com/uploads/igorchernioglo/form_files/Example.6184c3c330630
🌐
HubSpot
community.hubspot.com › t5 › CMS-Development › How-can-I-make-modal-popup-on-image-click › m-p › 395703
Solved: HubSpot Community - How can I make modal popup on image click? - HubSpot Community
December 28, 2020 - If you do that, the button will be rendered, but there will be no onclick event, you have to put in also the JS (You can find that on top https://getbootstrap.com/docs/4.0/components/modal/ (How it works section)) Best way to try this function is to build a new module just for that.
🌐
CSS-Tricks
css-tricks.com › creating-a-modal-image-gallery-with-bootstrap-components
Creating a Modal Image Gallery With Bootstrap Components | CSS-Tricks
March 6, 2020 - This makes it so clicking anything in the gallery opens the modal. We should also add the data-target value (#exampleModal) as the ID of the modal itself, but we’ll do that once we get to the modal markup. Let’s add data-target="#carouselExample" and a data-slide-to attribute to each image.
🌐
USU
extension.usu.edu › employee › ou-campus › blog › pop-up-image-model
Pop-up Image Modals for USU Extension Web Pages | USU
December 14, 2023 - Example of a pop-up image modal for USU Extension websites. An enlarged version of the image pops up when the photo is clicked. The magnifying glass icon is automatically displayed in the lower left corner.
🌐
Dimsemenov
dimsemenov.com › plugins › magnific-popup
Magnific Popup: Responsive jQuery Lightbox Plugin
Three simple popups with different scaling settings. 1 — fits horizontally and vertically, 2 — only horizontally, 3 — no gaps, zoom animation, close icon in top-right corner. You may put any HTML content in each gallery item and mix content types. In this example lazy-loading of images is enabled for the next image based on move direction.
🌐
Bootstrap Studio Forum
forum.bootstrapstudio.io › bootstrap studio help
Click on a image and display it in modal windows - Bootstrap Studio Help - Bootstrap Studio Forum
June 13, 2022 - Hi, Would anyone have an example (or a component) where users can click on an image to display it larger in a modal window (with just one button to close it) ? In the best World, I would like to use always the same modal windows and give the name of the clicked image in paramaters I know how ...
🌐
Stack Overflow
stackoverflow.com › questions › 63920075 › open-image-on-click-in-modal
Open Image on Click in Modal
<script> $(".pop").on("click", function() { $('#imagepreview').attr('src', $(this).find('img').attr('src')); $('#imagemodal').modal('show'); }); </script>
🌐
Bootstrap
getbootstrap.com › docs › 5.0 › components › modal
Modal · Bootstrap v5.0
Use Bootstrap’s JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
🌐
CodeSandbox
codesandbox.io › s › view-image-modal-gzsns
View Image Modal - CodeSandbox
December 7, 2020 - View Image Modal by paqoibanez using @material-ui/core, @material-ui/icons, @material-ui/styles, react, react-dom, react-scripts
Published   Dec 07, 2020
Author   paqoibanez