<metaname="description"content="Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages.">
<metaname="author"content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
<metaname="twitter:description"content="Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages.">
<metaproperty="og:description"content="Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages.">
<aclass="btn btn-sm btn-bd-light my-2 my-md-0"href="https://github.com/twbs/bootstrap/blob/v4-dev/site/content/docs/4.6/components/alerts.md"title="View and edit this file on GitHub"target="_blank"rel="noopener">View on GitHub</a>
<h1class="bd-title"id="content">Alerts</h1>
</div>
<pclass="bd-lead">Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages.</p>
<p>Alerts are available for any length of text, as well as an optional dismiss button. For proper styling, use one of the eight <strong>required</strong> contextual classes (e.g., <code>.alert-success</code>). For inline dismissal, use the <ahref="#dismissing">alerts jQuery plugin</a>.</p>
<h5id="conveying-meaning-to-assistive-technologies">Conveying meaning to assistive technologies</h5>
<p>Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (e.g. the visible text), or is included through alternative means, such as additional text hidden with the <code>.sr-only</code> class.
</div>
<h3id="link-color">Link color</h3>
<p>Use the <code>.alert-link</code> utility class to quickly provide matching colored links within any alert.</p>
<divclass="bd-example">
<divclass="alert alert-primary"role="alert">
A simple primary alert with <ahref="#"class="alert-link">an example link</a>. Give it a click if you like.
</div>
<divclass="alert alert-secondary"role="alert">
A simple secondary alert with <ahref="#"class="alert-link">an example link</a>. Give it a click if you like.
</div>
<divclass="alert alert-success"role="alert">
A simple success alert with <ahref="#"class="alert-link">an example link</a>. Give it a click if you like.
</div>
<divclass="alert alert-danger"role="alert">
A simple danger alert with <ahref="#"class="alert-link">an example link</a>. Give it a click if you like.
</div>
<divclass="alert alert-warning"role="alert">
A simple warning alert with <ahref="#"class="alert-link">an example link</a>. Give it a click if you like.
</div>
<divclass="alert alert-info"role="alert">
A simple info alert with <ahref="#"class="alert-link">an example link</a>. Give it a click if you like.
</div>
<divclass="alert alert-light"role="alert">
A simple light alert with <ahref="#"class="alert-link">an example link</a>. Give it a click if you like.
</div>
<divclass="alert alert-dark"role="alert">
A simple dark alert with <ahref="#"class="alert-link">an example link</a>. Give it a click if you like.
A simple primary alert with <spanclass="p"><</span><spanclass="nt">a</span><spanclass="na">href</span><spanclass="o">=</span><spanclass="s">"#"</span><spanclass="na">class</span><spanclass="o">=</span><spanclass="s">"alert-link"</span><spanclass="p">></span>an example link<spanclass="p"></</span><spanclass="nt">a</span><spanclass="p">></span>. Give it a click if you like.
A simple secondary alert with <spanclass="p"><</span><spanclass="nt">a</span><spanclass="na">href</span><spanclass="o">=</span><spanclass="s">"#"</span><spanclass="na">class</span><spanclass="o">=</span><spanclass="s">"alert-link"</span><spanclass="p">></span>an example link<spanclass="p"></</span><spanclass="nt">a</span><spanclass="p">></span>. Give it a click if you like.
A simple success alert with <spanclass="p"><</span><spanclass="nt">a</span><spanclass="na">href</span><spanclass="o">=</span><spanclass="s">"#"</span><spanclass="na">class</span><spanclass="o">=</span><spanclass="s">"alert-link"</span><spanclass="p">></span>an example link<spanclass="p"></</span><spanclass="nt">a</span><spanclass="p">></span>. Give it a click if you like.
A simple danger alert with <spanclass="p"><</span><spanclass="nt">a</span><spanclass="na">href</span><spanclass="o">=</span><spanclass="s">"#"</span><spanclass="na">class</span><spanclass="o">=</span><spanclass="s">"alert-link"</span><spanclass="p">></span>an example link<spanclass="p"></</span><spanclass="nt">a</span><spanclass="p">></span>. Give it a click if you like.
A simple warning alert with <spanclass="p"><</span><spanclass="nt">a</span><spanclass="na">href</span><spanclass="o">=</span><spanclass="s">"#"</span><spanclass="na">class</span><spanclass="o">=</span><spanclass="s">"alert-link"</span><spanclass="p">></span>an example link<spanclass="p"></</span><spanclass="nt">a</span><spanclass="p">></span>. Give it a click if you like.
A simple info alert with <spanclass="p"><</span><spanclass="nt">a</span><spanclass="na">href</span><spanclass="o">=</span><spanclass="s">"#"</span><spanclass="na">class</span><spanclass="o">=</span><spanclass="s">"alert-link"</span><spanclass="p">></span>an example link<spanclass="p"></</span><spanclass="nt">a</span><spanclass="p">></span>. Give it a click if you like.
A simple light alert with <spanclass="p"><</span><spanclass="nt">a</span><spanclass="na">href</span><spanclass="o">=</span><spanclass="s">"#"</span><spanclass="na">class</span><spanclass="o">=</span><spanclass="s">"alert-link"</span><spanclass="p">></span>an example link<spanclass="p"></</span><spanclass="nt">a</span><spanclass="p">></span>. Give it a click if you like.
A simple dark alert with <spanclass="p"><</span><spanclass="nt">a</span><spanclass="na">href</span><spanclass="o">=</span><spanclass="s">"#"</span><spanclass="na">class</span><spanclass="o">=</span><spanclass="s">"alert-link"</span><spanclass="p">></span>an example link<spanclass="p"></</span><spanclass="nt">a</span><spanclass="p">></span>. Give it a click if you like.
<p>Alerts can also contain additional HTML elements like headings, paragraphs and dividers.</p>
<divclass="bd-example">
<divclass="alert alert-success"role="alert">
<h4class="alert-heading">Well done!</h4>
<p>Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.</p>
<hr>
<pclass="mb-0">Whenever you need to, be sure to use margin utilities to keep things nice and tidy.</p>
<spanclass="p"><</span><spanclass="nt">p</span><spanclass="p">></span>Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.<spanclass="p"></</span><spanclass="nt">p</span><spanclass="p">></span>
<spanclass="p"><</span><spanclass="nt">p</span><spanclass="na">class</span><spanclass="o">=</span><spanclass="s">"mb-0"</span><spanclass="p">></span>Whenever you need to, be sure to use margin utilities to keep things nice and tidy.<spanclass="p"></</span><spanclass="nt">p</span><spanclass="p">></span>
<p>Using the alert JavaScript plugin, it’s possible to dismiss any alert inline. Here’s how:</p>
<ul>
<li>Be sure you’ve loaded the alert plugin, or the compiled Bootstrap JavaScript.</li>
<li>If you’re building our JavaScript from source, it <ahref="/docs/4.6/getting-started/javascript/#util">requires <code>util.js</code></a>. The compiled version includes this.</li>
<li>Add a dismiss button and the <code>.alert-dismissible</code> class, which adds extra padding to the right of the alert and positions the <code>.close</code> button.</li>
<li>On the dismiss button, add the <code>data-dismiss="alert"</code> attribute, which triggers the JavaScript functionality. Be sure to use the <code><button></code> element with it for proper behavior across all devices.</li>
<li>To animate alerts when dismissing them, be sure to add the <code>.fade</code> and <code>.show</code> classes.</li>
</ul>
<p>You can see this in action with a live demo:</p>
<spanclass="p"><</span><spanclass="nt">strong</span><spanclass="p">></span>Holy guacamole!<spanclass="p"></</span><spanclass="nt">strong</span><spanclass="p">></span> You should check in on some of those fields below.
</code></pre></div><p>Note that closing an alert will remove it from the DOM.</p>
<h3id="methods">Methods</h3>
<table>
<thead>
<tr>
<th>Method</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>$().alert()</code></td>
<td>Makes an alert listen for click events on descendant elements which have the <code>data-dismiss="alert"</code> attribute. (Not necessary when using the data-api’s auto-initialization.)</td>
</tr>
<tr>
<td><code>$().alert('close')</code></td>
<td>Closes an alert by removing it from the DOM. If the <code>.fade</code> and <code>.show</code> classes are present on the element, the alert will fade out before it is removed.</td>