Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                 <div class="guide">
      <p>Hello, this Page has 2 Modals.</p>
   
      <button class="modal-open" data-popup-trigger="modal1">
        Open Modal 1
      </button>
      <button class="modal-open" data-popup-trigger="modal2">
        Open Modal 2
      </button>
    </div>

    <div class="modal" id="modal1">
      <div class="modal-content">
        <div class="modal-close-button">&#10008;</div>
        <div class="modal-text">Content of the modal 1</div>
      </div>
    </div>

    <div class="modal" id="modal2">
      <div class="modal-content">
        <div class="modal-close-button">&#10008;</div>
        <div class="modal-text">
          <h2>Title of the Modal</h2>
          <br />
          Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
          sollicitudin id ligula quis laoreet. Maecenas felis mi, dictum ac
          condimentum in, bibendum ut diam. Vestibulum iaculis scelerisque velit
          vel convallis. Praesent sodales sollicitudin tortor eu facilisis.
          Aenean in tincidunt sapien, id consequat nisi. Quisque interdum, justo
          at commodo sodales, diam ipsum venenatis odio, id aliquam leo massa
          nec felis. Aliquam in libero est. Ut ultricies eros diam, vitae
          ullamcorper nisl pretium eget. Etiam in gravida sem. Donec nec nisl
          pulvinar ligula hendrerit malesuada.
        </div>
      </div>
    </div>

View Tutorial at <a href="https://holycoders.com/tutorial/vanilla-javascript-popup-modal/" target="_blank">How to create Modals in Pure Vanilla Javascript</a>
              
            
!

CSS

              
                /* General Styling */

@import url("https://fonts.googleapis.com/css2?family=Ubuntu&display=swap");

body {
  font-family: "Ubuntu", sans-serif;
  background-color: #ff7979;
  font-size: 1.2rem;
  color: #333;
}

button {
  background-color: #333;
  color: #fff;
  font-size: 1.2rem;
  padding: 10px;
  font-weight: 400;
  cursor: pointer;
  border-radius: 5px;
  border: 1px solid #d5d5d5;
}

.guide {
  text-align: center;
  color: #fff;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translateX(-50%) translateY(-50%);
}

/* General Styling Ends */

@keyframes scaleup {
  0% {
    transform: scale(0.2);
  }
  90% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

.modal {
  display: none;
  position: fixed;
  z-index: 1;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: #333;
  background-color: rgba(0, 0, 0, 0.7);
  animation: scaleup 0.2s ease-in;
}

.modal-content {
  position: absolute;
  top: 50%;
  background-color: #f2f2f2;
  border-radius: 5px;
  padding: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
}

.modal-close-button {
  position: absolute;
  background-color: #e74c3c;
  padding: 10px;
  border-radius: 50%;
  color: #fff;
  right: -20px;
  top: -20px;
  cursor: pointer;
}
.modal-close-button:hover {
  transition: all 0.2s;
  padding: 12px;
}

.show-modal {
  display: block;
}

              
            
!

JS

              
                var modals = document.querySelectorAll(".modal-open");

    modals.forEach((element) => {
      //Add click listeners to open-modal buttons
      element.addEventListener("click", () => {

        //Get the unique popup modal for that button
        var popupModal = document.getElementById(element.dataset.popupTrigger);

        //Select the close button of current popup modal
        var popupModalCloseButton = document
          .getElementById(element.dataset.popupTrigger)
          .getElementsByClassName("modal-close-button")[0];

        // Show/hide modal on click by toggling the class
        popupModal.classList.toggle("show-modal");

        //Add event listener to close button on popup modal.
        popupModalCloseButton.addEventListener("click", () => {
          popupModal.classList.remove("show-modal");
        });

      });
    });
              
            
!
999px

Console