Bootstrap Type-to-Confirm Delete Modal — Free Snippet
Bootstrap Type-to-Confirm Delete Modal · Modals · Plain HTML, CSS & JS · Live preview
Copy & paste
Source Code
<div class="container py-5 text-center">
<button class="btn btn-outline-danger" data-bs-toggle="modal" data-bs-target="#bsdelModal">Delete project</button>
<p class="small text-muted mt-3" id="bsdelResult"></p>
</div>
<div class="modal fade" id="bsdelModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header border-0">
<h5 class="modal-title text-danger fw-bold">Delete "Northwind Marketing"?</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p class="small text-muted">This permanently deletes the project, its 48 files, and cannot be undone.</p>
<label class="form-label small">Type <strong>delete northwind-marketing</strong> to confirm.</label>
<input type="text" class="form-control" id="bsdelInput" autocomplete="off">
</div>
<div class="modal-footer border-0">
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-danger" id="bsdelConfirm" disabled>Delete project</button>
</div>
</div>
</div>
</div>#bsdelInput.is-valid { border-color: #16a34a; }const PHRASE = 'delete northwind-marketing';
const modalEl = document.getElementById('bsdelModal');
const input = document.getElementById('bsdelInput');
const confirmBtn = document.getElementById('bsdelConfirm');
const result = document.getElementById('bsdelResult');
input.addEventListener('input', () => {
const match = input.value.trim() === PHRASE;
confirmBtn.disabled = !match;
input.classList.toggle('is-valid', match);
});
confirmBtn.addEventListener('click', () => {
result.textContent = 'Project "Northwind Marketing" was deleted.';
bootstrap.Modal.getInstance(modalEl).hide();
});
// Every reopen starts from a clean, disabled state — a stale typed phrase
// from a previous open must never leave the confirm button pre-enabled.
modalEl.addEventListener('hidden.bs.modal', () => {
input.value = '';
input.classList.remove('is-valid');
confirmBtn.disabled = true;
});Extend with AI
Take This Snippet Further With AI
The AI prompt for this one is for Patreon supporters ($3 a month), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.
What's included
Features
About this UI Snippet
Bootstrap Type-to-Confirm Delete Modal — HTML, CSS & JavaScript

A plain "Are you sure?" confirm dialog is easy to click through on autopilot. This snippet uses the stronger pattern real production tools reach for on genuinely irreversible actions: the Delete button inside a real Bootstrap 5.3 modal stays disabled until the visitor types an exact phrase — here, delete northwind-marketing — matched with a plain string comparison on every keystroke.
The input also gets Bootstrap's real is-valid styling the instant the phrase matches exactly, giving immediate positive feedback rather than leaving the visitor to guess whether they've typed it correctly. On close — whether by cancelling, confirming, or the backdrop — Bootstrap's own hidden.bs.modal event resets the input and re-disables the button, so a stale typed phrase from a previous open can never leave the button pre-enabled the next time.
Step by step
How to Use
- 1Load the snippetClick the snippet in the sidebar Library tab. The preview loads a "Delete project" button.
- 2Open the modalClick it — a real Bootstrap modal opens with a disabled red Delete button.
- 3Type an incomplete or wrong phraseThe Delete button stays disabled no matter what's typed, until it matches exactly.
- 4Type the exact phrase shown"delete northwind-marketing" — the input turns green and the Delete button enables.
- 5Click DeleteThe modal closes and a confirmation message appears below the original button.
- 6Reopen the modalThe input is empty and the button disabled again — nothing carries over from the previous attempt.
Real-world uses
Common Use Cases
Got questions?
Frequently Asked Questions
Genuinely — its disabled property is set based on an exact string match, so it's functionally unclickable and correctly skipped in tab order until the phrase matches exactly.
Yes, this demo does a plain, case-sensitive trimmed comparison against the exact phrase. Add .toLowerCase() to both sides of the comparison if you want it case-insensitive.
No — this is a front-end demo showing a confirmation message. Wire the confirm button's click handler to a real DELETE API call before hiding the modal.
Bootstrap's hidden.bs.modal event clears the input and re-disables the button on every close, so reopening always starts from a clean, unconfirmed state.
Yes — build the PHRASE string from a real project/resource name variable instead of a hardcoded string, and update the visible instruction text to match.