webdevpuneet.com

Bootstrap Notification Center Dropdown — Free Snippet

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

CategoryNavigation

About this UI Snippet

Bootstrap Notification Center Dropdown — HTML, CSS & JavaScript

Screenshot of the Bootstrap Notification Center Dropdown snippet rendered live

This is a complete notification center built on real Bootstrap 5.3's Dropdown component: a bell button with a red badge, and a 360px panel with coloured icon tiles, a headline, a short preview line and a timestamp for every notification, All / Unread tabs, a "Mark all read" link and a "View all notifications" footer.

Everything is derived from the DOM

The badge, the counter on the Unread tab and the empty state are never tracked in a separate variable. render() re-counts the .bsnotif-unread items after every click, so the numbers cannot drift out of sync. When the Unread tab is selected and nothing is left, a friendly "You're all caught up" state replaces the list instead of leaving a blank box.

Keeping the menu open past the first click

Bootstrap's Dropdown closes on any click by default, including a click on an item inside it. The bell's data-bs-auto-close="outside" attribute switches to Bootstrap's other documented mode, so the menu closes only on a genuine outside click and a visitor can read several notifications in one go. The bell also rings once on load, respecting prefers-reduced-motion.

What's included

Features

Real Bootstrap 5.3 Dropdown component, loaded from the actual CDN
Coloured icon tiles, bold names, preview text and timestamps on every notification
All / Unread tabs with a live unread counter
Badge count, tab counter and empty state all derived from the DOM, never a separate counter
Clicking one notification marks only that one read, without closing the dropdown
"Mark all read" action and a "View all notifications" footer link
"You're all caught up" empty state, scrollable list, and a bell animation that honours reduced motion

Step by step

How to Use

  1. 1
    Load the snippetClick the snippet in the sidebar Library tab. The bell rings once and the panel opens with a red "3" badge.
  2. 2
    Click a notificationIt loses its tint and dot, the badge and the Unread tab count drop to "2", and the dropdown stays open.
  3. 3
    Switch to the Unread tabAlready-read items are hidden so only what still needs attention is listed.
  4. 4
    Click "Mark all read"Every notification clears, the badge disappears, and the Unread tab shows the "You're all caught up" state.

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 UI
A clean example of computing a badge, a tab counter and an empty state from the current DOM instead of tracking separate counters.
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 with an Unread filter generalizes to inboxes, task lists, or any 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.

render() re-counts the elements carrying the .bsnotif-unread class after every click, tab switch or "mark all", and updates the badge, the Unread tab counter and the empty state from that one number.

The bell carries data-bs-auto-close="outside". With Bootstrap's default (autoClose: true) the menu would close on any click inside it, dismissing the panel after the very first notification you read.

The tabs only toggle a bsnotif-only-unread class on the panel. CSS then hides every item that lacks .bsnotif-unread, so no items are removed or re-rendered.

Yes — insert a new .dropdown-item.bsnotif-item.bsnotif-unread element into #bsnotifList and call render(); the click handler is delegated on the list, so new items work automatically.

Only in this demo, so the design is visible straight away. Delete the window load listener at the bottom of the JS to keep it closed until clicked.

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.

Copy & paste

Source Code

<div class="container-fluid py-5 d-flex justify-content-center bsnotif-stage">
  <div class="dropdown">
    <button class="btn bsnotif-bell position-relative" id="bsnotifBell" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false" aria-label="Notifications">
      <svg width="20" height="20" 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" id="bsnotifPanel">
      <div class="bsnotif-head">
        <div class="d-flex justify-content-between align-items-center">
          <strong>Notifications</strong>
          <button class="btn btn-link btn-sm p-0 text-decoration-none" id="bsnotifReadAll">Mark all read</button>
        </div>
        <div class="bsnotif-tabs" role="tablist">
          <button class="bsnotif-tab active" data-filter="all" role="tab" aria-selected="true">All</button>
          <button class="bsnotif-tab" data-filter="unread" role="tab" aria-selected="false">Unread <span id="bsnotifTabCount">3</span></button>
        </div>
      </div>
      <div id="bsnotifList">
        <a href="javascript:void(0)" class="dropdown-item bsnotif-item bsnotif-unread">
          <span class="bsnotif-ico bsnotif-blue"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg></span>
          <span class="bsnotif-body"><span class="bsnotif-title"><b>Sara Lopez</b> commented on your pull request</span><span class="bsnotif-sub">"Looks great, just one small naming nit on line 42."</span><span class="bsnotif-time">2 min ago</span></span>
          <span class="bsnotif-dot" aria-hidden="true"></span>
        </a>
        <a href="javascript:void(0)" class="dropdown-item bsnotif-item bsnotif-unread">
          <span class="bsnotif-ico bsnotif-green"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><path d="M22 4 12 14.01l-3-3"/></svg></span>
          <span class="bsnotif-body"><span class="bsnotif-title">Deploy to <b>production</b> succeeded</span><span class="bsnotif-sub">Build #482 finished in 1m 12s.</span><span class="bsnotif-time">1 hour ago</span></span>
          <span class="bsnotif-dot" aria-hidden="true"></span>
        </a>
        <a href="javascript:void(0)" class="dropdown-item bsnotif-item bsnotif-unread">
          <span class="bsnotif-ico bsnotif-amber"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 3v18h18"/><path d="M7 15l4-4 3 3 5-6"/></svg></span>
          <span class="bsnotif-body"><span class="bsnotif-title">Your weekly report is ready</span><span class="bsnotif-sub">Traffic is up 12% compared with last week.</span><span class="bsnotif-time">3 hours ago</span></span>
          <span class="bsnotif-dot" aria-hidden="true"></span>
        </a>
        <a href="javascript:void(0)" class="dropdown-item bsnotif-item">
          <span class="bsnotif-ico bsnotif-violet"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg></span>
          <span class="bsnotif-body"><span class="bsnotif-title"><b>Dev Patel</b> joined your workspace</span><span class="bsnotif-sub">Invited by you yesterday.</span><span class="bsnotif-time">Yesterday</span></span>
          <span class="bsnotif-dot" aria-hidden="true"></span>
        </a>
        <a href="javascript:void(0)" class="dropdown-item bsnotif-item">
          <span class="bsnotif-ico bsnotif-rose"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg></span>
          <span class="bsnotif-body"><span class="bsnotif-title">Payment method expires soon</span><span class="bsnotif-sub">Update your card ending 4242 before 30 Nov.</span><span class="bsnotif-time">2 days ago</span></span>
          <span class="bsnotif-dot" aria-hidden="true"></span>
        </a>
      </div>
      <div class="bsnotif-empty" id="bsnotifEmpty" hidden>
        <div class="bsnotif-empty-ico"><svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><path d="M22 4 12 14.01l-3-3"/></svg></div>
        <strong>You're all caught up</strong>
        <span>No unread notifications right now.</span>
      </div>
      <a href="javascript:void(0)" class="bsnotif-foot">View all notifications</a>
    </div>
  </div>
</div>

Extend with AI

Take This Snippet Further With AI

Hand this snippet's HTML, CSS, and JS to an AI coding assistant like Claude and ask it to add real-time notifications via a WebSocket or polling connection that prepend new unread items, to add a per-item dismiss button, or to group notifications under Today / Earlier headings. It's also a good exercise to ask the assistant to persist read state to localStorage so it survives a page reload.

Prompt to recreate it

Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:

text
Build a Bootstrap 5.3 notification center dropdown, using the real Bootstrap CDN framework (bootstrap.min.css and bootstrap.bundle.min.js), not custom CSS made to resemble Bootstrap.

Requirements:
- A round bell button with a red unread-count badge, using Bootstrap's real Dropdown component (data-bs-toggle="dropdown" with data-bs-auto-close="outside") to reveal a rounded, shadowed panel about 360px wide.
- Panel header with the title "Notifications", a "Mark all read" link, and All / Unread tabs where the Unread tab shows a live count.
- At least five notifications, each with a coloured icon tile, a headline with bold names, a one-line preview and a relative timestamp. Unread ones have a tinted background and a dot; read ones are muted.
- Clicking a notification marks only that one as read without closing the dropdown. The Unread tab hides read items.
- Badge, tab counter and empty state must be recalculated from the DOM on every change (no separate counter); the badge hides at zero, and the Unread tab shows a "You're all caught up" empty state when nothing is left.
- A "View all notifications" footer link, a scrollable list, and a one-time bell ring animation on load that respects prefers-reduced-motion.

Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.