Hi, gamers

wassup

0

Template

Use this HTML structure:

<dialog>
  <form method="dialog">
    <button type="submit">Close</button>
  </form>
</dialog>

Copy this CSS:

(click to reveal like 46 lines of CSS)
dialog {
  /* Reset styles */
  border: none;
  padding: 0;
  color: inherit;
  max-width: unset;
  max-height: unset;

  /* Set styles to mimic open state for closing animation */
  display: block;
  visibility: hidden;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;

  /* Dialog styles (feel free to change) */
  background-color: rgba(0, 0, 0, 0.8);

  /* Closing animation */
  opacity: 0;
  transition: all 0.5s;
}
dialog[open] {
  /* Opening animation */
  visibility: visible;
  opacity: 1;
  pointer-events: unset;
  user-select: text;
}
dialog::backdrop {
  /* Reset style */
  background: none;
}
form {
  /* Closing animation */
  transform: scale(0.9);
  transition: transform 0.5s;
}
dialog[open] form {
  /* Opening animation */
  transform: none;
}

Open the dialog with JavaScript:

dialog.showModal()

Allow the user to click the greyed area to close:

// Close modal when backdrop clicked
dialog.addEventListener('click', e => {
  if (e.target === e.currentTarget) {
    e.currentTarget.close()
  }
})

Browser notes