Lottie Notification Bell Nav — Free HTML CSS JS Snippet

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

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.

Build with AI

Build, Understand, Optimize, and Extend It With AI

Hand this snippet's HTML, CSS, and JavaScript to an AI coding assistant like Claude and ask it to adapt "Lottie Notification Bell Nav" to your project — restyle it to match your design system, wire it up to real data instead of the static example, or port it to the framework you're building in.

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 navigation component called "Lottie Notification Bell Nav" using plain HTML, CSS, and vanilla JavaScript — no framework, no build step.

Requirements:
- Match the structure and behavior of the "Lottie Notification Bell Nav" snippet from the UI Snippets Library.
- Keep the markup semantic and the styling self-contained (no external dependencies beyond what the original snippet uses).
- Keep the JavaScript vanilla, with no framework runtime required.
- Make it easy to restyle via CSS custom properties or class overrides so it can be dropped into a real project.

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.

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>

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 nav bars
Alert users to new activity with an animated bell instead of a silent badge.
Real-time apps with live events
Trigger playRingAnimation() from your actual WebSocket message handler.
Notification center entry points
Use the bell as the trigger for a dropdown or panel listing recent alerts.
lottie-web integration example
Demonstrates triggering a one-shot Lottie animation in response to app events.

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.