Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <h2>Modal window example 3</h2>

<button class="modal__show">Show Modal</button>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nostrum error, odit <a href="#">aperiam</a> aliquid distinctio sapiente amet, ratione mollitia expedita tempore necessitatibus <a href="#">odio</a> esse! Doloribus laboriosam voluptate fugit, <a href="#">ullam</a> pariatur ab?</p>

  <li><a href="#">Element 1</a></li>
  <li><a href="#">Element 2</a></li>
  <li><a href="#">Element 3</a></li>
  <li><a href="#">Element 4</a></li>
  <li><a href="#">Element 5</a></li>
  <li><a href="#">Element 6</a></li>
  <li><a href="#">Element 7</a></li>
  <li><a href="#">Element 8</a></li>
  <li><a href="#">Element 9</a></li>
  <li><a href="#">Element 10</a></li>

<div class="modal" id="modal" tabindex="0">
  <div class="modal__content">
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit qui, iusto numquam harum est officiis voluptate animi eligendi, incidunt saepe dolore. <a href="#">Adipisci</a> quos odio, optio aspernatur ex quae excepturi repudiandae.</p>
    <form action="#">
        <label for="firstname">First name</label>
        <input type="text" id="firstname" />
        <label for="lastname">First name</label>
        <input type="text" id="lastname" />

    <button class="modal__close">
    </button> <!-- .modal__close -->
  </div> <!-- .modal__content -->
</div> <!-- .modal -->
              .modal {
  background-color: rgba(0,0,0,0.5);

  height: 100vh;
  width: 100vw;

  position: absolute;
  left: 0;
  top: 0;

  display: none;

.modal--visible {
  display: flex;
  justify-content: center;
  align-items: center;

.modal__content {
  background-color: rgb(255, 255, 255);
  height: 70%;
  width: 70%;
  padding: 2rem;

  position: relative;

.modal__close {
  background-color: #000000;
  position: absolute;
  right: -1rem;
  top: -1rem;
  color: #ffffff;

:focus {
  outline: 4px solid #FF0000;
              // Button to trigger the modal window
var button = document.querySelector('.modal__show');
// Variable for storing the last focused element
var lastFocusedElement;

// Open modal window on click
button.addEventListener('click', showModal);

// Show modal
function showModal() {
  // Close all open modal windows
  // Store the last focused element
  lastFocusedElement = document.activeElement;
  // Select the modal window
  var modal = document.getElementById('modal');
  // Show the window
  // Focus the window
  // Add keydown event
  modal.addEventListener('keydown', function(e) {
    // Close the window by pressing the Esc-key
    if(e.keyCode === 27) {

// Close the window by clicking the close button
document.querySelector('.modal__close').addEventListener('click', removeModal);

// Remove the modal window if it's visible
function removeModal() {
  var visibleClass = 'modal--visible';
  if (document.querySelector('.' + visibleClass)) {
    document.querySelector('.' + visibleClass).classList.remove(visibleClass);
    // Return the focus to the last focused element
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.