alerts.mdx 16 KB

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