Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

Save Automatically?

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="h-screen w-screen flex items-center justify-center">
  <button 
    class="bg-indigo-700 text-3xl text-white rounded-full px-8 hover:bg-indigo-600"
    data-modal-trigger="form">Open my modal</button>
  <button>
</div>

<div 
  class="fixed inset-0 transition-all transition-250 modal" 
  data-modal="form"
 >
  <div class="h-full w-full flex items-center justify-center">
    <div class="bg-white rounded-lg p-5 modal-body max-w-full md:max-w-2xl overflow-y-scroll">
      <div class="text-right border-b mb-3 py-1">
        <button class="close-modal">Close [x]</button>
      </div>
      <h2 class="text-center text-2xl leading-none">This is my modal title</h2>
      
      <p class="my-3"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin interdum velit eget nibh lacinia, cursus commodo libero efficitur. Cras iaculis hendrerit interdum. Suspendisse potenti. Nunc eu felis neque. Nunc pulvinar aliquet neque, sed vestibulum felis dapibus eget. Nam hendrerit, sem ac tincidunt ultrices, lorem neque vestibulum purus, et imperdiet lectus nisi eu nisl. Pellentesque vitae semper sem, ac rhoncus justo. Suspendisse pellentesque fringilla velit, ut vehicula magna vehicula vel. Sed vel dapibus enim, et gravida magna. Interdum et malesuada fames ac ante ipsum primis in faucibus. Donec quis libero urna.
 </p>
      <p class="my-3">Vestibulum eu ex interdum, dignissim magna nec, maximus mi. In hac habitasse platea dictumst. Donec tristique faucibus urna, id lacinia odio ullamcorper eget. Quisque ornare ex id facilisis dictum. Morbi non sapien sit amet massa sodales venenatis ut at ante. Morbi ullamcorper porttitor viverra. Praesent lobortis congue fermentum. Nullam sit amet rhoncus lorem, eu convallis libero. Pellentesque bibendum fermentum est, nec viverra nisi. Vivamus luctus interdum erat vel sodales. Fusce lectus felis, fringilla sollicitudin lacinia dignissim, ornare ut lacus. Aenean lorem nibh, aliquam sed dapibus at, sodales et augue. Sed tempor tortor sit amet urna varius vehicula. Etiam ligula dui, pretium porttitor nibh vitae, commodo euismod urna.</p>
    </div>
  </div>
</div>

              
            
!

CSS

              
                /* Components */
.modal {
  display: none;
  background: rgba(0, 0, 0, 0.5);
  animation: fadeInFromNone 0.5s ease-out;
}

.modal-open {
  display: block;
}

/* Utilities */
.transition-all {
  transition: all;
}

.transition-250 {
  transition-duration: 250ms;
}

/* Animations */
@keyframes fadeInFromNone {
    0% {
        display: none;
        opacity: 0;
    }

    1% {
        display: block;
        opacity: 0;
    }

    100% {
        display: block;
        opacity: 1;
    }
}
              
            
!

JS

              
                const modalService = () => {
  const d = document;
  const body = d.querySelector('body');
  const buttons = d.querySelectorAll('[data-modal-trigger]');
  
  // attach click event to all modal triggers
  for(let button of buttons) {
    triggerEvent(button);
  }
  
  function triggerEvent(button) {
    button.addEventListener('click', () => {
      const trigger = button.getAttribute('data-modal-trigger');
      const modal = d.querySelector(`[data-modal=${trigger}]`);
      const modalBody = modal.querySelector('.modal-body');
      const closeBtn = modal.querySelector('.close-modal');
      
      closeBtn.addEventListener('click', () => modal.classList.remove('modal-open'))
      modal.addEventListener('click', () => modal.classList.remove('modal-open'))
      
      modalBody.addEventListener('click', (e) => e.stopPropagation());

      modal.classList.toggle('modal-open');
      
      // Close modal when hitting escape
      body.addEventListener('keydown', (e) => {
        if(e.keyCode === 27) {
          modal.classList.remove('modal-open')
        }
      });
    });
  }
}

modalService();
              
            
!
999px

Console