Just move the entire modal outside of the rest of your code, to the very bottom. It doesn't need to be nested in any other element, other than the body.

<body>
    <!-- All other HTML -->
    <div>
        ...
    </div>

    <!-- Modal -->
    <div class="modal fade" id="myModal">
        ...
    </div>
</body>

Demo

They hint at this solution in the documentation.

Modal Markup Placement
Always try to place a modal's HTML code in a top-level position in your document to avoid other components affecting the modal's appearance and/or functionality.

Answer from Schmalzy on Stack Overflow
🌐
Bootstrap
getbootstrap.com › docs › 4.4 › components › modal
Modal · Bootstrap
It also adds .modal-open to the <body> to override default scrolling behavior and generates a .modal-backdrop to provide a click area for dismissing shown modals when clicking outside the modal.
🌐
Bootstrap
getbootstrap.com › docs › 5.0 › components › modal
Modal · Bootstrap v5.0
The modal plugin toggles your hidden ... scrolling behavior and generates a .modal-backdrop to provide a click area for dismissing shown modals when clicking outside the modal....
Discussions

Bootstrap modal and backdrop issue
Current behavior Having this bootstrap modal displayed, when clicking "Close", modal is hidden, but backdrop is always here (Working on Chrome or Safari). Currently I do this to avoid the issue: cy... More on github.com
🌐 github.com
2
December 17, 2022
Back Button in browser not clearing Bootstrap 5 modal backdrop?
we would have to know how you are doing your routing, where the modal component is located in the routing tree, etc. if the same exact modal component is present in both pages, it’s not going to clear until the show state is set to false. More on reddit.com
🌐 r/reactjs
1
0
July 2, 2023
Modal with blurry background
When the modal is open, a backdrop div is shown in front of the page, behind the modal. Style the backdrop div to the blur should get what you want e.g., .modal-backdrop { background-color: rgba(255, 255, 255, 0.5); backdrop-filter: blur(10px); } More on reddit.com
🌐 r/bootstrap
3
4
March 19, 2022
Any workaround for this Safari bug with a Bootstrap 4 modal?
This is a problem I have run into before. Neither positioning nor z-index will solve it for you, sadly. The solution is to add the following to the correct parent container of the modal. In this case, the body of the iframe you are jsfiddle is using: -webkit-transform: translate3d(0,0,0); I just tested in your fiddle and this will solve your problem. The use of the webkit prefix will limit the impact of this to only webkit based browsers. More on reddit.com
🌐 r/webdev
13
7
April 23, 2018
🌐
MDBootstrap
mdbootstrap.com › standard › modal backdrop
Bootstrap Modal Backdrop - free examples & tutorial
Backdrop options for a responsive popup with Bootstrap 5. Prevent close on click outside with static backdrop, remove backdrop, enable interactivity & more. Default modal backdrop is a delicate shadow overlaying the rest of the page design.
🌐
Codeply
codeply.com › go › oNKsVikW6n
Bootstrap 4 modal backdrop color on Codeply
HTML, CSS, JavaScript editor playground for designers & developers to compare, prototype and test frontend frameworks
🌐
W3Schools
w3schools.com › bootstrap › tryit.asp
Modal Options
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
CoreUI
coreui.io › react › documentation › components › modal
Bootstrap Modal - extended examples and tutorials
July 5, 2023 - They’re positioned over everything else in the document and remove scroll from the <body> so that modal content scrolls instead. Clicking on the modal “backdrop” will automatically close the modal.
🌐
Bootstrap
getbootstrap.com › docs › 5.3 › components › modal
Modal · Bootstrap v5.3
The modal plugin toggles your hidden ... scrolling behavior and generates a .modal-backdrop to provide a click area for dismissing shown modals when clicking outside the modal....
Find elsewhere
🌐
GitHub
github.com › mdbootstrap › bootstrap-modal-backdrop
GitHub - mdbootstrap/bootstrap-modal-backdrop: Backdrop options for a responsive popup with Bootstrap 5. Prevent close on click outside with static backdrop, remove backdrop, enable interactivity & more. · GitHub
Backdrop options for a responsive popup with Bootstrap 5. Prevent close on click outside with static backdrop, remove backdrop, enable interactivity & more. - mdbootstrap/bootstrap-modal-backdrop
Author   mdbootstrap
🌐
Bootstrap
getbootstrap.com › docs › 4.6 › components › modal
Modal · Bootstrap v4.6
It also adds .modal-open to the <body> to override default scrolling behavior and generates a .modal-backdrop to provide a click area for dismissing shown modals when clicking outside the modal.
🌐
TutorialsPoint
tutorialspoint.com › bootstrap › examples › modal_static_backdrop.php
Bootstrap - Modal
Modal with static backdrop · Launch modal · Modal title · This is a modal with static backdrop. Try clicking outside to close me!!! Sorry you can't, as this has a static backdrop · Close
🌐
Tutorial Republic
tutorialrepublic.com › codelab.php
Live Demo: Bootstrap Modal with Static Backdrop
View the live example as well as try and test it using the online HTML editor.
🌐
CodePen
codepen.io › cristinaconacel › pen › ZmxgYm
Bootstrap 4 Basic Modal with Static Backdrop
<div class="container"> <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#glassAnimals" data-backdrop="static"> Glass Animals Info </button> </div> <div class="modal fade" id="glassAnimals" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">Glass Animals</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span> </button> </div> <div class="modal-body"> Glass Animals are an English indie rock band from Oxford consisting of members Dave Bayley (lead vocals, guitar), Drew MacFarlane (guitar, keys, backing vocals), Edmund Irwin-Singer (bass, keys, backing vocals), and Joe Seaward (drums).
🌐
W3Schools
w3schools.com › bootstrap5 › bootstrap_modal.php
Bootstrap 5 Modal
<!-- Button to Open the Modal --> <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#myModal"> Open modal </button> <!-- The Modal --> <div class="modal" id="myModal"> <div class="modal-dialog"> <div class="modal-content"> <!-- Modal Header --> <div class="modal-header"> <h4 class="modal-title">Modal Heading</h4> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <!-- Modal body --> <div class="modal-body"> Modal body..
🌐
Rick Strahl's Web Log
weblog.west-wind.com › posts › 2016 › sep › 14 › bootstrap-modal-dialog-showing-under-modal-background
Bootstrap Modal Dialog showing under Modal Background - Rick Strahl's Web Log
September 14, 2016 - The problem is that the .modal-backdrop overlay sits in the root of the DOM tree while the other content is buried in a separate DOM node tree. If anything inside of that tree is relatively positioned, the z-index can no longer be compared effectively. You can try using the following (Bootstrap 4 - in 3 use .modal-dialog instead of .modal-content:
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Reference › Properties › backdrop-filter
backdrop-filter - CSS | MDN
December 16, 2025 - The backdrop-filter CSS property lets you apply graphical effects such as blurring or color shifting to the area behind an element. Because it applies to everything behind the element, to see the effect the element or its background needs to be transparent or partially transparent.
🌐
GitHub
github.com › cypress-io › cypress › issues › 25202
Bootstrap modal and backdrop issue · Issue #25202 · cypress-io/cypress
December 17, 2022 - Backdrop should be auto removed as in my Chrome browser. ... <div class="modal fade" id="modal-id" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h1 class="modal-title fs-5">Header</h1> </div> <div class="modal-body">Body</div> <div class="modal-footer text-center"> <button type="button" class="btn btn-primary" data-bs-dismiss="modal"> Close </button> </div> </div> </div> </div>
Author   lugosium
🌐
GeeksforGeeks
geeksforgeeks.org › bootstrap › bootstrap-5-modal-static-backdrop
Bootstrap 5 Modal Static backdrop - GeeksforGeeks
November 30, 2022 - Bootstrap 5 Modal Static backdrop facilitates the modal that will not be going to be closed while clicking outside of the modal, by setting the backdrop to static.