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="container mx-auto py-10">

  <div class="flex justify-center">
    
    <a href="#modal" class="modal-trigger bg-teal hover:bg-teal-dark shadow text-white font-bold py-4 px-6 rounded no-underline">Trigger Modal</a>
    
  </div>

<div id="modal" class="modal fixed pin p-30 w-100 h-100 m-0 z-20 mt-4" role="dialog">
  <div class="modal-overlay fixed pin z-10 bg-teal-dark"></div>
  <div class="modal-container relative bg-white rounded-lg shadow max-w-lg mx-auto p-16 z-30" role="document">
    
    <h3 class="font-sans text-2xl mb-2 text-teal-dark">Welcome to a super modal</h3>
    
    <p class="font-serif leading-normal mb-4">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Esse hic quam velit fugiat ipsam, quos atque ex aperiam repellendus sequi qui perspiciatis deserunt officia fugit adipisci, consectetur veritatis, explicabo sit!</p>
    
    <button class="bg-white hover:bg-grey-lightest text-grey-darkest font-semibold py-2 px-4 border border-grey-light rounded pin-b pin-r absolute mb-6 mr-6">Do something</button>
    
    <button class="modal-close absolute pin-t pin-r w-16 h-16" aria-label="Close">
      <svg width="24" height="24" viewBox="0 0 24 24">
        <path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"></path>
</svg>
    </button>
  </div>
</div>
  
</div>
              
            
!

CSS

              
                .modal {
  opacity: 0;
  visibility: hidden;
  transition: visibility 0s lineaer 0.1s, opacity 0.3s ease;
  
  &.open {
    visibility: visible;
    opacity: 1;
    transition-delay: 0s;
  }
}
              
            
!

JS

              
                /* Let's Build: With JavaScript - Web-Crunch.com
   Subscribe on YouTube - https://youtube.com/c/webcrunch
   
   Let's Build: Vanilla JavaScript Modal 
*/

function openModal() {
  let modalTrigger = document.querySelectorAll('.modal-trigger');
  
  modalTrigger.forEach(function(trigger) {
    trigger.addEventListener('click', function(event) {
      
      // remove "#" from #modal
      const target = this.getAttribute('href').substr(1);
      
      // use dynamic target to reference given modal
      const modalWindow = document.getElementById(target);
      
      if(modalWindow.classList) {
        modalWindow.classList.add('open');
      }
      
      event.preventDefault();
    });
  });
}

function closeModal() {
  let closeBtns = document.querySelectorAll('.modal-close');
  let modalOverlays = document.querySelectorAll('.modal-overlay');
  
  closeBtns.forEach(function(btn) {
    btn.addEventListener('click', function(event) {
    
      // target the whole modal
      const modalWindow = this.parentNode.parentNode;
      
      modalWindow.classList.remove('open');
    });
  });
  
  modalOverlays.forEach(function(overlay) {
    // get the whole modal using overlay argument
    const modalWindow = overlay.parentNode;
    
    // close modal if click event is fired on overlay background
    overlay.addEventListener('click', function() {
      modalWindow.classList.remove('open');
    });
  });
}

function fireWhenReady(func) {
  document.addEventListener('DOMContentLoaded', func);
}

fireWhenReady(openModal);
fireWhenReady(closeModal);
              
            
!
999px

Console