Bootstrap Notification Bubble

What is a notification bubble?

Bubbles are built into the Notification system. They float on top of the website or the button to indicate pending notifications. Bubbles can be expanded to reveal the information inside the notification or can be collapsed/dismissed when not being used.

The section consists of two types of examples to demonstrate the notification bubbles.

Following is an example that shows the number of notifications. A number(in a smaller font) floats on the edge of the button to show the total pending notifications.

Example 1:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">  
    <title>Bootstrap Notification Bubble</title>
    <style>
body{
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #57606f;
    background-color: #f1f2f6;
}
.container {
  margin: 100px auto;
  text-align: center;
}
.notification-container {
  position: relative;
	display: inline-block;
  margin-top: 10px;
}
.notification-bubble {
    position: absolute;
    top: -8px;
    right: -7px;
    padding: 2px 5px 2px 6px;
    background-color: #3742fa;
    color: white;
    font-size: 0.60em;
    border-radius: 50%;
    box-shadow: 1px 1px 1px gray;
    display: none;
  }
.btn {
  background: #574b90;
  color: #f1f2f6;
  border: none;
  border-radius: 12px;
  opacity: 0.6;
}
.btn:hover {
  background-color: #8c7ae6;
  border: none;
}
.btn:focus {
  background-color: #8c7ae6;
  outline: none;
  box-shadow: none;


}
    </style>
</head>
<body>
    <div class="container">
        <h3>Following is an example to demonstrate the Bootstrap notification bubble.</h3><br>
        <p>Click on the button to generate the bubble</p><br>
        <div class="notification-container">
          <span class="notification-bubble">4</span>
          <button type="button" class="btn btn-notification">Check Notifications</button>
        </div>
      </div>  
</body>
<script>
    $(function() {
  $('.btn-notification').click(function() {
  	$('.notification-bubble').show(200);
	});
});
</script>
</html>

Output:

Initially, the website looks like this,

Bootstrap Notification Bubble

Following is an example that shows the list of notifications. It displays all the pending notifications, and the user can either view them or dismiss/collapse them.

Example 2:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">  
    <title>Bootstrap Notification Bubble</title>
    <style>
body{
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #57606f;
    background-color: #c8d6e5;
}
.row{
  margin:auto;
  padding: 30px;
  width: 80%;
  display: flex;
  flex-flow: column;
}
.card{
    width: 100%;
    margin-bottom: 5px;
    display: block;
    transition: opacity 0.3s;
  }
  a.btn{
          font-size: 0.8rem;
          padding: 3px;
        }
.card-body{
  padding: 0.5rem;
  border-radius: 50%;
}
tr{
      display:flex;
      
    }
table{
    width: 100%;
  }
.card-title:before{
  display:inline-block;
  font-family: 'Font Awesome\ 5 Free';
  font-weight:900;
  font-size: 1.1rem;
  text-align: center;
  border: 2px solid grey;
  border-radius: 100px;
  width: 30px;
  height: 30px;
  padding-bottom: 3px;
  margin-right: 10px;
}
.card-title:before {
      color: #90CAF9;
      border-color: #90CAF9;
      content: "\f007";
    }
.card-title:before {
      color: #FFE082;
      border-color: #FFE082;
      content: "\f071";
    }
.card-title:before {
      color: #FFAB91;
      border-color: #FFAB91;
      content: "\f00d";
    }
.card-title:before {
      color: #CE93D8;
      border-color: #CE93D8;
      content: "\f017";
    }
.card.display-none{
  display: none;
  transition: opacity 2s;
}
.btn{
    border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  border-radius: 10px;
}
.btn-reply{
    background-color: #2e86de;
}
.btn-danger{
    background-color: #1e3799;
}
.btn-reply:hover{
    background-color: #34B7F1;
}
.btn-danger:hover{
    background-color: #0c2461;
}
.btn-danger:focus{
    background-color: #0c2461;
}
    </style>
</head>
<body>
    <div class="container">
        <div class="row">
        <h3 class="text-center">Here are all the Notifications popped up!</h3>
        <p class="dismiss text-right"><a id="dismiss-all" href="#">Dimiss All</a></p>
        <div class="card notification-card notification-invitation">
          <div class="card-body">
            <table>
              <tr>
                <td style="width:70%"><div class="card-title"><b>Mom: </b>Get some eggs on your way back.</div></td>
                <td style="width:30%">
                  <a href="#" class="btn btn-reply">Reply</a>
                  <a href="#" class="btn btn-danger dismiss-notification">Dismiss</a>
                </td>
              </tr>
            </table>
          </div>
        </div>
        <div class="card notification-card notification-warning">
          <div class="card-body">
             <table>
              <tr>
                <td style="width:70%"><div class="card-title"><b>Sam: </b>Coming to the party?</div></td>
                <td style="width:30%">
                  <a href="#" class="btn btn-reply">Reply</a>
                  <a href="#" class="btn btn-danger dismiss-notification">Dismiss</a>
                </td>
              </tr>
            </table>
          </div>
        </div>
        <div class="card notification-card notification-danger">
          <div class="card-body">
             <table>
              <tr>
                <td style="width:70%"><div class="card-title"><b>Martha: </b>We have a meeting scheduled on Tuesday. Cool?</div></td>
                <td style="width:30%">
                  <a href="#" class="btn btn-reply">Reply</a>
                  <a href="#" class="btn btn-danger dismiss-notification">Dismiss</a>
                </td>
              </tr>
            </table>
          </div>
        </div>
        <div class="card notification-card notification-reminder">
          <div class="card-body">
             <table>
              <tr>
                <td style="width:70%"><div class="card-title"><b>Peter: </b>Hey bro, call me when you are free.</div></td>
                <td style="width:30%">
                  <a href="#" class="btn btn-reply">Reply</a>
                  <a href="#" class="btn btn-danger dismiss-notification">Dismiss</a>
                </td>
              </tr>
            </table>
          </div>
        </div>
      </div>
      </div>  
</body>
<script>
const dismissAll = document.getElementById('dismiss-all');
const dismissBtns = Array.from(document.querySelectorAll('.dismiss-notification'));
const notificationCards = document.querySelectorAll('.notification-card');
dismissBtns.forEach(btn => {
  btn.addEventListener('click', function(e){
    e.preventDefault;
    var parent = e.target.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
    parent.classList.add('display-none');
  })
});
dismissAll.addEventListener('click', function(e){
  e.preventDefault;
  notificationCards.forEach(card => {
    card.classList.add('display-none');
  });
  const row = document.querySelector('.notification-container');
  const message = document.createElement('h4');
  message.classList.add('text-center');
  message.innerHTML = 'Great! You are all caught up!';
  row.appendChild(message);
})
</script>
</html>

Output:

Bootstrap Notification Bubble

We can click on the “Dismiss” buttons to collapse the notification, as shown below

Bootstrap Notification Bubble

We can click on the “Dismiss All” button to dismiss all the notifications, as shown below

Bootstrap Notification Bubble

Related Topics

Bootstrap With CSS

← Prev Next → ...

1 minute read.

Bootstrap 4 Form

Bootstrap 4 Forms Bootstrap 4 provides forms, which are one of the essential components for web pages and web applications. It is an input-based component, used to collect user data with the help of...

8 minutes read.

Bootstrap Datepicker

What is a Bootstrap Datepicker? It is used to display a calendar with the date, month, and time from a dropdown menu. We will use an example to see how the date...

5 minutes read.

Bootstrap 4 Tooltip

Bootstrap 4 Tooltip Tooltip Bootstrap 4 offers a tooltip component, a small popup box that appears when you move the cursor over an element such as buttons or any highlighted element. It...

3 minutes read.

Bootstrap Buttons Groups

Bootstrap 4 Button Group Bootstrap 4 provides a feature button group that helps in creating a series of buttons together in a group. Basic Button Group  The .btn-group class is used within the <div> tag to create a...

6 minutes read.

Bootstrap Time Picker Example

What is a Bootstrap Time picker? It is used to display the time in hours, minutes and seconds from a dropdown menu. In this section, we will create an example to...

4 minutes read.

Environment Setup

How to use Bootstrap? We can use bootstrap in our project either by downloading or by providing link of the library files. 1) Download Bootstrap files To download files, visit official site of bootstrap www.getbootstrap.com/download/ and...

1 minute read.

Bootstrap 4 Pagination

Bootstrap 4 Pagination Bootstrap pagination is used to show the existence of a series of web pages of the website. It allows navigation on multiple pages of a website. In pagination, there is a block...

9 minutes read.

Bootstrap 4 Alerts

Bootstrap 4 Alerts Bootstrap 4 offers alerts that are used to provide feedback messages on the user’s actions. There is no boundation of text length in the alerts. Alerts can be created...

1 minute read.

Dropdown & Dropup

Bootstrap Dropdowns The bootstrap dropdown menu is used to create a toggleable menu. It provides users to choose one value from a predefined list. Before creating dropdown menu, we have to know...

3 minutes read.

Bootstrap 4 Collapse

Bootstrap 4 Collapse Collapse is a bootstrap component that is similar to the dropdown button. Collapse is used to hide or show the content such as paragraphs, sentences, etc.  When we click on a...

4 minutes read.

Bootstrap Badges and Labels

Bootstrap Badges Bootstrap Badges are numerical indicators. It is used to show that how many items are associated with a link.The .badge class is used to create of Bootstrap Badges. Let us see...

2 minutes read.

Bootstrap Notification Bubble

What is a notification bubble? Bubbles are built into the Notification system. They float on top of the website or the button to indicate pending notifications. Bubbles can be expanded to reveal...

5 minutes read.

Bootstrap Multiselect Dropdown

What is a multi-select Dropdown? Multi-select dropdown lists are used when we want to select multiple options for a particular record. Usually, dropdown lists provide the feature of choosing just one value...

4 minutes read.

Bootstrap 4 Popover

Bootstrap 4 Popover Popover A popover is similar to the tooltip. The only difference between tooltip and Popover is that in the tooltip, the popup box appears when you move the cursor...

6 minutes read.

Bootstrap 4 Media Objects

Bootstrap 4 Media Objects Bootstrap 4 offers a media object component that aligns the media objects and the content. The media object is used to create a repetitive and complex component...

7 minutes read.

Text Shadows in CSS

Text shadows are created with the text-shadow CSS property. It takes a list of shadows separated by commas to be applied to the text and any of its styles. Each...

5 minutes read.

Bootstrap Grid System Example

Bootstrap Grid System Example Stacked to horizontal – In stacked to the horizontal grid system, the grid columns are stacked on top of each other on extra small devices and becomes...

7 minutes read.

Bootstrap Contact Us page

What is a “Contact Us” page? A “Contact Us” page is a web page available on the websites of various companies, organisations etc., for its users to contact the organisation or...

5 minutes read.

Bootstrap 4 Content

Typography Typography is used for styling and formatting the content. It also helps in creating customized headings, sub-headings, lists, paragraphs, etc. Headings Bootstrap 4 offers HTML heading <h1> to <h6> that has bolder...

8 minutes read.