Open In App

Bootstrap 5 Popover Component on Hover

Last Updated : 19 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The Bootstrap 5 Popover component allows for the creation of interactive hover-triggered tooltips that display additional content when hovering over an element. This feature enhances user experience by providing contextually relevant information without cluttering the interface, making it ideal for showcasing supplementary details or explanations.

Approach:

  • Structure your HTML with elements that will trigger the popovers.
  • Include the Bootstrap 5 CDN link in HTML file.
  • Add necessary data attributes to the popover trigger elements (data-bs-toggle=”popover”, data-bs-trigger=”hover”, data-bs-placement, title, and data-bs-content).
  • Customize popover styling using custom CSS classes if needed.
  • Initialize the popovers in your JavaScript code by selecting the trigger elements and creating Popover instances for each.

Popover from Top and Bottom

To display a popover from the top, set data-bs-trigger=”hover” and data-bs-placement=”top” attributes. Use the data-bs-content for the popover message. And to display a popover from the bottom, use the same approach as above but with data-bs-placement=”bottom”.

Example: Implementation to showcase popover from top and bottom.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href=
    <title>Bootstrap Popover</title>
    <style>
        .background {
            background-size: cover;
            background-position: center;
            background: rgb(58, 207, 92);
            min-height: 100vh;
            padding: 50px;
        }
  
        .popover {
            background-color: rgba(27, 27, 27, 0.8);
            color: white;
        }
  
        .popover-header {
            color: green;
        }
  
        .popover-body {
            color: white;
        }
    </style>
</head>
  
<body>
    <div class="background">
        <div class="container mt-5">
            <!-- Top -->
            <h3 class="text-center text-light">
                Hover the button for popover from top
                <button type="button" class="btn btn-primary" 
                        data-bs-toggle="popover" data-bs-trigger="hover"
                        data-bs-placement="top" title="Top popover"
                        data-bs-content="This is the content of the Top Popover.">
                    Hover me (Top)
                </button>
            </h3>
            <!-- Bottom -->
            <h3 class="text-center text-light">
                Hover the link for popover from bottom
                <a  href="#" class="btn btn-success" 
                       data-bs-toggle="popover" data-bs-trigger="hover"
                    data-bs-placement="bottom" title="Bottom Popover"
                    data-bs-content="This is the content of the Bottom Popover.">
                    Hover me (Bottom)
                </a>
            </h3>
        </div>
    </div>
    <script src=
      </script>
    <script>
        let popoverTriggerList = [].slice.call(
            document.querySelectorAll('[data-bs-toggle="popover"]'))
          
        let popoverList = 
        popoverTriggerList.map(function (popoverTriggerEl) {
            return new bootstrap.Popover(popoverTriggerEl)
        })
    </script>
</body>
  
</html>


Output:

aq

Popover from Left and Right

To display a popover from the left, set data-bs-trigger=”hover” and data-bs-placement=”left” attributes. Utilize the data-bs-content attribute for the popover message. Similarly, to display a popover from the right, use the same approach as above but with data-bs-placement=”right”.

Example: Implementation to showcase popover from left and right.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href=
    <title>Bootstrap Popover</title>
    <style>
        .background {
            background-size: cover;
            background-position: center;
            background: rgb(58, 207, 92);
            min-height: 100vh;
            padding: 50px;
        }
  
        .popover {
            background-color: rgba(27, 27, 27, 0.8);
            color: white;
        }
  
        .popover-header {
            color: green;
        }
  
        .popover-body {
            color: white;
        }
    </style>
</head>
  
<body>
    <div class="background">
        <div class="container mt-5">
            <!-- Left -->
            <h3 class="text-center text-light">
                Hover the button for popover from left
                <button type="button" class="btn btn-warning" 
                        data-bs-toggle="popover" data-bs-trigger="hover"
                        data-bs-placement="left" title="Left Popover"
                        data-bs-content="This is the content of the Left Popover.">
                    Hover me (Left)
                </button>
            </h3>
            <!-- Right -->
            <h3 class="text-center text-light">
                Hover the link for popover from right
                <a  href="#" class="btn btn-danger" 
                       data-bs-toggle="popover" data-bs-trigger="hover"
                    data-bs-placement="right" title="Right Popover"
                    data-bs-content="This is the content of the Right Popover.">
                    Hover me (Right)
                </a>
            </h3>
        </div>
    </div>
    <script src=
      </script>
    <script>
        let popoverTriggerList = [].slice.call(document.querySelectorAll(
          '[data-bs-toggle="popover"]'))
            
        let popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
            return new bootstrap.Popover(popoverTriggerEl)
        })
    </script>
</body>
  
</html>


Output:

aa



Similar Reads

How to make Bootstrap popover appear/disappear on hover instead of click?
Bootstrap provides in-built support for making popovers. A popover is a content box that appears when a user triggers a specific event with specified element selector. Here, we will discuss methods to trigger popover using "hover" instead of "click". Method 1: Here, we will specify popover trigger in 'hover' using jQuery initialization only. We can
2 min read
React Suite Popover &lt;Popover&gt; Props
React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. To display content specific to a certain topic only when the user performs a certain action Popover comes in handy. Popover Component allows the user to show the popup information that is triggered on some event
3 min read
Angular ng Bootstrap Popover Component
Angular ng bootstrap is a bootstrap framework used with angular to create components with great styling and this framework is very easy to use and is used to make responsive websites. In this article we will know how to use Popover in angular ng bootstrap. Popover is used to make a button that will be pop out by clicking on it. Installation syntax:
2 min read
Angular ngx Bootstrap Popover Component
Angular ngx bootstrap is a bootstrap framework used with angular to create components with great styling and this framework is very easy to use and is used to make responsive websites. In this article we will know how to use Popover in angular ngx bootstrap. Popover is used to make a button that will be pop out by clicking on it. Installation synta
2 min read
React-Bootstrap Popover Component
React-Bootstrap is a front-end framework that was designed keeping react in mind. Popover Component is a container-type element that hovers over the parent window. It is just like popup information that is trigger on some event over the parent window. We can use the following approach in ReactJS to use the react-bootstrap Popover Component. Popover
2 min read
ReactJS Blueprint Popover Component
BlueprintJS is a React-based UI toolkit for the web. This library is very optimized and popular for building interfaces that are complex data-dense for desktop applications. Popover Component provides a way for users to display floating content next to a target element. We can use the following approach in ReactJS to use the ReactJS Blueprint Popov
5 min read
ReactJS UI Ant Design Popover Component
Ant Design Library has this component pre-built, and it is very easy to integrate as well. Popover Component is used as a floating card that is popped by clicking or hovering over an element. We can use the following approach in ReactJS to use the Ant Design Popover Component. Popover Props: content: It is used to denote the content of the card.tit
2 min read
ReactJS Evergreen Popover Component
React Evergreen is a popular front-end library with a set of React components for building beautiful products as this library is flexible, sensible defaults, and User friendly. Popover Component allows the user to show floating content in relation to a target. We can use the following approach in ReactJS to use the Evergreen Popover Component. Popo
3 min read
React Suite Popover Component
React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. Popover Component allows the user to show the popup information that is trigger on some event over the parent window. We can use the following approach in ReactJS to use the React Suite Popover Component. Popove
4 min read
Onsen UI CSS Component Popover(right)
Popovers are used to notify the user about what notes a user should know before he proceeds further. It can also be used as a notification, like supposing the user has no idea what is going on in any particular section, then this popover can help or guide him/her. Onsen UI CSS Component offers us to create a self-designed popover. There are a lot o
3 min read