Make Modal Background Not Clickable in Bootstrap 5, 4, and 3

Last Updated on December 31, 2024 by Roshan Parihar

In this tutorial, learn how to set modal background not clickable in Bootstrap 5. The short answer is: use the data-bs-backdrop and data-bs-keyboard attributes to the button that displays the modal popup on click.

How to Make Modal Background Not Clickable in Bootstrap 5

To make modal background not clickable in Bootstrap 5, you have to add the attribute with value data-bs-backdrop="static" and data-bs-keyboard="false" to the modal as given below.

Test it Live

Output

How to Make Modal Background Not Clickable in Bootstrap 5

When you click the above button, you will get the modal that you cannot click outside to close it. It’s because of the static backdrop attributes added to the modal div.

Make Modal Background Not Clickable in Bootstrap 4

If you want to make modal background not clickable in Bootstrap 4, you have to add to attribute data-backdrop with value static. Also, add the attribute data-keyboard with value false as showing below.

Test it Live

Output

Make Modal Background Not Clickable in Bootstrap 4

When you click the above button, you will get a modal popup in which you cannot click the background to close it. This is because of the added attribute to the modal div element.

Do Not Allow Outside Click in Bootstrap 3

You have to first create a modal using Bootstrap. If you have no idea about creating a modal popup with Bootstrap, you can follow our post on Bootstrap modal.

Use the below example to add a simple Bootstrap button. The button takes attribute data-target, data-toggle, backdrop and data-keyboard.

Add the id of the modal in the data-target attribute as given in the example below. Use the other attribute input values as given in the example below.

Test it Live

Output

Make Modal Background Not Clickable in Bootstrap 4

The above example showing the button that opens the modal on click. You have to just click the above button to open the modal. If you got your modal open, click on the background or outer area of the modal. When you click the background or outer area, the modal remains open in the browser.

It only close when you click the inner close button or cross(x) sign given inside the modal. This can be helpful for bloggers to create a modal and get more user engagement through modal.