Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Creating Custom Template for Bootstrap Tooltips Using JavaScript</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script> <style> .bs-example{ margin: 150px; } /* Styles for custom tooltip template */ .tooltip-head{ color: #fff; background: #000; padding: 10px 10px 5px; border-radius: 4px 4px 0 0; text-align: center; margin-bottom: -2px; /* Hide default tooltip rounded corner from top */ } .tooltip-head h3{ margin: 0; font-size: 18px; } .tooltip-head i{ font-size: 22px; vertical-align: bottom; } </style> <script> document.addEventListener("DOMContentLoaded", function(){ var element = document.getElementById("myTooltip"); var tooltip = new bootstrap.Tooltip(element, { template: '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-head"><h3><i class="bi-info-circle"></i> Important Info</h3></div><div class="tooltip-inner"></div>' }); }); </script> </head> <body> <div class="bs-example"> <p> <a href="#" id="myTooltip" data-bs-toggle="tooltip" title="This is a simple example of custom Bootstrap tooltip.">Hover over me</a> </p> </div> </body> </html>