0 Tailwind6 with JSPublished 2026-10-04Free · no sign-up
Six modal designs that pair the native dialog element with Tailwind classes: a delete confirmation, a mobile bottom sheet, a slide-over filter panel, a success message, a newsletter prompt and a non-blocking cookie banner.
A destructive-action confirmation using the native dialog element styled with Tailwind, including the backdrop: variant for the dimmed overlay. showModal() gives focus trapping and Escape to close for free, and the action buttons sit in a method="dialog" form.
View code
<button id="twm-o" class="rounded-lg bg-red-600 px-4 py-2.5 font-bold text-white">Delete project</button>
<dialog id="twm" aria-labelledby="twm-t" class="w-[min(380px,90vw)] rounded-2xl p-6 text-slate-600 shadow-2xl backdrop:bg-slate-950/60 backdrop:backdrop-blur-sm">
<h2 id="twm-t" class="mb-2 text-lg font-bold text-slate-900">Delete this project?</h2>
<p class="mb-5 text-[15px] leading-relaxed">It will be removed for everyone on your team. This cannot be undone.</p>
<form method="dialog" class="flex justify-end gap-2">
<button class="rounded-lg border border-slate-300 px-4 py-2 text-sm font-bold text-slate-700">Cancel</button>
<button class="rounded-lg bg-red-700 px-4 py-2 text-sm font-bold text-white">Delete</button>
</form>
</dialog>
const twm = document.getElementById('twm');
document.getElementById('twm-o').addEventListener('click', () => twm.showModal());
twm.addEventListener('click', e => { if (e.target === twm) twm.close(); });
twm.showModal();
02. Tailwind Bottom Sheet
TailwindMobile
A share sheet pinned to the bottom of the screen with rounded top corners and a grab handle, built on dialog with Tailwind margin utilities to anchor it. Large tap targets in a three-column grid suit thumbs on phones.
const sd = document.getElementById('tws-d');
document.getElementById('tws-o').addEventListener('click', () => sd.showModal());
sd.addEventListener('click', e => { if (e.target === sd) sd.close(); });
sd.showModal();
03. Tailwind Slide-Over Panel
TailwindDrawer
A full-height panel on the right edge for filters or a cart, made from dialog with ml-auto and h-full. The header, scrollable middle and footer form a flex column, so the checkout button stays visible however long the list gets.
const td = document.getElementById('twd');
document.getElementById('twd-o').addEventListener('click', () => td.showModal());
td.addEventListener('click', e => { if (e.target === td) td.close(); });
td.showModal();
04. Tailwind Success Modal
TailwindFeedback
A confirmation modal with a large tick icon in a tinted circle, a heading, a short message and one primary action that receives focus when it opens. The icon is an inline SVG hidden from screen readers since the heading already says what happened.
A two-column signup prompt with a decorative art panel and an email form, collapsing to one column on phones with sm:grid-cols-2. It has a clear close button in the corner, and the open: variant applies the grid only when the dialog is open.
A non-modal consent card fixed to the bottom corner, so visitors can still use the page. Reject and Accept have equal size and visual weight, and the dialog is closed from a small script once either choice is made.
View code
<dialog open aria-labelledby="twck-t" class="fixed bottom-4 right-4 left-auto top-auto m-0 w-[min(340px,calc(100vw-32px))] rounded-2xl border border-slate-200 p-5 text-sm leading-relaxed text-slate-600 shadow-xl shadow-slate-900/15">
<h2 id="twck-t" class="mb-1.5 font-bold text-slate-900">Cookies on this site</h2>
<p class="mb-4">We use cookies to keep your cart and to see how the site is used. <a href="#" class="font-semibold text-blue-700 underline">Settings</a></p>
<div class="grid grid-cols-2 gap-2"><button class="twck rounded-lg border-2 border-slate-900 py-2 font-bold text-slate-900">Reject all</button><button class="twck rounded-lg border-2 border-slate-900 bg-slate-900 py-2 font-bold text-white">Accept all</button></div>
</dialog>
Tailwind's backdrop: variant styles the dialog's ::backdrop, so backdrop:bg-slate-950/60 backdrop:backdrop-blur-sm dims and blurs the page behind a modal with no extra element.
Layout only when open
A closed dialog must stay hidden. The open: variant applies flex or grid only while the dialog has the open attribute, as in the slide-over and newsletter demos, so the dialog never shows by accident.
Positioning sheets and drawers
Dialogs are centred with automatic margins. m-0 mt-auto pins the bottom sheet to the bottom edge, and m-0 ml-auto h-full turns the slide-over into a full-height right panel.
Behaviour comes from dialog
showModal() traps focus, makes the page inert and closes on Escape. Buttons inside form method="dialog" close it without any extra script.
Frequently asked questions
Do I need a modal library?
No. The dialog element covers focus, Escape and the backdrop in every current browser.
Why do the previews open on load?
So you can see each design. In your site, call showModal() from a click.