webdevpuneet.com

Lottie Notification Bell Nav — Free HTML CSS JS Snippet

Lottie Notification Bell Nav · Navigation · Plain HTML, CSS & JS · Live preview

CategoryNavigation

Copy & paste

Source Code

Requires
<nav class="lnb-nav">
  <span class="lnb-brand">Acme</span>
  <div class="lnb-actions">
    <button class="lnb-bell-btn" id="lnbBellBtn" type="button" aria-label="Notifications">
      <svg id="lnbBellIcon" 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-12 0c0 7-3 9-3 9h18s-3-2-3-9" />
        <path d="M13.73 21a2 2 0 0 1-3.46 0" />
      </svg>
      <span class="lnb-lottie-ring" id="lnbLottieRing"></span>
      <span class="lnb-badge" id="lnbBadge" hidden>0</span>
    </button>
  </div>
</nav>
<div class="lnb-log" id="lnbLog">Waiting for new notifications…</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

Loads the real lottie-web library from a CDN via cdnUrls
Inline animationData JSON object — no external .json file fetched
Simulated new notification via setTimeout, incrementing a live badge counter
Lottie ring animation layered behind the bell icon on each new notification
CSS keyframe shake retriggered by forcing a reflow on the icon element
Previous Lottie instance destroyed before each new trigger to avoid leaks
Badge hidden until the first notification arrives
Self-contained — no image or font assets required

About this UI Snippet

Lottie Notification Bell Nav — Animated Bell With Live Badge Counter

Screenshot of the Lottie Notification Bell Nav snippet rendered live

This snippet builds a notification bell for a navigation bar that reacts to new notifications with both a CSS shake and a real Lottie ring animation from the lottie-web library, instead of a silent badge number change.

Simulating a new notification

A setTimeout fires receiveNotification() about two seconds after the page loads, standing in for a real push event from a WebSocket or polling call. Each call increments notificationCount, updates the badge text, and reveals it if it was hidden.

The ring animation

playRingAnimation() calls lottie.loadAnimation({ container, renderer: 'svg', loop: false, autoplay: true, animationData }) against an inline animation JSON object, layering a brief non-looping burst behind the bell icon, while a CSS keyframe shake is retriggered on the icon itself by removing and re-adding its animation class (forcing a reflow with offsetWidth so the animation restarts).

Cleanup between triggers

Each call destroys any previous Lottie instance before creating a new one and removes the ring container from view after the animation finishes, so repeated notifications never stack multiple running Lottie players.

Step by step

How to Use

  1. 1
    Load the snippetClick "Lottie Notification Bell Nav" in the sidebar to load its HTML, CSS, and JS into the editor panels. The preview updates instantly.
  2. 2
    Edit the codeModify any panel — HTML, CSS, or JS. The preview refreshes as you type. Use Reset in each panel header to restore the original.
  3. 3
    Preview on devicesClick the Mobile (375px), Tablet (768px), or Desktop buttons in the preview header to check responsiveness.
  4. 4
    Export in your formatClick "HTML" to download a standalone file, "JSX" for a React component, "Tailwind" for a React + Tailwind CSS component, "Tailwind HTML" for a standalone HTML file with Tailwind CDN, "Vue" for a Vue 3 SFC with <template>/<script setup>/<style scoped>, or "Angular" for a standalone Angular .component.ts file. "Copy all" copies the full code to clipboard.
  5. 5
    Save your versionClick "Save as", type a name, and press Enter. Your snippet saves to IndexedDB and appears in the Saved tab.

Real-world uses

Common Use Cases

🔔
Dashboard and SaaS navigation
Alert users to new activity with a bell that plays a Lottie ring animation and also shakes, rather than silently changing a badge number.
⚡
Real-time event apps
Trigger the ring when a live event arrives, with a simulated setTimeout notification incrementing the counter in the demo.
📥
Notification centre entry points
Use the bell as the trigger for a panel of notifications, with the Lottie layer positioned behind the icon.
🎓
lottie-web integration reference
See how to load the library from a CDN and use inline animationData so no external JSON file is fetched.

Got questions?

Frequently Asked Questions

Simulated — a setTimeout fires it once, two seconds after load, standing in for a real event from a WebSocket, server-sent event, or polling call in a production app.

The ring is meant to play once as a brief burst reacting to a specific event, not loop continuously like a background decorative animation, so it is destroyed shortly after it finishes.

The class is removed, the element's offsetWidth is read to force a synchronous reflow, and the class is re-added — without that reflow, browsers would not restart an already-applied CSS animation.

Yes. While the Lottie Notification Bell Nav 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.