Popovers
A popover shows a small floating box with a title and content when an element is clicked.
In this page:
Syntax
<button data-bs-toggle="popover" data-bs-title="Title" data-bs-content="Content">Click</button>
<script>
new bootstrap.Popover(element);
</script>
Popovers
Popovers are opt-in: initialise them in JavaScript with new bootstrap.Popover(element), and set data-bs-toggle="popover", data-bs-title and data-bs-content on the trigger.
Placement is chosen with data-bs-placement. They use Popper for positioning and are triggered by click by default.
Note:
Popovers and tooltips must be initialised manually for performance reasons.
Example: Popovers
<!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">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body class="p-3">
<div class="container">
<button type="button" class="btn btn-secondary" data-bs-toggle="popover" data-bs-title="Popover title" data-bs-content="And here is some amazing content." data-bs-placement="right">Click for popover</button>
</div>
<script>
document.querySelectorAll('[data-bs-toggle="popover"]').forEach((el) => new bootstrap.Popover(el));
</script>
</body>
</html>
Live Example
Related Topics
Common Mistakes
- Forgetting to initialise them
- Using them on disabled elements
- Hiding critical info in popovers
Chapter Summary
- Popovers must be initialised
- data-bs-title and data-bs-content
- data-bs-placement positions
- Click trigger by default
🔒
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: