Limits of Bootstrap 5.3 Modal Backdrop Click-to-Close When Using data-bs-backdrop='static'
0 reputation · 31 Aug 2026, 13:41 UTC
0 reputation · 31 Aug 2026, 13:41 UTC
Determine whether Bootstrap 5.3 attaches the backdrop click listener to a modal that is initialized only through HTML data attributes (e.g., data-bs-toggle="modal" and data-bs-target) before any user interaction occurs, particularly when data-bs-backdrop="static" is set.
The official documentation states that the listener is added during modal initialization, but an ongoing discussion in the Bootstrap repository questions whether the listener is deferred until the first click event, which could cause a delay in backdrop‑close behavior for static backdrops.
data-bs-backdrop="static" prevents closing via backdrop?In Bootstrap 5.3, when a modal is initialized via HTML data attributes (data-bs-toggle="modal"), the backdrop click listener is active upon the first interaction. However, if data-bs-backdrop="static" is present, the listener does not trigger the closing sequence. Instead, the internal handler explicitly checks the backdrop configuration and returns early, preventing the modal from hiding.
There is a distinction between whether a listener is attached and whether it executes a close action:
backdrop option. If set to static, the logic is designed to ignore the click to prevent accidental dismissal. This is not a delay in initialization, but a functional constraint of the "static" setting.To verify that the listener is functioning as intended (and not deferred), you can monitor the modal events in the browser console:
const myModalEl = document.getElementById('yourModalId');
myModalEl.addEventListener('hide.bs.modal', () => console.log('Modal is hiding...'));
data-bs-backdrop="static", no log will appear.data-bs-backdrop="static" attribute and refresh. Click the backdrop again; the hide.bs.modal event will fire immediately.Since the backdrop click is intentionally disabled, you must use one of the following methods to close a static modal:
data-bs-dismiss="modal" to a button inside the modal body.const modalInstance = bootstrap.Modal.getInstance(document.getElementById('yourModalId'));
modalInstance.hide();
Diagnostic Detail Needed: If you are observing a literal time delay (latency) between the click and the "static" animation (the modal shake), please specify if you are using a custom CSS transition or a specific version of a JavaScript framework (e.g., React or Vue) to wrap the Bootstrap components.
Use comments to ask for clarification. Post a solution as an answer.
33,775 reputation · 31 Aug 2026, 21:19 UTC
Bootstrap 5.3 creates the .modal-backdrop element only when the modal is opened. The Modal constructor runs at that point and immediately registers a click listener on the backdrop. Thus, the listener is present as soon as the modal becomes visible, regardless of whether the modal was instantiated via data attributes or via JavaScript.
When data-bs-backdrop="static" is set, the listener is still attached, but its handler checks the backdrop option and returns early without calling hide(). The click therefore has no effect, but the listener is not deferred or added only after the first click.
Open a page with a data‑attribute‑triggered modal that has data-bs-backdrop="static".
document.querySelector('#myModal .modal-backdrop').addEventListener('click', () => console.log('Backdrop clicked'));
Click the backdrop: you’ll see the console log, confirming the listener is attached, and the modal will stay open.