webdevpuneet.com

Bootstrap Type-to-Confirm Delete Modal — Free Snippet

Bootstrap Type-to-Confirm Delete Modal · Modals · Plain HTML, CSS & JS · Live preview

CategoryModals

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>

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.

· Become a supporter

What's included

Features

Real Bootstrap 5.3 modal component, loaded from the actual CDN
Delete button stays genuinely disabled until an exact phrase match, not just a non-empty check
Live input validation with Bootstrap's real is-valid state on an exact match
Closes via Bootstrap's documented Modal API (getInstance().hide()), not manual class toggling
Fully resets on every close via Bootstrap's hidden.bs.modal event — no stale state on reopen
The same, stronger pattern production tools like GitHub use for irreversible actions

About this UI Snippet

Bootstrap Type-to-Confirm Delete Modal — HTML, CSS & JavaScript

Screenshot of the Bootstrap Type-to-Confirm Delete Modal snippet rendered live

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

  1. 1
    Load the snippetClick the snippet in the sidebar Library tab. The preview loads a "Delete project" button.
  2. 2
    Open the modalClick it — a real Bootstrap modal opens with a disabled red Delete button.
  3. 3
    Type an incomplete or wrong phraseThe Delete button stays disabled no matter what's typed, until it matches exactly.
  4. 4
    Type the exact phrase shown"delete northwind-marketing" — the input turns green and the Delete button enables.
  5. 5
    Click DeleteThe modal closes and a confirmation message appears below the original button.
  6. 6
    Reopen the modalThe input is empty and the button disabled again — nothing carries over from the previous attempt.

Real-world uses

Common Use Cases

Deleting a project, repository, or account
Type-to-confirm is the appropriate friction level for an action that destroys real data with no undo.
A lighter-friction alternative for lower-stakes deletes
See bootstrap-hold-to-confirm-delete-button for a press-and-hold pattern when typing a confirmation phrase feels heavier than the action warrants.
Learning exact-match input validation
A clean example of gating an action behind a precise string comparison rather than a checkbox or a simple non-empty check.
Preventing accidental destructive clicks
Typing a specific phrase forces genuine intent in a way a single confirm click cannot, reducing costly mistakes.
Admin panels with high-stakes bulk actions
Reuse this pattern for "delete all users," "reset production database," or any admin action with serious consequences.

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.