Skip to content

Native dialog Modal

Accessible modal built on the native HTML dialog element with @starting-style enter and exit animation, blurred backdrop, mobile bottom sheet and an invite form.

Also known as: dialog modal, popup window, modal with form, bottom sheet modal

Native dialog Modal live demo

Open in new tab

Pure CSS code (HTML, CSS, JS)

A modal built on the native HTML dialog element, styled with pure CSS and opened with a few lines of vanilla JavaScript. It animates in and out with @starting-style, blurs the page behind it, turns into a bottom sheet on phones and contains a small invite form. Use the pattern for confirmations, settings, sign-up prompts or any form that needs the user's full attention.

How it works

The root section.dm-demo holds a .dm-panel with a member list and the .dm-open trigger, plus the dialog.dm-dialog. Inside the dialog, form.dm-form uses method="dialog": every submit button closes the dialog and sets returnValue to its value. The close icon and "Cancel" use value="cancel" with formnovalidate, so they close even when the email field is empty.

Calling showModal() gives you the hard parts for free: the dialog renders in the top layer, the rest of the page becomes inert, focus moves into it (to the autofocus email field) and Escape closes it. The animation is pure CSS. .dm-dialog transitions opacity and transform, @starting-style defines where [open] starts from, and overlay plus display with allow-discrete keep the dialog visible while it fades out. The ::backdrop fades from transparent to a tinted blur the same way.

The script opens the dialog, closes it on a backdrop click (the closedby="any" attribute does the same natively in newer browsers), and listens for submit on the form. When "Send invite" is used, it shows a busy state for 700 ms; replace that setTimeout with fetch() to your API. On the close event it reads returnValue, adds the invited person to .dm-members, writes a message to .dm-status and returns focus to the trigger.

Customization

  • --dm-accent and --dm-accent-dark on .dm-demo: primary button, selected role card and the icon badge.
  • --dm-width: the maximum dialog width from 560px up.
  • --dm-speed: duration of the open and close animation for the dialog and its backdrop.
  • --dm-radius: corner radius of the panel and the dialog.
  • rgba(17, 32, 26, 0.55) and blur(4px) in .dm-dialog[open]::backdrop: the tint and blur of the page behind.
  • .dm-roles uses three columns from 560px; change grid-template-columns to stack the role cards.
  • Remove closedby="any" and the backdrop click listener if clicking outside should not close the modal.

Use cases

  • Team management screens: an invite dialog collects an email and role without leaving the page
  • Sign-up prompts: a blurred backdrop keeps the visitor focused on a short form
  • Confirmations and settings: the browser handles focus, Escape and inert background automatically
  • Mobile web apps: the modal turns into a bottom sheet on phones and animates in and out

Accessibility

The dialog is labelled by .dm-title with aria-labelledby and described by .dm-desc with aria-describedby. The trigger has aria-haspopup="dialog". Focus is trapped by the browser while the modal is open and goes back to the trigger on close. The role choices are real radio buttons in a fieldset with a legend. Every control has a visible amber :focus-visible outline, and prefers-reduced-motion: reduce removes the slide and fade.

Usage notes

@starting-style and allow-discrete work in current Chromium, Safari and Firefox; older browsers simply open the dialog without animation.

Native dialog Modal at a glance

Framework
Pure CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
None
Layout
Responsive, works on mobile
Category
Modals
License
Free for personal and commercial use

Questions about this template

Can I use the Native dialog Modal code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

There is nothing to install. Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

No dependencies. Pure HTML, CSS and JavaScript.

Native dialog Modal – free Pure CSS modal template
Native dialog Modal · free Pure CSS modal template

More Modals

Multi-Step Wizard Dialog – free Bootstrap 6 modal template

Multi-Step Wizard Dialog

Bootstrap 6 Dialog wizard with three steps, a Stepper and progress bar, back/next buttons, per-step validation, Chips email invites and a review screen.

Image Lightbox Dialog – free Bootstrap 6 modal template

Image Lightbox Dialog

Dark Bootstrap 6 Dialog lightbox that opens gallery thumbnails large, with previous/next buttons, arrow-key and swipe navigation, captions and a photo counter.

Multi-Step Modal Dialog – free Tailwind CSS modal template

Multi-Step Modal Dialog

Tailwind CSS modal with a three-step wizard: template picker, validated details form and review, plus stepper, focus trap and Escape to close.

Product Quick View Modal with Photo – free Bootstrap 5 modal template

Product Quick View Modal with Photo

Bootstrap 5 product quick view modal with photo, rating, material and size options that update price and image, quantity stepper and add to cart.

Newsletter Popup Dialog – free Bootstrap 6 modal template

Newsletter Popup Dialog

Bootstrap 6 Dialog newsletter popup with a photo side, email signup with validation, a don't-show-again option, delayed auto-open and a confirmation state.

Fullscreen Dialog on Mobile – free Bootstrap 6 modal template

Fullscreen Dialog on Mobile

Dark Bootstrap 6 Dialog for notification settings that is centered on desktop, fullscreen on phones, with a scrollable body of switches and a sticky footer.