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">
  <h1>A simple Dialog with HTML</h1>
  <button class="btn btn-primary" data-target="my-dialog" data-modeltrigger>
    Click me
  </button>
  <dialog data-name="my-dialog">
    <header>
      <h2>Well hello there!</h2>
      <button class="btn btn-icon" data-target="my-dialog" data-modeltrigger>
        <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
          <path stroke-linecap="round" stroke-linejoin="round" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
        </svg>
      </button>
    </header>
    <main>
      <p>I am a lovely dialog with HTML. This is a really awesome HTML feature don't you think? Only requires a bit of javascript and so versatile.</p>
      <p>I even have a great scroll behaviour right outside the box :) check it out by editing this text</p>

    </main>
    <footer>
      <button class="btn btn-primary-outline" data-target="my-dialog" data-modeltrigger>
        close
      </button>
    </footer>
  </dialog>
</div>
              
            
!

CSS

              
                /* Styling the modal and backdrop */

dialog {
  width: 100%;
  max-width: 600px;
  padding: 0;
  background: #fff;
  border-radius: 8px;
  border: 1px solid #dedede;
  box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
  animation: scale-in 0.4s ease-out;
}

dialog::backdrop {
  background: radial-gradient(
    circle,
    rgba(216, 209, 116, 0.5) 0%,
    rgba(182, 196, 84, 0.7) 100%
  );
}

/* Styling inside of the modal */

dialog header {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 24px;
  background: #fff;
  border-bottom: 1px solid rgba(216, 209, 116, 1);
}

dialog footer {
  border-top: 1px solid rgba(216, 209, 116, 1);
}

dialog > * {
  padding: 24px;
}

dialog p:last-of-type {
  margin-bottom: 0;
}

/* bouncy animation because i can */
@keyframes scale-in {
  0% {
    opacity: 0;
  }
  50% {
    opacity: 1;
    transform: scale(0.9);
  }
  100% {
    transform: scale(1);
  }
}

/* some basic styling (added to the bottom for convenience) */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: "Lato", sans-serif;
  font-size: 1.3rem;
  line-height: 1.5;
  color: #333;
  background: radial-gradient(#e6d3a3 20%, transparent 19%),
    radial-gradient(#e6d3a3 20%, #f6fedb 19%), #f6fedb;
  background-size: 6px 6px;
  background-position: 0 0, 3px 3px;
}

h1 {
  margin: 0 0 16px 0;
  font-family: "Merriweather", serif;
  font-size: 2rem;
}

h2 {
  margin: 0;
  font-family: "Merriweather", serif;
  font-size: 1.4rem;
}

p {
  margin: 0 0 24px 0;
}

.container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  justify-content: center;
  align-items: center;
  max-width: 1300px;
  margin: 0 auto;
  padding: 50px;
}

/* quick and dirty button styling, forgive me ;) */
.btn {
  display: inline-block;
  font-family: "Merriweather", sans-serif;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
}

.btn-primary {
  padding: 20px 50px;
  font-size: 1.6rem;
  line-height: 1.6rem;
  letter-spacing: 2px;
  font-weight: 700;
  background: #91972a;
  border-color: #91972a;
  color: #fff;
  transition: all 0.24s;
}

.btn-primary:hover,
.btn-primary:active {
  background-color: #797d25;
  border-color: #797d25;
}

.btn-primary-outline {
  padding: 10px 25px;
  font-size: 1.2rem;
  letter-spacing: 0;
  color: #91972a;
  background: #fff;
  border-width: 2px;
  border-color: #91972a;
  border-radius: 6px;
  transition: all 0.24s;
}

.btn-primary-outline:hover,
.btn-primary-outline:active {
  border-color: #797d25;
}

.btn-icon {
  padding: 0;
  background: transparent;
  width: 24px;
  height: 24px;
  color: #91972a;
}

              
            
!

JS

              
                const triggers = document.querySelectorAll("[data-modeltrigger]");

triggers.forEach(function (el) {
  el.addEventListener("click", function () {
    const getTarget = el.getAttribute("data-target");
    const target = document.querySelector(`[data-name="${getTarget}"]`);
    if (target.hasAttribute("open")) {
      target.close();
    } else {
      target.showModal();
    }
  });
});

              
            
!
999px

Console