Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Example of Setting Bootstrap 3 Modal's backdrop Option via Data Attribute</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <style> .bs-example{ margin: 20px; } </style> </head> <body> <div class="bs-example"> <p><strong>Note:</strong> Click the following buttons to show modals with different <code>backdrop</code> option setting.</p> <!-- Button HTML (to Trigger Modal) --> <button type="button" class="btn btn-success" data-toggle="modal" data-target="#withBackdrop">Modal (data-backdrop="true")</button> <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#noBackdrop">Modal (data-backdrop="false")</button> <button type="button" class="btn btn-info" data-toggle="modal" data-target="#staticBackdrop">Modal (data-backdrop="static")</button> <!-- Modal HTML --> <div id="withBackdrop" class="modal fade" data-backdrop="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">Modal with Backdrop</h4> </div> <div class="modal-body"> <p>Bootstrap modal with backdrop/black overlay. This is default behavior.</p> <p class="text-info"><small><strong>Note:</strong> If you click outside the modal i.e. on the backdrop, it will close.</small></p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">OK</button> </div> </div> </div> </div> <!-- Modal HTML --> <div id="noBackdrop" class="modal fade" data-backdrop="false"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">Modal without Backdrop</h4> </div> <div class="modal-body"> <p>Bootstrap modal without backdrop/black overlay.</p> <p class="text-info"><small><strong>Note:</strong> If you click outside the modal, it will not close, as there is no backdrop.</small></p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">OK</button> </div> </div> </div> </div> <!-- Modal HTML --> <div id="staticBackdrop" class="modal fade" data-backdrop="static"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">Modal with Static Backdrop</h4> </div> <div class="modal-body"> <p>Bootstrap modal with static backdrop/black overlay.</p> <p class="text-info"><small><strong>Note:</strong> If you click outside the modal i.e. on the backdrop, it will not hide.</small></p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">OK</button> </div> </div> </div> </div> </div> </body> </html>