An animated theme toggle component built using Next.js, Tailwind CSS, Framer Motion, and Lucide Icons. This component uses local storage to remember the user’s theme preference and provides a smooth animation transition between light and dark modes.
• Animated Transitions: Smooth transitions between light and dark themes using Framer Motion.
• Persistent Theme: Theme preference is saved using local storage, ensuring the user’s preference is remembered across sessions.
• Responsive Design: Fully responsive and works across all devices, thanks to Tailwind CSS.
• Customizable: Easy to customize to fit the design needs of any project.
• Accessible: Designed with accessibility in mind, ensuring it is usable by everyone.
https://github.com/user-attachments/assets/db5a32a9-f8e3-4d41-a72e-65cffdfe4658
Prerequisites: Ensure you have the following installed:
• Node.js (version 12 or later)
• Next.js project setup
Step 1: Install Dependencies
Run the following command to install the required dependencies:
npm install framer-motion lucide-react tailwindcss
Step 2: Configure Tailwind CSS
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
module.exports = { darkMode: 'class', // Enable class-based dark mode content: [ './pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}', ], theme: { extend: {}, }, plugins: [], }
@tailwind base;
@tailwind components;
@tailwind utilities;
Step 3: Using the Theme Toggle Component
import DarkToggle from './components/DarkToggle';
export default function MyApp() { return (