Bootstrap 5 Confirmation Dialog
A Confirmation Dialog is a modal overlay that asks the user to explicitly verify a destructive or irreversible action before it executes, such as deleting a record or cancelling a subscription. Built with Bootstrap 5's modal component, it combines a focused message, a clear Cancel option, and a visually distinct Confirm button. Use it whenever the consequence of proceeding cannot be easily undone and accidental clicks would cause real data loss or user frustration.
Primary Class
.confirmation-dialogCommon Use Cases
- →Permanently deleting a customer account or database record from an admin dashboard, where the action cannot be reversed without a full restore
- →Cancelling an active paid subscription mid-cycle, ensuring the user understands they will lose access immediately rather than at the billing period end
- →Removing a team member from a shared workspace, which revokes their permissions and deletes their local data across all connected devices
- →Discarding unsaved form edits when the user navigates away from a multi-step configuration wizard, preventing silent data loss
Variants & Classes
| Variant | Description |
|---|---|
| Confirmation Dialog Default | Standard confirmation dialog with Bootstrap's default styling. |
| Confirmation Dialog Responsive | Responsive variant that adapts to different screen sizes. |
Code Example
<!-- Trigger Button -->
<button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#deleteAccountModal">
Delete Account
</button>
<!-- Confirmation Modal -->
<div class="modal fade" id="deleteAccountModal" tabindex="-1" aria-labelledby="deleteAccountModalLabel" aria-modal="true" role="dialog">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header border-0 pb-0">
<h5 class="modal-title fw-semibold" id="deleteAccountModalLabel">Delete your account?</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Cancel"></button>
</div>
<div class="modal-body pt-2">
<p class="text-muted mb-0">This will permanently remove all your data, projects, and billing history. <strong>This action cannot be undone.</strong></p>
</div>
<div class="modal-footer border-0 pt-1">
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-danger" id="confirmDeleteBtn">Yes, delete my account</button>
</div>
</div>
</div>
</div>
<!-- JavaScript: wire up the confirmed action -->
<script>
document.getElementById('confirmDeleteBtn').addEventListener('click', function () {
// Execute the delete request here
console.log('Account deletion confirmed');
const modal = bootstrap.Modal.getInstance(document.getElementById('deleteAccountModal'));
modal.hide();
});
</script>Live Examples
Basic Confirmation Dialog
Canvas Framework Variants
The Canvas template extends Bootstrap 5 with 1,658+ component variants. Generate any of these using Canvas Builder:
- ✓Canvas Builder generated confirmation dialog with custom colours
- ✓Confirmation Dialog with interactive states
- ✓Responsive confirmation dialog for all screen sizes
Best Practices
Use modal-dialog-centered for visual clarity
Adding the class modal-dialog-centered vertically centers the dialog on all screen sizes, preventing it from appearing tucked against the top of the viewport on mobile where users may miss the message body.
Label the confirm button with the exact action, not just 'OK'
Replace generic labels like 'OK' or 'Yes' with specific text such as 'Delete project' or 'Cancel subscription' so users process what they are agreeing to even if they only skim the dialog.
Remove the backdrop dismiss for high-stakes confirmations
Set data-bs-backdrop="static" and data-bs-keyboard="false" on the modal element to prevent accidental dismissal by clicking outside or pressing Escape, forcing a deliberate choice between Cancel and Confirm.
Keep the destructive button on the right
Place Cancel on the left and the destructive action on the right inside modal-footer so the layout matches the cognitive expectation users bring from native OS dialogs, reducing hesitation and misclicks.