Back to KB
Difficulty
Intermediate
Read Time
3 min

Using Lottie Animations in Next.js (App Router & Pages Router)

By Codcompass TeamΒ·Β·3 min read

Adding Lottie to Next.js has one key gotcha: lottie-web and lottie-react are client-only libraries that access the DOM, so you need to handle SSR carefully. Here's how.

Step 1: Get Your Animation File

Download a free .json Lottie file from IconKing β€” preview and download with no signup. Save it to public/animations/ in your Next.js project so it's served as a static asset.

Step 2: Install lottie-react

npm install lottie-react

Enter fullscreen mode Exit fullscreen mode

Step 3: Create a Client Component (App Router)

In Next.js App Router, any component using browser APIs must be a Client Component. Create components/LottieAnimation.tsx:

"use client";

imp

πŸŽ‰ Mid-Year Sale β€” Unlock Full Article

Base plan from just $4.99/mo or $49/yr

Sign in to read the full article and unlock all 635+ tutorials.

Sign In / Register β€” Start Free Trial

7-day free trial Β· Cancel anytime Β· 30-day money-back