Bootstrap 5 Alerts Icons are used so as to add icons to the alert bar to format the bar and make it extra informative. To incorporate the icon utilizing <svg> tag we have now to outline its path contained in the <path> tag in svg tag. We additionally have to specify its top and width to regulate its dimension in accordance with the notification dimension.
Alert Icons Lessons: No particular courses are utilized in Alerts Icons. You’ll be able to customise the Record utilizing Bootstrap icon courses and magnificence them with flexbox utilities. (We should embody the bootstrap 5 icons CSS file)
Alert icon Attributes(for svg tag solely):
- width: To specify width inside the icon.
- top: To specify top of icon.
- fill: To specify colour of the icon often set to currentColor.
- d: Used inside path tag to specify the trail.
Syntax:
<div class="alert alert-...>
// To show icon utilizing i tag
<i class="bi bi-..."></i>
</div>
// To show icon utilizing svg tag
<svg width="..." top="..." fill="..." class="bi bi-">
<path d="...">
</svg>
Instance 1: The next code demonstrates the Alert Icons utilizing the svg tag.
HTML
<!DOCTYPE html>
< html >
< head >
< hyperlink rel = "stylesheet"
href =
< hyperlink rel = "stylesheet"
href =
</ head >
< physique class = "m-3" >
< h1 class = "text-success" >
GeeksforGeeks
</ h1 >
< sturdy >
Bootstrap 5 Alert Icons
</ sturdy >
< div class = "alert alert-danger d-flex align-items-center" >
< svg width = "24" top = "24"
fill = "currentColor"
class = "bi bi-exclamation-triangle-fill flex-shrink-0 mt-2" >
< path d="M8.982 1.566a1.13 1.13 0 0 0-1.96
0L.165 13.233c-.457.778.091 1.767.98
1.767h13.713c.889 0 1.438-.99.98-1.767L8.982
1.566zM8 5c.535 0 .954.462.9.995l-.35
3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905
0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z" />
</ svg >
< div >
:Alert hazard
</ div >
</ physique >
</ html >
|
Output:

Instance 2: The next code demonstrates a number of icons utilizing the Bootstrap 5 Alert properties with the assistance of <i> tag.
HTML
<!DOCTYPE html>
< html >
< head >
< hyperlink rel = "stylesheet"
href =
< hyperlink rel = "stylesheet"
href =
</ head >
< physique class = "m-3" >
< h1 class = "text-success" >
GeeksforGeeks
</ h1 >
< sturdy >
Bootstrap 5 Alert with icons
</ sturdy >
< div class = "alert alert-danger d-flex" >
< i class = "bi bi-exclamation-triangle-fill " >
Alert field Hazard
</ i >
</ div >
< div class = "alert alert-primary d-flex" >
< i class = "bi bi-info-circle-fill" >
Alert field Major
</ i >
</ div >
< div class = "alert alert-warning d-flex" >
< i class = "bi bi-exclamation-triangle-fill" >
Alert field Warning
</ i >
</ div >
< div class = "alert alert-success d-flex" >
< i class = "bi bi-check-circle-fill" >
Alert field Success
</ i >
</ div >
</ physique >
</ html >
</ html >
|
Output:

Reference: https://getbootstrap.com/docs/5.0/elements/alerts/#icons