1001Ferramentas
🪟Generators

Modal HTML

Gera estrutura HTML básica de modal/dialog.

HTML

Modal dialogs: when interruption is justified

A modal (or modal dialog) is an overlay UI element that demands the user's attention and blocks interaction with the rest of the page until it is dismissed. Properly used, it is the most efficient way to confirm a destructive action, collect a single critical input or display media that needs the full canvas. Misused — auto-popping newsletter sign-ups, nested modals, modals without an obvious close — it becomes the most hated pattern on the web.

The HTML platform now ships a first-class primitive: the <dialog> element, supported in Chrome 37+, Edge 79+, Firefox 98+ and Safari 15.4+. Calling dialog.showModal() opens it, locks the page below the ::backdrop pseudo-element, traps focus, handles Esc to close and returns focus to the trigger automatically. A bare-bones example:

<dialog id="confirm">
  <form method="dialog">
    <p>Delete this file?</p>
    <button value="cancel">Cancel</button>
    <button value="ok">Delete</button>
  </form>
</dialog>
<script>
  confirm.showModal()
</script>

Accessibility requirements

A handcrafted modal (the kind this generator produces, using a div overlay) has to reproduce what <dialog> gives you for free: focus trap (Tab cycles inside the modal), Esc to close, return focus to the opener element on close, role="dialog", aria-modal="true", and aria-labelledby pointing at the title. Skip any of these and screen-reader and keyboard users get stranded behind the overlay.

Anti-patterns to avoid

  • Nested modals (a modal opening another modal) — terrible UX, hard to escape.
  • Modal that pops within seconds of pageload (newsletter capture) — usually counter-productive and blocked by browsers as intrusive.
  • Modals without a visible close button (X) or click-outside-to-close — leaves the user no escape.
  • Tiny centered modal on mobile — prefer full-screen or bottom-sheet for narrow viewports.
  • Modals containing the entire onboarding flow — break it into a wizard or a dedicated page.

Libraries

In React, the go-to primitives are @radix-ui/react-dialog (most accessible, used by shadcn/ui), @headlessui/react Dialog (Tailwind Labs), and the older react-modal. Material UI ships Modal and Dialog; Vue has Vuetify v-dialog and PrimeVue Dialog; Angular Material has MatDialog. Bottom-sheet variants are popular on mobile-first stacks (vaul by Emil Kowalski for React).

Modal vs drawer vs toast

A drawer (side sheet) slides in from the edge and is great for secondary navigation or filters — less interruptive than a modal. A toast conveys ephemeral, non-blocking information. A modal earns its interruption only when the user must decide or input something before continuing. If the answer to "what if the user ignores it?" is "nothing bad", you should not be using a modal.

FAQ

Is native <dialog> production-ready? Yes for modern browsers. For IE/legacy Safari support add the dialog-polyfill from Google.

Is every modal automatically accessible? No. The native <dialog> handles focus management; custom div-based modals require manual focus trap, Esc handling and ARIA attributes.

When should I use a toast instead? When the message is transient and non-blocking — "Saved", "Copied". Modals are reserved for blocking decisions.

How do I animate the dialog? Modern CSS supports @starting-style and the transition-behavior: allow-discrete property to animate display changes. A subtle fade-in plus 8 px slide-up is the canonical style.

Related Tools