<button id="button-open">モーダルを開く</button>
<dialog id="my-modal">
  <p>モーダルの中身です。</p>
  <button id="button-close">モーダルを閉じる</button>
</dialog>
#my-modal:modal {
}
#my-modal::backdrop {
}
const modal = document.querySelector('#my-modal')
const buttonOpen = document.querySelector('#button-open')
const buttonClose = document.querySelector('#button-close')

buttonOpen.addEventListener('click', () => {
  modal.showModal()
})

buttonClose.addEventListener('click', () => {
  modal.close()
})

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.