<div class="container">

  <!-- basic dialog -->
  <div class="dialog-container">
    <button class="close-dialog" onclick="showDialog('.basic-dialog')">Basic Dialog</button>
    <dialog class="dialog basic-dialog">
      <header>
        <h2>Confirmation</h2>
      </header>
      <div>
        <p>Are you sure you want to delete your product?</p>
      </div>
      <footer>
        <button onclick="closeDialog('.basic-dialog')">Cancel</button>
        <button onclick="closeDialog('.basic-dialog')">Yes</button>
      </footer>
    </dialog>
  </div>

  <!-- custom dialog -->
  <div class="dialog-container">
    <button class="close-dialog" onclick="showDialog('.custom-dialog')">Custom Dialog</button>
    <dialog class="dialog custom-dialog">
      <header>
        <h2>Confirmation</h2>
      </header>
      <div>
        <p>Are you sure you want to delete your product?</p>
      </div>
      <footer>
        <button data-type='cancel' onclick="closeDialog('.custom-dialog')">Cancel</button>
        <button data-type='yes' onclick="closeDialog('.custom-dialog')">Yes</button>
      </footer>
    </dialog>
  </div>

  <!-- dialog with custom backdrop -->
  <div class="dialog-container">
    <button class="close-dialog" onclick="showDialog('.custom-backdrop')">Dialog with Custom
      Backdrop</button>
    <dialog class="dialog custom-dialog custom-backdrop">
      <header>
        <h2>Confirmation</h2>
      </header>
      <div>
        <p>Are you sure you want to delete your product?</p>
      </div>
      <footer>
        <button data-type='cancel' onclick="closeDialog('.custom-backdrop')">Cancel</button>
        <button data-type='yes' onclick="closeDialog('.custom-backdrop')">Yes</button>
      </footer>
    </dialog>
  </div>

  <!-- dialog with animation -->
  <div class="dialog-container">
    <button class="close-dialog" onclick="showDialog('.animation-dialog')">Dialog with Animation</button>
    <dialog class="dialog custom-dialog animation-dialog">
      <header>
        <h2>Confirmation</h2>
      </header>
      <div>
        <p>Are you sure you want to delete your product?</p>
      </div>
      <footer>
        <button data-type='cancel' onclick="closeDialog('.animation-dialog')">Cancel</button>
        <button data-type='yes' onclick="closeDialog('.animation-dialog')">Yes</button>
      </footer>
    </dialog>
  </div>
</div>
.container {
  padding-inline: 1em;
  display: grid;
  gap: 1.5rem;
}

.dialog-container > button {
  all: unset;
  cursor: pointer;
  border: 2px solid black;
  border-radius: 0.25em;
  padding-block: 0.25em;
  height: 100%;
  text-align: center;
  width: 100%;
  font-weight: bold;
  font-family: system-ui, sans-serif;
}

.dialog-container > button:is(:hover, :focus) {
  background-color: black;
  color: white;
}

.dialog-container > button:focus {
  outline: 2px solid black;
  outline-offset: 2px;
}

@media (min-width: 500px) {
  .container {
    grid-template-columns: repeat(2, 1fr);
  }
}

.custom-dialog {
  border: 2px solid black;
  border-radius: 0.5rem;
  padding: 0 1em 1em 1em;
  font-family: system-ui, sans-serif;
  box-shadow: 0 4px 16px -4px black;
}

.custom-dialog > header > h2 {
  color: rgb(255, 118, 118);
}

.custom-dialog > div > p {
  font-weight: bold;
}

.custom-dialog > footer {
  display: flex;
  justify-content: end;
  gap: 1rem;
}

.custom-dialog > footer > button {
  all: unset;
  cursor: pointer;
  border: 1px solid gray;
  border-radius: 0.25rem;
  padding-inline: 1em;
  padding-block: 0.25em;
  font-weight: bold;
}

.custom-dialog > footer > button[data-type="cancel"] {
  border: 2px solid black;
}

.custom-dialog > footer > button[data-type="cancel"]:is(:hover, :focus) {
  background-color: black;
  color: white;
}

.custom-dialog > footer > button[data-type="cancel"]:focus {
  outline: 2px solid black;
  outline-offset: 2px;
}

.custom-dialog > footer > button[data-type="yes"] {
  color: red;
  border: 2px solid red;
}

.custom-dialog > footer > button[data-type="yes"]:is(:hover, :focus) {
  background-color: red;
  color: white;
}

.custom-dialog > footer > button[data-type="yes"]:focus {
  outline: 2px solid red;
  outline-offset: 2px;
}

.custom-backdrop::backdrop {
  background: linear-gradient(-45deg, blue, green);
  opacity: 0.5;
}

.dialog-animate-in {
  animation: dialogAnimateIn 0.5s ease;
}

@keyframes dialogAnimateIn {
  0% {
    transform: scale(0);
    opacity: 0;
  }

  50% {
    transform: scale(110%);
  }

  100% {
    transform: scale(100%);
    opacity: 1;
  }
}
const showDialog = function (dialogEl) {
  const dialog = document.querySelector(dialogEl);

  if (dialog.classList.contains("animation-dialog")) {
    dialog.classList.add("dialog-animate-in");
  }

  dialog.showModal();
};

const closeDialog = function (dialogEl) {
  const dialog = document.querySelector(dialogEl);

  dialog.close();
};

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.