Open In App

Bootstrap 5 Tooltips Usage Options

Bootstrap 5 Tooltip usage options can be passed through the data attributes or via javascript. To pass the options through data attributes we have to append the option name with the data-bs for example data-bs-animation=”true”.

Some of the many options available are:



Options can be passed via javascript as well.

Example 1: In this example, we will demonstrate the tooltip option trigger through which we can specify the user action that will trigger the tooltip.






<!DOCTYPE>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1">
    <link href=
          rel="stylesheet">
    <script src=
    </script>
</head>
  
<body >
    <div class="container">
        <center>
          
            <h1 class="text-success">GeeksforGeeks</h1>
          <strong>Bootstrap 5 Tooltip Usage Options</strong>
            <button type="button" 
                    class="btn btn-primary" 
                    data-bs-toggle="tooltip" 
                    data-bs-placement="top" 
                    data-bs-trigger="cilck"
                    title="Tooltip on top">
              Click on to show tooltip
          </button>
  
        </center>
    </div>
  
    <script type="text/javascript">
      var tooltipTriggerList = 
          [].slice.call(document
                .querySelectorAll('[data-bs-toggle="tooltip"]'))
      var tooltipList = tooltipTriggerList
                              .map(function (tooltipTriggerEl) {
        return new bootstrap
                        .Tooltip(tooltipTriggerEl)
       })
    </script>
</body>
</html>

Output:

Bootstrap 5 Tooltips Usage Options

Example 2: In this example, we will demonstrate the tooltip option data-bs-placement through which we can place the tooltip in different places.




<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1">
    <link href=
          rel="stylesheet">
    <script src=
    </script>
</head>
  
<body>
    <div class="container">
        <center>
            <h1 class="text-success">GeeksforGeeks</h1>
            <strong>Bootstrap 5 Tooltip Usage Options</strong>
            <br>
            <button type="button" 
                    class="btn btn-primary" 
                    data-bs-toggle="tooltip" 
                    data-bs-placement="top" 
                    title="Tooltip on top">
              Tooltip on top
          </button>
            <button type="button" 
                    class="btn btn-primary"
                    data-bs-toggle="tooltip" 
                    data-bs-placement="right" 
                    title="Tooltip on right"
              Tooltip on right
          </button>
            <button type="button" 
                    class="btn btn-primary" 
                    data-bs-toggle="tooltip" 
                    data-bs-placement="bottom" 
                    title="Tooltip on bottom">
              Tooltip on bottom
          </button>
          <button type="button" 
                  class="btn btn-primary" 
                  data-bs-toggle="tooltip" 
                  data-bs-placement="left" 
                  title="Tooltip on left">
              Tooltip on left
          </button>
        </center>
    </div>
  
    <script type="text/javascript">
        var tooltipTriggerList = 
          [].slice.call(document
                      .querySelectorAll('[data-bs-toggle="tooltip"]'))
        var tooltipList = tooltipTriggerList
                            .map(function (tooltipTriggerEl) {
          return new bootstrap
                          .Tooltip(tooltipTriggerEl)
})
    </script>
</body>
</html>

Output :

Bootstrap 5 Tooltips Usage Options

Reference: https://getbootstrap.com/docs/5.0/components/tooltips/#options


Article Tags :