alerts.mdx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. ---
  2. title: Alerts
  3. description: Alert messages are used to inform users of the status of their action and help them solve any problems that might have occurred. Good design of alert modals is very important for the overall user experience of a website or app.
  4. bootstrapLink: components/alerts/
  5. ---
  6. ## Default markup
  7. Depending on the information you need to convey, you can use one of the following types of alert messages - **success**, **info**, **warning** or **danger**. Using the right type of alert modal will help draw users' attention to the message and prompt them to take action.
  8. ```html example
  9. <div class="alert alert-success" role="alert">
  10. <h4 class="alert-title">Wow! Everything worked!</h4>
  11. <div class="text-secondary">Your account has been saved!</div>
  12. </div>
  13. <div class="alert alert-info" role="alert">
  14. <h4 class="alert-title">Did you know?</h4>
  15. <div class="text-secondary">Here is something that you might like to know.</div>
  16. </div>
  17. <div class="alert alert-warning" role="alert">
  18. <h4 class="alert-title">Uh oh, something went wrong</h4>
  19. <div class="text-secondary">Sorry! There was a problem with your request.</div>
  20. </div>
  21. <div class="alert alert-danger" role="alert">
  22. <h4 class="alert-title">I'm so sorry&hellip;</h4>
  23. <div class="text-secondary">Your account has been deleted and can't be restored.</div>
  24. </div>
  25. ```
  26. ```html
  27. <div class="alert alert-success" role="alert">
  28. <h4 class="alert-title">Wow! Everything worked!</h4>
  29. <div class="text-secondary">Your account has been saved!</div>
  30. </div>
  31. ```
  32. ## Alert links
  33. Add a link to your alert message to redirect users to the details they need to complete or additional information they should read.
  34. ```html example
  35. <div class="alert alert-danger m-0">
  36. This is a danger alert — <a href="#" class="alert-link">check it out</a>!
  37. </div>
  38. ```
  39. ```html
  40. <div class="alert alert-danger" role="alert">
  41. This is a danger alert — <a href="#" class="alert-link">check it out</a>!
  42. </div>
  43. ```
  44. ## Dismissible alerts
  45. Add the `x` close button to make an alert modal dismissible. Thanks to that, your alert modal will disappear only once the user closes it.
  46. ```html example
  47. <div class="alert alert-success alert-dismissible" role="alert">
  48. <div class="d-flex">
  49. <div>
  50. <svg xmlns="http://www.w3.org/2000/svg" class="icon alert-icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  51. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  52. <path d="M5 12l5 5l10 -10" />
  53. </svg>
  54. </div>
  55. <div>
  56. <h4 class="alert-title">Wow! Everything worked!</h4>
  57. <div class="text-secondary">Your account has been saved!</div>
  58. </div>
  59. </div>
  60. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  61. </div>
  62. <div class="alert alert-info alert-dismissible" role="alert">
  63. <div class="d-flex">
  64. <div>
  65. <svg xmlns="http://www.w3.org/2000/svg" class="icon alert-icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  66. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  67. <circle cx="12" cy="12" r="9" />
  68. <line x1="12" y1="8" x2="12.01" y2="8" />
  69. <polyline points="11 12 12 12 12 16 13 16" />
  70. </svg>
  71. </div>
  72. <div>
  73. <h4 class="alert-title">Did you know?</h4>
  74. <div class="text-secondary">Here is something that you might like to know.</div>
  75. </div>
  76. </div>
  77. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  78. </div>
  79. <div class="alert alert-warning alert-dismissible" role="alert">
  80. <div class="d-flex">
  81. <div>
  82. <svg xmlns="http://www.w3.org/2000/svg" class="icon alert-icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  83. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  84. <path d="M12 9v2m0 4v.01" />
  85. <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" />
  86. </svg>
  87. </div>
  88. <div>
  89. <h4 class="alert-title">Uh oh, something went wrong</h4>
  90. <div class="text-secondary">Sorry! There was a problem with your request.</div>
  91. </div>
  92. </div>
  93. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  94. </div>
  95. <div class="alert alert-danger alert-dismissible" role="alert">
  96. <div class="d-flex">
  97. <div>
  98. <svg xmlns="http://www.w3.org/2000/svg" class="icon alert-icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  99. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  100. <circle cx="12" cy="12" r="9" />
  101. <line x1="12" y1="8" x2="12" y2="12" />
  102. <line x1="12" y1="16" x2="12.01" y2="16" />
  103. </svg>
  104. </div>
  105. <div>
  106. <h4 class="alert-title">I'm so sorry&hellip;</h4>
  107. <div class="text-secondary">Your account has been deleted and can't be restored.</div>
  108. </div>
  109. </div>
  110. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  111. </div>
  112. ```
  113. ```html
  114. <div class="alert alert-success alert-dismissible" role="alert">
  115. <div class="d-flex">
  116. <div>
  117. <!-- SVG icon from http://tabler-icons.io/i/check -->
  118. <svg>...</svg>
  119. </div>
  120. <div>
  121. <h4 class="alert-title">Wow! Everything worked!</h4>
  122. <div class="text-secondary">Your account has been saved!</div>
  123. </div>
  124. </div>
  125. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  126. </div>
  127. ```
  128. ## Alerts with icons
  129. Add an icon to your alert modal to make it more user-friendly and help users easily identify the message.
  130. ```html example
  131. <div class="alert alert-success" role="alert">
  132. <div class="d-flex">
  133. <div>
  134. <svg xmlns="http://www.w3.org/2000/svg" class="icon alert-icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  135. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  136. <path d="M5 12l5 5l10 -10" />
  137. </svg>
  138. </div>
  139. <div>
  140. <h4 class="alert-title">Wow! Everything worked!</h4>
  141. <div class="text-secondary">Your account has been saved!</div>
  142. </div>
  143. </div>
  144. </div>
  145. <div class="alert alert-info" role="alert">
  146. <div class="d-flex">
  147. <div>
  148. <svg xmlns="http://www.w3.org/2000/svg" class="icon alert-icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  149. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  150. <circle cx="12" cy="12" r="9" />
  151. <line x1="12" y1="8" x2="12.01" y2="8" />
  152. <polyline points="11 12 12 12 12 16 13 16" />
  153. </svg>
  154. </div>
  155. <div>
  156. <h4 class="alert-title">Did you know?</h4>
  157. <div class="text-secondary">Here is something that you might like to know.</div>
  158. </div>
  159. </div>
  160. </div>
  161. <div class="alert alert-warning" role="alert">
  162. <div class="d-flex">
  163. <div>
  164. <svg xmlns="http://www.w3.org/2000/svg" class="icon alert-icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  165. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  166. <path d="M12 9v2m0 4v.01" />
  167. <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" />
  168. </svg>
  169. </div>
  170. <div>
  171. <h4 class="alert-title">Uh oh, something went wrong</h4>
  172. <div class="text-secondary">Sorry! There was a problem with your request.</div>
  173. </div>
  174. </div>
  175. </div>
  176. <div class="alert alert-danger" role="alert">
  177. <div class="d-flex">
  178. <div>
  179. <svg xmlns="http://www.w3.org/2000/svg" class="icon alert-icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  180. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  181. <circle cx="12" cy="12" r="9" />
  182. <line x1="12" y1="8" x2="12" y2="12" />
  183. <line x1="12" y1="16" x2="12.01" y2="16" />
  184. </svg>
  185. </div>
  186. <div>
  187. <h4 class="alert-title">I'm so sorry&hellip;</h4>
  188. <div class="text-secondary">Your account has been deleted and can't be restored.</div>
  189. </div>
  190. </div>
  191. </div>
  192. ```
  193. ```html
  194. <div class="alert alert-success" role="alert">
  195. <div class="d-flex">
  196. <div>
  197. <!-- SVG icon from http://tabler-icons.io/i/check -->
  198. <svg>...</svg>
  199. </div>
  200. <div>
  201. <h4 class="alert-title">Wow! Everything worked!</h4>
  202. <div class="text-secondary">Your account has been saved!</div>
  203. </div>
  204. </div>
  205. </div>
  206. <div class="alert alert-info" role="alert">
  207. <div class="d-flex">
  208. <div>
  209. <!-- SVG icon from http://tabler-icons.io/i/info-circle -->
  210. <svg>...</svg>
  211. </div>
  212. <div>
  213. <h4 class="alert-title">Did you know?</h4>
  214. <div class="text-secondary">Here is something that you might like to know.</div>
  215. </div>
  216. </div>
  217. </div>
  218. <div class="alert alert-warning" role="alert">
  219. <div class="d-flex">
  220. <div>
  221. <!-- SVG icon from http://tabler-icons.io/i/alert-triangle -->
  222. <svg>...</svg>
  223. </div>
  224. <div>
  225. <h4 class="alert-title">Uh oh, something went wrong</h4>
  226. <div class="text-secondary">Sorry! There was a problem with your request.</div>
  227. </div>
  228. </div>
  229. </div>
  230. <div class="alert alert-danger" role="alert">
  231. <div class="d-flex">
  232. <div>
  233. <!-- SVG icon from http://tabler-icons.io/i/alert-circle -->
  234. <svg>...</svg>
  235. </div>
  236. <div>
  237. <h4 class="alert-title">I'm so sorry&hellip;</h4>
  238. <div class="text-secondary">Your account has been deleted and can't be restored.</div>
  239. </div>
  240. </div>
  241. </div>
  242. ```
  243. ## Alert with avatar
  244. Add an avatar to your alert modal to make it more personalized.
  245. ```html code example
  246. <div class="alert alert-success" role="alert">
  247. <div class="d-flex">
  248. <div>
  249. <span class="avatar float-start me-3"></span>
  250. </div>
  251. <div>
  252. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit.
  253. </div>
  254. </div>
  255. </div>
  256. <div class="alert alert-info" role="alert">
  257. <div class="d-flex">
  258. <div>
  259. <span class="avatar float-start me-3">JL</span>
  260. </div>
  261. <div>
  262. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit.
  263. </div>
  264. </div>
  265. </div>
  266. <div class="alert alert-warning" role="alert">
  267. <div class="d-flex">
  268. <div>
  269. <span class="avatar float-start me-3"></span>
  270. </div>
  271. <div>
  272. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit.
  273. </div>
  274. </div>
  275. </div>
  276. <div class="alert alert-danger" role="alert">
  277. <div class="d-flex">
  278. <div>
  279. <span class="avatar float-start me-3"></span>
  280. </div>
  281. <div>
  282. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit.
  283. </div>
  284. </div>
  285. </div>
  286. ```
  287. ## Alert with buttons
  288. Add primary and secondary buttons to your alert modals if you want users to take a particular action based on the information included in the modal message.
  289. ```html code example
  290. <div class="alert alert-success alert-dismissible" role="alert">
  291. <h3 class="mb-1">Some Title</h3>
  292. <p>Lorem ipsum Minim ad pariatur eiusmod ea ut nulla aliqua est quis id dolore minim voluptate.</p>
  293. <div class="btn-list">
  294. <a href="#" class="btn btn-success">Okay</a>
  295. <a href="#" class="btn">Cancel</a>
  296. </div>
  297. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  298. </div>
  299. <div class="alert alert-info alert-dismissible" role="alert">
  300. <h3 class="mb-1">Some Title</h3>
  301. <p>Lorem ipsum Minim ad pariatur eiusmod ea ut nulla aliqua est quis id dolore minim voluptate.</p>
  302. <div class="btn-list">
  303. <a href="#" class="btn btn-info">Okay</a>
  304. <a href="#" class="btn">Cancel</a>
  305. </div>
  306. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  307. </div>
  308. <div class="alert alert-warning alert-dismissible" role="alert">
  309. <h3 class="mb-1">Some Title</h3>
  310. <p>Lorem ipsum Minim ad pariatur eiusmod ea ut nulla aliqua est quis id dolore minim voluptate.</p>
  311. <div class="btn-list">
  312. <a href="#" class="btn btn-warning">Okay</a>
  313. <a href="#" class="btn">Cancel</a>
  314. </div>
  315. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  316. </div>
  317. <div class="alert alert-danger alert-dismissible" role="alert">
  318. <h3 class="mb-1">Some Title</h3>
  319. <p>Lorem ipsum Minim ad pariatur eiusmod ea ut nulla aliqua est quis id dolore minim voluptate.</p>
  320. <div class="btn-list">
  321. <a href="#" class="btn btn-danger">Okay</a>
  322. <a href="#" class="btn">Cancel</a>
  323. </div>
  324. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  325. </div>
  326. ```
  327. ## Important alerts
  328. If you want your alert to be really eye-catching, you can add a class `alert-important`.
  329. ```html example
  330. <div class="alert alert-important alert-danger alert-dismissible" role="alert">
  331. <div class="d-flex">
  332. <div>
  333. <svg xmlns="http://www.w3.org/2000/svg" class="icon alert-icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  334. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  335. <circle cx="12" cy="12" r="9" />
  336. <line x1="12" y1="8" x2="12" y2="12" />
  337. <line x1="12" y1="16" x2="12.01" y2="16" />
  338. </svg>
  339. </div>
  340. <div>Your account has been deleted and can't be restored.</div>
  341. </div>
  342. <a class="btn-close btn-close-white" data-bs-dismiss="alert" aria-label="close"></a>
  343. </div>
  344. ```
  345. ```html
  346. <div class="alert alert-important alert-success alert-dismissible" role="alert">
  347. <div class="d-flex">
  348. <div>
  349. <!-- SVG icon from http://tabler-icons.io/i/check -->
  350. <svg>...</svg>
  351. </div>
  352. <div>
  353. Your account has been saved!
  354. </div>
  355. </div>
  356. <a class="btn-close btn-close-white" data-bs-dismiss="alert" aria-label="close"></a>
  357. </div>
  358. <div class="alert alert-important alert-info alert-dismissible" role="alert">
  359. <div class="d-flex">
  360. <div>
  361. <!-- SVG icon from http://tabler-icons.io/i/info-circle -->
  362. <svg>...</svg>
  363. </div>
  364. <div>
  365. Here is something that you might like to know.
  366. </div>
  367. </div>
  368. <a class="btn-close btn-close-white" data-bs-dismiss="alert" aria-label="close"></a>
  369. </div>
  370. <div class="alert alert-important alert-warning alert-dismissible" role="alert">
  371. <div class="d-flex">
  372. <div>
  373. <!-- SVG icon from http://tabler-icons.io/i/alert-triangle -->
  374. <svg>...</svg>
  375. </div>
  376. <div>
  377. Sorry! There was a problem with your request.
  378. </div>
  379. </div>
  380. <a class="btn-close btn-close-white" data-bs-dismiss="alert" aria-label="close"></a>
  381. </div>
  382. <div class="alert alert-important alert-danger alert-dismissible" role="alert">
  383. <div class="d-flex">
  384. <div>
  385. <!-- SVG icon from http://tabler-icons.io/i/alert-circle -->
  386. <svg>...</svg>
  387. </div>
  388. <div>
  389. Your account has been deleted and can't be restored.
  390. </div>
  391. </div>
  392. <a class="btn-close btn-close-white" data-bs-dismiss="alert" aria-label="close"></a>
  393. </div>
  394. ```