Open In App

How to Use the Magnific Popup jQuery Plugin?

Last Updated : 15 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Magnific Popup is a fast, light, mobile-friendly and responsive lightbox and modal dialog jQuery plugin. It can be used to open inline HTML, ajax loaded content, image, form, iframe (YouTube video, Vimeo, Google Maps), and photo gallery. It has added animation effects using CSS3 transitions.

Approach

IN this approach, we have created a small popup using the Magnific Popup library. It includes necessary CSS and JavaScript files from CDNs. A button is provided, and when clicked, it opens a small popup displaying "GEEKSFORGEEKS" and "WELCOME TO GEEKSFORGEEKS". The jQuery script initializes the Magnific Popup with specific settings to manage the popup's appearance and behavior.

Installation Process: There are several ways to start using this plugin:

  • Download the zipped folder of the latest version of Magnific Popup from here.
  • Alternatively, clone the Github Repository to any desired location by executing the following command in the Git Bash.
git clone https://github.com/dimsemenov/Magnific-Popup
  • Since the Magnific is a plugin of the jQuery framework, it needs to reference the jQuery library. This can be done by using the Google-hosted version of jQuery or downloading and using the distribution files.
<link rel="stylesheet" type="text/css" href="path/magnific-popup.css">
  • Add the magnific-popup.css file from the dist folder of Magnific.
  • Add the jquery.magnific-popup.min.js file from the dist folder of Magnific.

CDN link:

<script type="text/javascript" src="path/jquery.magnific-popup.min.js"></script>

Note: We will use CDN link to use the Magnific Popup.

Example: This example shows a popup using the plugin.

html
<!DOCTYPE html>
<html>

<head>
    <title>Magnific Popup Example</title>
    <link rel="stylesheet" type="text/css"
          href=
"https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.min.css">
</head>

<body style="text-align:center;">
    <button>
        <a href="#popup-info" 
           class="open-popup"
           style="text-decoration: none;">
            Click to Open PopUp
        </a>
    </button>
    <div id="popup-info" class="mfp-hide"
        style=
"text-align:center; background:white; padding:20px; width:300px; margin:auto;">
        <h1 style="color: green;">GEEKSFORGEEKS</h1>
        <div style="font-size: 15px; font-weight: bold;">WELCOME TO GEEKSFORGEEKS</div>
    </div>

    <script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src=
"https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function ($) {
            $('.open-popup').magnificPopup({
                type: 'inline',
                fixedContentPos: true,
                closeBtnInside: false,
                preloader: false,
                removalDelay: 160,
                mainClass: 'mfp-fade'
            });
        });
    </script>
</body>

</html>

Output: 

popuppp
Output

Similar Reads