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>Dialog with close confirmation &#128517</h1>
  <button class="btn btn-primary" data-target="my-dialog" data-modeltrigger>
    Click me
  </button>
  <dialog data-name="my-dialog">
    <header>
      <h2>Don't you dare close me!</h2>
      <button class="btn btn-icon" data-target="second-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. Please don't close me &#128525</p>
    </main>
    <footer>
      <button class="btn btn-primary outline" data-target="second-dialog" data-modeltrigger>
        close
      </button>
    </footer>

    <dialog data-name="second-dialog" class="confirm-dialog warning-dialog">
      <header>
        <h2>Are you sure? &#128530</h2>
      </header>
      <main>
        <p>I will be one sad dialog if you choose to leave me</p>

      </main>
      <footer>
        <button class="btn btn-primary outline" data-target="third-dialog" data-modeltrigger>
          yes, go away!
        </button>
        <button class="btn btn-primary" data-target="second-dialog" data-modeltrigger>
          No, you can stay
        </button>

      </footer>
      <dialog data-name="third-dialog" class="confirm-dialog danger-dialog">
        <header>
          <h2>Why did you do that?! &#128546</h2>
        </header>
        <main>
          <p>I just wanted to come out and play </p>

        </main>
        <footer>
          <button class="btn btn-primary outline" data-target="third-dialog" data-parenttrigger data-modeltrigger>
            BE GONE! &#128545
          </button>
        </footer>
      </dialog>
    </dialog>
  </dialog>
</div>
              
            
!

CSS

              
                /* Styling the modal and backdrop */
:root {
  --theme-color: #8a9ccc;
  --theme-color-hover: #afc0ee;
}

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(124, 222, 220, 0.5) 0%,
    rgba(124, 222, 220, 0.7) 100%
  );
}

/* just a friendly warning backdrop */

.warning-dialog {
  --theme-color: rgba(245, 191, 66, 1);
  --theme-color-hover: rgba(227, 175, 54, 1);
  max-width: 400px;
}

.warning-dialog::backdrop {
  background: radial-gradient(
    circle,
    rgba(245, 191, 66, 0.5) 0%,
    rgba(245, 191, 66, 0.7) 100%
  );
}

/* modal is angry backdrop */

.danger-dialog {
  --theme-color: rgba(181, 0, 48, 1);
  --theme-color-hover: rgba(153, 14, 51, 1);
  background: var(--theme-color);
  color: #fff;
  max-width: 360px;
}

.danger-dialog header {
  background: var(--theme-color);
}

.danger-dialog::backdrop {
  background: radial-gradient(
    circle,
    rgba(181, 0, 48, 0.5) 0%,
    rgba(181, 0, 48, 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 var(--theme-color);
}

dialog footer {
  border-top: 1px solid var(--theme-color);
}

dialog > *:not(dialog) {
  padding: 24px;
}

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

.confirm-dialog {
  width: auto;
  border: 1px solid var(--theme-color);
}

.confirm-dialog h2 {
  padding-bottom: 0;
}

.confirm-dialog footer .btn {
  width: 100%;
  margin: 5px 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(#fff 20%, transparent 19%),
    radial-gradient(#edf5fc 20%, #edf5fc 19%), #f6fedb;
  background-size: 10px 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: 10px 25px;
  font-size: 1.2rem;
  letter-spacing: 0;
  color: #fff;
  background: var(--theme-color);
  border: 2px solid var(--theme-color);
  border-radius: 6px;
  transition: all 0.24s;
}

.btn-primary:hover,
.btn-primary:active {
  background-color: var(--theme-color-hover);
  border-color: var(--theme-color-hover);
}

.btn-primary.outline {
  color: var(--theme-color);
  background: #fff;
}

.btn-primary.outline:hover,
.btn-primary.outline:active {
  border-color: var(--theme-color-hover);
}

.btn-icon {
  padding: 0;
  background: transparent;
  width: 24px;
  height: 24px;
  color: var(--theme-color);
}

              
            
!

JS

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

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();
    }
    /* closes all dialogs when data attribute is available */
    if (el.getAttribute("data-parenttrigger") !== null) {
      dialogs.forEach(function (el) {
        el.close();
      });
    }
  });
});

              
            
!
999px

Console