Alert types
Alerts show short, coloured messages about success, warnings or errors.
In this page:
Syntax
<div class="alert alert-success" role="alert">Message</div>
<div class="alert alert-danger" role="alert">Message</div>
Alert types
Use .alert with a contextual class such as .alert-success, .alert-warning, .alert-danger or .alert-info and role="alert".
Links inside use .alert-link. You can add headings and paragraphs.
Colour should be supported by text, since not all users see colour.
Note:
role="alert" makes screen readers announce the message.
Example: Alert types
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="container">
<div class="alert alert-success" role="alert">Saved! Your changes were stored.</div>
<div class="alert alert-warning" role="alert">Warning: disk space is low.</div>
<div class="alert alert-danger" role="alert">Error: could not connect. <a href="#" class="alert-link">Try again</a></div>
<div class="alert alert-info" role="alert">Tip: press ? to see shortcuts.</div>
</div>
</body>
</html>
Live Example
Related Topics
Common Mistakes
- Missing role alert
- Relying only on colour
- Using alerts for permanent content
Chapter Summary
- alert plus contextual class
- role="alert" for accessibility
- alert-link styles links
- Colour needs supporting text
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: