The native <dialog showModal()> gives you focus trapping and top-layer stacking for free. If you build one by hand, set role="dialog" aria-modal="true", move focus inside on open (usually the title or first field), trap Tab so it can't escape the dialog, and return focus to the trigger button on close.
It's often compared with a drawer. A modal centers on screen and reads as "deal with this now," while a drawer slides in from an edge and is used for lighter supporting tasks — filters, settings — sometimes built as non-modal so the page behind stays usable.
Esc and backdrop-click closing are conventional, but a form that could lose data should ask for confirmation before closing that way.
When to use
Reserve it for moments that truly block progress until the user decides — delete confirmations. For informational messages, a toast is less disruptive.