modals.mdx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. ---
  2. title: Modals
  3. summary: Use Bootstrap’s JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
  4. description: Dialogs for notifications and content.
  5. ---
  6. Modals are built with HTML, CSS, and JavaScript. They’re positioned over everything else in the document and remove scroll from the `<body>` so that modal content scrolls instead.
  7. ## Default markup
  8. To create a modal, you need to add a `.modal` element to the document. Inside the `.modal`, you need to add a `.modal-dialog` element, which contains a `.modal-content` element. The `.modal-content` element contains the modal’s header, body, and footer.
  9. ```html
  10. <div class="modal" tabindex="-1">
  11. <div class="modal-dialog" role="document">
  12. <div class="modal-content">
  13. <div class="modal-header">
  14. ...
  15. </div>
  16. <div class="modal-body">
  17. ...
  18. </div>
  19. <div class="modal-footer">
  20. ...
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. ```
  26. Look at the example below to see how the modal looks.
  27. ```html example centered height="30rem"
  28. <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
  29. Launch demo modal
  30. </button>
  31. <div class="modal" id="exampleModal" tabindex="-1">
  32. <div class="modal-dialog" role="document">
  33. <div class="modal-content">
  34. <div class="modal-header">
  35. <h5 class="modal-title">Modal title</h5>
  36. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  37. </div>
  38. <div class="modal-body">
  39. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci animi beatae delectus deleniti dolorem eveniet facere fuga iste nemo nesciunt nihil odio perspiciatis, quia quis reprehenderit sit tempora totam unde.
  40. </div>
  41. <div class="modal-footer">
  42. <button type="button" class="btn me-auto" data-bs-dismiss="modal">Close</button>
  43. <button type="button" class="btn btn-primary" data-bs-dismiss="modal">Save changes</button>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. ```
  49. ## Prompt and alert
  50. You can use the modal to create a prompt or alert. Look at the example below to see how the prompt and alert look.
  51. ```html example centered height="30rem"
  52. <div class="modal" id="exampleModal" tabindex="-1">
  53. <div class="modal-dialog modal-sm" role="document">
  54. <div class="modal-content">
  55. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  56. <div class="modal-status bg-danger"></div>
  57. <div class="modal-body text-center py-4">
  58. <svg xmlns="http://www.w3.org/2000/svg" class="icon mb-2 text-danger icon-lg" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  59. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  60. <path d="M12 9v2m0 4v.01" />
  61. <path d="M5 19h14a2 2 0 0 0 1.84 -2.75l-7.1 -12.25a2 2 0 0 0 -3.5 0l-7.1 12.25a2 2 0 0 0 1.75 2.75" />
  62. </svg>
  63. <h3>Are you sure?</h3>
  64. <div class="text-secondary">Do you really want to remove 84 files? What you've done cannot be undone.</div>
  65. </div>
  66. <div class="modal-footer">
  67. <div class="w-100">
  68. <div class="row">
  69. <div class="col">
  70. <a href="#" class="btn w-100" data-bs-dismiss="modal">
  71. Cancel
  72. </a>
  73. </div>
  74. <div class="col">
  75. <a href="#" class="btn btn-danger w-100" data-bs-dismiss="modal">
  76. Delete 84 items
  77. </a>
  78. </div>
  79. </div>
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. <script>
  86. document.addEventListener("DOMContentLoaded", function() {
  87. var myModal = new bootstrap.Modal(document.getElementById('exampleModal'))
  88. myModal.show()
  89. })
  90. </script>
  91. ```
  92. ```html example centered height="30rem"
  93. <div class="modal" id="exampleModal" tabindex="-1">
  94. <div class="modal-dialog modal-sm" role="document">
  95. <div class="modal-content">
  96. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  97. <div class="modal-status bg-success"></div>
  98. <div class="modal-body text-center py-4">
  99. <svg xmlns="http://www.w3.org/2000/svg" class="icon mb-2 text-green icon-lg" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  100. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  101. <circle cx="12" cy="12" r="9" />
  102. <path d="M9 12l2 2l4 -4" />
  103. </svg>
  104. <h3>Payment succedeed</h3>
  105. <div class="text-secondary">Your payment of $290 has been successfully submitted. Your invoice has been sent to support@tabler.io.</div>
  106. </div>
  107. <div class="modal-footer">
  108. <div class="w-100">
  109. <div class="row">
  110. <div class="col">
  111. <a href="#" class="btn w-100" data-bs-dismiss="modal">
  112. Go to dashboard
  113. </a>
  114. </div>
  115. <div class="col">
  116. <a href="#" class="btn btn-success w-100" data-bs-dismiss="modal">
  117. View invoice
  118. </a>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. </div>
  124. </div>
  125. </div>
  126. <script>
  127. document.addEventListener("DOMContentLoaded", function() {
  128. var myModal = new bootstrap.Modal(document.getElementById('exampleModal'))
  129. myModal.show()
  130. })
  131. </script>
  132. ```
  133. ## Modal with form
  134. You can use the modal to create a form. Look at the example below to see how the form looks.
  135. ```html example centered height="30rem"
  136. <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
  137. Launch modal with form
  138. </button>
  139. <div class="modal" id="exampleModal" tabindex="-1">
  140. <div class="modal-dialog modal-lg" role="document">
  141. <div class="modal-content">
  142. <div class="modal-header">
  143. <h5 class="modal-title">New report</h5>
  144. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  145. </div>
  146. <div class="modal-body">
  147. <div class="mb-3">
  148. <label class="form-label">Name</label>
  149. <input type="text" class="form-control" name="example-text-input" placeholder="Your report name" />
  150. </div>
  151. <label class="form-label">Report type</label>
  152. <div class="form-selectgroup-boxes row mb-3">
  153. <div class="col-md-6">
  154. <label class="form-selectgroup-item">
  155. <input type="radio" name="report-type" value="1" class="form-selectgroup-input" checked />
  156. <span class="form-selectgroup-label d-flex align-items-center p-3">
  157. <span class="me-3">
  158. <span class="form-selectgroup-check"></span>
  159. </span>
  160. <span class="form-selectgroup-label-content">
  161. <span class="form-selectgroup-title strong mb-1">Simple</span>
  162. <span class="d-block text-secondary">Provide only basic data needed for the report</span>
  163. </span>
  164. </span>
  165. </label>
  166. </div>
  167. <div class="col-md-6">
  168. <label class="form-selectgroup-item">
  169. <input type="radio" name="report-type" value="1" class="form-selectgroup-input" />
  170. <span class="form-selectgroup-label d-flex align-items-center p-3">
  171. <span class="me-3">
  172. <span class="form-selectgroup-check"></span>
  173. </span>
  174. <span class="form-selectgroup-label-content">
  175. <span class="form-selectgroup-title strong mb-1">Advanced</span>
  176. <span class="d-block text-secondary">Insert charts and additional advanced analyses to be inserted in the report</span>
  177. </span>
  178. </span>
  179. </label>
  180. </div>
  181. </div>
  182. <div class="row">
  183. <div class="col-lg-8">
  184. <div class="mb-3">
  185. <label class="form-label">Report url</label>
  186. <div class="input-group input-group-flat">
  187. <span class="input-group-text">
  188. https://tabler.io/reports/
  189. </span>
  190. <input type="text" class="form-control ps-0" value="report-01" autocomplete="off" />
  191. </div>
  192. </div>
  193. </div>
  194. <div class="col-lg-4">
  195. <div class="mb-3">
  196. <label class="form-label">Visibility</label>
  197. <select class="form-select">
  198. <option value="1" selected>Private</option>
  199. <option value="2">Public</option>
  200. <option value="3">Hidden</option>
  201. </select>
  202. </div>
  203. </div>
  204. </div>
  205. </div>
  206. <div class="modal-body">
  207. <div class="row">
  208. <div class="col-lg-6">
  209. <div class="mb-3">
  210. <label class="form-label">Client name</label>
  211. <input type="text" class="form-control" />
  212. </div>
  213. </div>
  214. <div class="col-lg-6">
  215. <div class="mb-3">
  216. <label class="form-label">Reporting period</label>
  217. <input type="date" class="form-control" />
  218. </div>
  219. </div>
  220. <div class="col-lg-12">
  221. <div>
  222. <label class="form-label">Additional information</label>
  223. <textarea class="form-control" rows="3"></textarea>
  224. </div>
  225. </div>
  226. </div>
  227. </div>
  228. <div class="modal-footer">
  229. <a href="#" class="btn btn-link link-secondary" data-bs-dismiss="modal">
  230. Cancel
  231. </a>
  232. <a href="#" class="btn btn-primary ms-auto" data-bs-dismiss="modal">
  233. <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-plus" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  234. <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
  235. <path d="M12 5l0 14"></path>
  236. <path d="M5 12l14 0"></path>
  237. </svg>
  238. Create new report
  239. </a>
  240. </div>
  241. </div>
  242. </div>
  243. </div>
  244. ```