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

              
                <h1>Modals the <em>easy</em> way</h1>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Impedit alias dicta quibusdam cumque ipsa ipsum reiciendis animi, officia provident veniam quis delectus minima earum suscipit ea, beatae vitae ipsam nemo.</p>
<p>Alias, architecto sapiente nostrum id, sed explicabo numquam aspernatur ratione qui excepturi repellat porro culpa molestiae? Culpa dolorem commodi cupiditate, eos deleniti similique repellendus nam velit natus a soluta et.</p>
<p>Fugiat ratione impedit officiis? Eligendi sapiente culpa tenetur esse quo reiciendis illum vero nisi ullam consequatur illo molestiae, nihil eaque. Esse asperiores tenetur natus! Quo asperiores molestias sed assumenda alias.</p>
<p>Sequi quo animi, nostrum laboriosam veritatis consequatur. Eos cumque unde porro explicabo provident, possimus alias magni pariatur quis consequuntur voluptatum? Debitis necessitatibus facilis fugiat repudiandae nobis neque nam, vel odio?</p>
<button class="button open-button">open modal</button>

<dialog class="modal" id="modal">
  <h2>An interesting title</h2>
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Rerum esse nisi, laboriosam illum temporibus ipsam?</p>
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Atque, quo.</p>
  <button class="button close-button">close modal</button>
  <form class="form" method="dialog">
    <label>Your name <input type="text"></label>
    <label>Your email <input type="email"></label>
    <button class="button" type="submit">submit form</button>
  </form>

</dialog>

<!--   
  <form class="form" method="dialog">
    <label>Your name <input type="text"></label>
    <label>Your email <input type="email"></label>
    <button class="button" type="submit">submit form</button>
  </form>-->
              
            
!

CSS

              
                .modal {
  // padding: 1em;
  max-width: 50ch;
  // border: 0;
  // box-shadow: 0 0 1em rgb(0 0 0 / .3);

  & > * {
    margin: 0 0 0.5rem 0;
  }
}

.modal::backdrop {
  background: rgb(0 0 0 / 0.4);
}

/* extra styling */

body {
  min-height: 100vh;
  margin: 2rem;
  font-family: system-ui;
  font-size: 1.25rem;
  line-height: 1.5;
  color: var(--gray-8);
  // background-image: url('https://images.unsplash.com/photo-1644242629712-943ae5c8c4f3?crop=entropy&cs=srgb&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTY0Njc1MjQxNA&ixlib=rb-1.2.1&q=85');
  // background-size: cover;
}

h1 em {
  color: var(--cyan-9);
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

.button {
  border: 0;
  cursor: pointer;
  background: var(--gray-8);
  color: var(--gray-2);
  font-weight: 700;
  padding: var(--size-2) var(--size-4);
}

.button:hover,
.button:focus {
  background: var(--cyan-9);
}

form {
  display: grid;
  gap: 1em;
}

              
            
!

JS

              
                const modal = document.querySelector("#modal");
const openModal = document.querySelector(".open-button");
const closeModal = document.querySelector(".close-button");

openModal.addEventListener("click", () => {
  modal.showModal();
});

closeModal.addEventListener("click", () => {
  modal.close();
});

              
            
!
999px

Console