webdevpuneet.com

Bootstrap Notification Center Dropdown — Free Snippet

Bootstrap Notification Center Dropdown · Navigation · Plain HTML, CSS & JS · Live preview

CategoryNavigation

Copy & paste

Source Code

<div class="container py-5 text-center">
  <div class="dropdown">
    <button class="btn btn-light position-relative" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false">
      <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"/><path d="M13.73 21a2 2 0 0 1-3.46 0"/></svg>
      <span class="badge rounded-pill bg-danger position-absolute top-0 start-100 translate-middle" id="bsnotifBadge">3</span>
    </button>
    <div class="dropdown-menu dropdown-menu-end bsnotif-panel p-0">
      <div class="d-flex justify-content-between align-items-center px-3 py-2 border-bottom">
        <strong class="small">Notifications</strong>
        <button class="btn btn-link btn-sm p-0" id="bsnotifReadAll">Mark all read</button>
      </div>
      <div id="bsnotifList">
        <a href="javascript:void(0)" class="dropdown-item bsnotif-item bsnotif-unread py-2">
          <div class="d-flex gap-2"><span class="bsnotif-dot"></span><div><div class="small">Sara commented on your PR</div><div class="text-muted" style="font-size:11px">2m ago</div></div></div>
        </a>
        <a href="javascript:void(0)" class="dropdown-item bsnotif-item bsnotif-unread py-2">
          <div class="d-flex gap-2"><span class="bsnotif-dot"></span><div><div class="small">Deploy to production succeeded</div><div class="text-muted" style="font-size:11px">1h ago</div></div></div>
        </a>
        <a href="javascript:void(0)" class="dropdown-item bsnotif-item bsnotif-unread py-2">
          <div class="d-flex gap-2"><span class="bsnotif-dot"></span><div><div class="small">Weekly report is ready</div><div class="text-muted" style="font-size:11px">3h ago</div></div></div>
        </a>
      </div>
    </div>
  </div>
</div>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Real Bootstrap 5.3 Dropdown component, loaded from the actual CDN
Unread badge count is derived live from the DOM, not a hardcoded or separately tracked number
Badge hides itself entirely once the unread count reaches zero
Clicking one notification marks only that one read, without closing the dropdown
"Mark all read" clears every unread notification in a single action
Unread notifications get a distinct background tint and dot indicator

About this UI Snippet

Bootstrap Notification Center Dropdown — HTML, CSS & JavaScript

Screenshot of the Bootstrap Notification Center Dropdown snippet rendered live

The badge count on this bell icon isn't a static "3" — it's derived live from how many .bsnotif-item elements currently carry the .bsnotif-unread class, recalculated by updateBadge() after every change and hidden entirely once it reaches zero, all inside real Bootstrap 5.3's Dropdown component.

Keeping the menu open past the first click

Bootstrap's Dropdown closes on any click by default — autoClose: true closes it both on an outside click *and* on a click anywhere inside the menu, including a notification item. Left as the default, marking one notification read would immediately dismiss the whole panel, making it impossible to read a second one without reopening it. The trigger button's data-bs-auto-close="outside" attribute changes that to Bootstrap's other documented mode: the menu now closes only on a genuine outside click, so clicking through several notifications in one open dropdown works as expected. A separate "Mark all read" control clears every unread notification in one action for the case where reading each individually isn't worth the effort.

Step by step

How to Use

  1. 1
    Load the snippetClick the snippet in the sidebar Library tab. The preview loads a bell icon with a red "3" badge.
  2. 2
    Open the dropdownClick the bell — Bootstrap's real Dropdown component opens showing three unread (tinted) notifications.
  3. 3
    Click one notificationIt loses its unread tint and dot, the badge updates to "2", and the dropdown stays open.
  4. 4
    Click "Mark all read"Every remaining notification clears at once and the badge disappears entirely.

Real-world uses

Common Use Cases

App and dashboard notification centers
The standard bell-icon-with-badge pattern for surfacing recent activity without a dedicated notifications page.
Learning derived-state badge counts
A clean example of computing a count from the current DOM state rather than incrementing/decrementing a separately tracked variable.
Admin panels and SaaS product headers
Pair with the Bootstrap Admin Dashboard snippet's top bar for a complete notification experience.
Any read/unread list pattern
The mark-one vs. mark-all pattern generalizes to inboxes, task lists, or any other read-state-tracked list.

Got questions?

Frequently Asked Questions

Yes — it uses Bootstrap 5.3's actual Dropdown component via data-bs-toggle="dropdown", loaded from the genuine CDN, for the open/close and outside-click behavior.

updateBadge() re-counts how many elements currently carry the .bsnotif-unread class every time a notification is read (individually or via "mark all"), so the number always reflects the real current state rather than a separately maintained counter.

The trigger button carries data-bs-auto-close="outside", one of Bootstrap's built-in Dropdown options. Left at the default (autoClose: true), Bootstrap closes the menu on any click inside it too, which would dismiss the whole panel after marking just the first notification read — "outside" mode closes it only on a genuine click outside the menu instead.

The badge hides itself entirely (display: none) once the unread count reaches zero, rather than showing a "0" badge, which would be visual noise.

Yes — insert a new .dropdown-item.bsnotif-item.bsnotif-unread element into #bsnotifList and call updateBadge() afterward; both the click-to-read and mark-all-read handlers pick it up automatically since they query by class, not by a fixed list.

Yes. While the Bootstrap Notification Center Dropdown snippet gives you one pattern to copy, the free Responsive Navbar Builder at webdevpuneet.com/navbar-builder/ designs a whole navigation bar: logo, links and dropdown menus, a mobile hamburger menu (dropdown panel, slide-in drawer or full screen) and a scroll effect (sticky, shrink, hide on scroll or transparent). It has six presets, a live preview that runs the real code, and exports HTML + CSS + vanilla JS, React, Tailwind, Vue 3 or Angular — or you can click Fork & Edit to keep editing it in My Code.