alerts.mdx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. ---
  2. title: Alerts
  3. summary: 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. description: Alert messages for user notifications.
  6. ---
  7. ## Default markup
  8. 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.
  9. Combine `alert` class with one of the following: `alert-success`, `alert-info`, `alert-warning`, `alert-danger` to get the alert that you need.
  10. Alert classes affect the color of all the text inside an alert. Use another class, e.g. `text-secondary` to change the color of the alert's content.
  11. ```html example vertical background="surface" columns={2} centered separated height="420px"
  12. <div class="alert alert-success" role="alert">
  13. <h4 class="alert-title">Wow! Everything worked!</h4>
  14. <div class="text-secondary">Your account has been saved!</div>
  15. </div>
  16. <div class="alert alert-info" role="alert">
  17. <h4 class="alert-title">Did you know?</h4>
  18. <div class="text-secondary">Here is something that you might like to know.</div>
  19. </div>
  20. <div class="alert alert-warning" role="alert">
  21. <h4 class="alert-title">Uh oh, something went wrong</h4>
  22. <div class="text-secondary">Sorry! There was a problem with your request.</div>
  23. </div>
  24. <div class="alert alert-danger" role="alert">
  25. <h4 class="alert-title">I'm so sorry&hellip;</h4>
  26. <div class="text-secondary">Your account has been deleted and can't be restored.</div>
  27. </div>
  28. ```
  29. ## Alert links
  30. Add a link to your alert message to redirect users to the details they need to complete or additional information they should read. Use `alert-link` class to style the link and match the text color.
  31. ```html example vertical background="surface" columns={2} centered height="120px"
  32. <div class="alert alert-danger m-0">This is a danger alert — <a href="#" class="alert-link">check it out</a>!</div>
  33. ```
  34. ## Dismissible alerts
  35. 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.
  36. ```html
  37. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  38. ```
  39. ```html example vertical background="surface" columns={2} centered separated height="420px"
  40. <div class="alert alert-success alert-dismissible" role="alert">
  41. <div>
  42. <h4 class="alert-title">Wow! Everything worked!</h4>
  43. <div class="text-secondary">Your account has been saved!</div>
  44. </div>
  45. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  46. </div>
  47. <div class="alert alert-info alert-dismissible" role="alert">
  48. <div>
  49. <h4 class="alert-title">Did you know?</h4>
  50. <div class="text-secondary">Here is something that you might like to know.</div>
  51. </div>
  52. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  53. </div>
  54. <div class="alert alert-warning alert-dismissible" role="alert">
  55. <div>
  56. <h4 class="alert-title">Uh oh, something went wrong</h4>
  57. <div class="text-secondary">Sorry! There was a problem with your request.</div>
  58. </div>
  59. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  60. </div>
  61. <div class="alert alert-danger alert-dismissible" role="alert">
  62. <div>
  63. <h4 class="alert-title">I'm so sorry&hellip;</h4>
  64. <div class="text-secondary">Your account has been deleted and can't be restored.</div>
  65. </div>
  66. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  67. </div>
  68. ```
  69. ## Alerts with icons
  70. Add an icon to your alert modal to make it more user-friendly and help users easily identify the message.
  71. Use `alert-icon` class for `<svg>` or `<i>`, when using webfont, to provide the proper styling.
  72. ```html example vertical background="surface" columns={2} centered separated height="420px"
  73. <div class="alert alert-success" role="alert">
  74. <div class="d-flex">
  75. <div>
  76. <svg
  77. xmlns="http://www.w3.org/2000/svg"
  78. class="icon alert-icon"
  79. width="24"
  80. height="24"
  81. viewBox="0 0 24 24"
  82. stroke-width="2"
  83. stroke="currentColor"
  84. fill="none"
  85. stroke-linecap="round"
  86. stroke-linejoin="round"
  87. >
  88. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  89. <path d="M5 12l5 5l10 -10" />
  90. </svg>
  91. </div>
  92. <div>
  93. <h4 class="alert-title">Wow! Everything worked!</h4>
  94. <div class="text-secondary">Your account has been saved!</div>
  95. </div>
  96. </div>
  97. </div>
  98. <div class="alert alert-info" role="alert">
  99. <div class="d-flex">
  100. <div>
  101. <svg
  102. xmlns="http://www.w3.org/2000/svg"
  103. class="icon alert-icon"
  104. width="24"
  105. height="24"
  106. viewBox="0 0 24 24"
  107. stroke-width="2"
  108. stroke="currentColor"
  109. fill="none"
  110. stroke-linecap="round"
  111. stroke-linejoin="round"
  112. >
  113. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  114. <circle cx="12" cy="12" r="9" />
  115. <line x1="12" y1="8" x2="12.01" y2="8" />
  116. <polyline points="11 12 12 12 12 16 13 16" />
  117. </svg>
  118. </div>
  119. <div>
  120. <h4 class="alert-title">Did you know?</h4>
  121. <div class="text-secondary">Here is something that you might like to know.</div>
  122. </div>
  123. </div>
  124. </div>
  125. <div class="alert alert-warning" role="alert">
  126. <div class="d-flex">
  127. <div>
  128. <svg
  129. xmlns="http://www.w3.org/2000/svg"
  130. class="icon alert-icon"
  131. width="24"
  132. height="24"
  133. viewBox="0 0 24 24"
  134. stroke-width="2"
  135. stroke="currentColor"
  136. fill="none"
  137. stroke-linecap="round"
  138. stroke-linejoin="round"
  139. >
  140. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  141. <path d="M12 9v2m0 4v.01" />
  142. <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" />
  143. </svg>
  144. </div>
  145. <div>
  146. <h4 class="alert-title">Uh oh, something went wrong</h4>
  147. <div class="text-secondary">Sorry! There was a problem with your request.</div>
  148. </div>
  149. </div>
  150. </div>
  151. <div class="alert alert-danger" role="alert">
  152. <div class="d-flex">
  153. <div>
  154. <svg
  155. xmlns="http://www.w3.org/2000/svg"
  156. class="icon alert-icon"
  157. width="24"
  158. height="24"
  159. viewBox="0 0 24 24"
  160. stroke-width="2"
  161. stroke="currentColor"
  162. fill="none"
  163. stroke-linecap="round"
  164. stroke-linejoin="round"
  165. >
  166. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  167. <circle cx="12" cy="12" r="9" />
  168. <line x1="12" y1="8" x2="12" y2="12" />
  169. <line x1="12" y1="16" x2="12.01" y2="16" />
  170. </svg>
  171. </div>
  172. <div>
  173. <h4 class="alert-title">I'm so sorry&hellip;</h4>
  174. <div class="text-secondary">Your account has been deleted and can't be restored.</div>
  175. </div>
  176. </div>
  177. </div>
  178. ```
  179. ## Alert with avatar
  180. Add an avatar to your alert modal to make it more personalized.
  181. ```html example vertical background="surface" columns={2} centered separated height="420px"
  182. <div class="alert alert-success" role="alert">
  183. <div class="d-flex">
  184. <div>
  185. <span class="avatar me-3" style="background-image: url(/static/samples/avatars/039m.jpg)"></span>
  186. </div>
  187. <div>
  188. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit.
  189. </div>
  190. </div>
  191. </div>
  192. <div class="alert alert-info" role="alert">
  193. <div class="d-flex">
  194. <div>
  195. <span class="avatar me-3">JL</span>
  196. </div>
  197. <div>
  198. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit.
  199. </div>
  200. </div>
  201. </div>
  202. <div class="alert alert-warning" role="alert">
  203. <div class="d-flex">
  204. <div>
  205. <span class="avatar me-3" style="background-image: url(/static/samples/avatars/035f.jpg)"></span>
  206. </div>
  207. <div>
  208. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit.
  209. </div>
  210. </div>
  211. </div>
  212. <div class="alert alert-danger" role="alert">
  213. <div class="d-flex">
  214. <div>
  215. <span class="avatar me-3" style="background-image: url(/static/samples/avatars/056f.jpg)"></span>
  216. </div>
  217. <div>
  218. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet, consectetur adipisicing elit.
  219. </div>
  220. </div>
  221. </div>
  222. ```
  223. ## Alert with buttons
  224. 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.
  225. Buttons don't inherit the alert's color, so you should set the proper class if you want it to be matched. For example, `btn-success` for `alert-success`.
  226. ```html example vertical background="surface" columns={2} centered separated height="740px"
  227. <div class="alert alert-success alert-dismissible" role="alert">
  228. <h3 class="mb-1">Some Title</h3>
  229. <p class="text-secondary">
  230. Lorem ipsum Minim ad pariatur eiusmod ea ut nulla aliqua est quis id dolore minim voluptate.
  231. </p>
  232. <div class="btn-list">
  233. <a href="#" class="btn btn-success">Okay</a>
  234. <a href="#" class="btn">Cancel</a>
  235. </div>
  236. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  237. </div>
  238. <div class="alert alert-info alert-dismissible" role="alert">
  239. <h3 class="mb-1">Some Title</h3>
  240. <p class="text-secondary">
  241. Lorem ipsum Minim ad pariatur eiusmod ea ut nulla aliqua est quis id dolore minim voluptate.
  242. </p>
  243. <div class="btn-list">
  244. <a href="#" class="btn btn-info">Okay</a>
  245. <a href="#" class="btn">Cancel</a>
  246. </div>
  247. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  248. </div>
  249. <div class="alert alert-warning alert-dismissible" role="alert">
  250. <h3 class="mb-1">Some Title</h3>
  251. <p class="text-secondary">
  252. Lorem ipsum Minim ad pariatur eiusmod ea ut nulla aliqua est quis id dolore minim voluptate.
  253. </p>
  254. <div class="btn-list">
  255. <a href="#" class="btn btn-warning">Okay</a>
  256. <a href="#" class="btn">Cancel</a>
  257. </div>
  258. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  259. </div>
  260. <div class="alert alert-danger alert-dismissible" role="alert">
  261. <h3 class="mb-1">Some Title</h3>
  262. <p class="text-secondary">
  263. Lorem ipsum Minim ad pariatur eiusmod ea ut nulla aliqua est quis id dolore minim voluptate.
  264. </p>
  265. <div class="btn-list">
  266. <a href="#" class="btn btn-danger">Okay</a>
  267. <a href="#" class="btn">Cancel</a>
  268. </div>
  269. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  270. </div>
  271. ```
  272. ## Important alerts
  273. If you want your alert to be really eye-catching, you can add a `alert-important` class. It will use the selected color as a background for the alert.
  274. ```html
  275. <div class="alert alert-important alert-success alert-dismissible" role="alert">...</div>
  276. ```
  277. You can also use other elements, like icons and dismissible buttons, with this type of alert.
  278. ```html example vertical columns={2} centered separated
  279. <div class="alert alert-important alert-success alert-dismissible" role="alert">
  280. <div class="d-flex">
  281. <div>
  282. <svg
  283. xmlns="http://www.w3.org/2000/svg"
  284. class="icon alert-icon"
  285. width="24"
  286. height="24"
  287. viewBox="0 0 24 24"
  288. stroke-width="2"
  289. stroke="currentColor"
  290. fill="none"
  291. stroke-linecap="round"
  292. stroke-linejoin="round"
  293. >
  294. <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
  295. <path d="M5 12l5 5l10 -10"></path>
  296. </svg>
  297. </div>
  298. <div>Wow! Everything worked!</div>
  299. </div>
  300. <a class="btn-close btn-close-white" data-bs-dismiss="alert" aria-label="close"></a>
  301. </div>
  302. <div class="alert alert-important alert-danger alert-dismissible" role="alert">
  303. <div class="d-flex">
  304. <div>
  305. <svg
  306. xmlns="http://www.w3.org/2000/svg"
  307. class="icon alert-icon"
  308. width="24"
  309. height="24"
  310. viewBox="0 0 24 24"
  311. stroke-width="2"
  312. stroke="currentColor"
  313. fill="none"
  314. stroke-linecap="round"
  315. stroke-linejoin="round"
  316. >
  317. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  318. <circle cx="12" cy="12" r="9" />
  319. <line x1="12" y1="8" x2="12" y2="12" />
  320. <line x1="12" y1="16" x2="12.01" y2="16" />
  321. </svg>
  322. </div>
  323. <div>Your account has been deleted and can't be restored.</div>
  324. </div>
  325. <a class="btn-close btn-close-white" data-bs-dismiss="alert" aria-label="close"></a>
  326. </div>
  327. ```
  328. ## Custom alert's color
  329. You're not limited to the 4 default alert's colors. You can use any [base or social color](../base/colors) you want.
  330. ```html example vertical background="surface" columns={2} centered separated height="420px"
  331. <div class="alert alert-lime" role="alert">
  332. <h4 class="alert-title">Wow! Everything worked!</h4>
  333. <div class="text-secondary">Your account has been saved!</div>
  334. </div>
  335. <div class="alert alert-cyan" role="alert">
  336. <h4 class="alert-title">Did you know?</h4>
  337. <div class="text-secondary">Here is something that you might like to know.</div>
  338. </div>
  339. <div class="alert alert-facebook" role="alert">
  340. <h4 class="alert-title">You have a new friend on Facebook</h4>
  341. <div class="text-secondary">Say hello to your new friend!</div>
  342. </div>
  343. <div class="alert alert-instagram alert-dismissible alert-important" role="alert">
  344. <div class="d-flex">
  345. <div>
  346. <span class="avatar me-3" style="background-image: url(/static/samples/avatars/035f.jpg)"></span>
  347. </div>
  348. <div>
  349. <h4 class="alert-title">Sophia just added a new post on Instagram</h4>
  350. <div>Be the first to see it!</div>
  351. </div>
  352. </div>
  353. <a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
  354. </div>
  355. ```