Using AOS (Animate On Scroll) in React with Tailwind CSS

Sandipan Kr Bag Apr 10, 2025
Using AOS (Animate On Scroll) in React with Tailwind CSS

If you want to add AOS (Animate On Scroll) animation to your component, here’s how you can do it step by step in a React + Tailwind CSS project:

✅ Step 1: Install AOS

npm install aos
 

✅ Step 2: Import and Initialize AOS

Add this in your main component (App.js, index.js, or where needed):

import AOS from 'aos';
import 'aos/dist/aos.css';
import { useEffect } from 'react';

useEffect(() => {
 AOS.init({
   duration: 1000, // animation duration in ms
   once: true      // animation occurs only once
 });
}, []);
 

✅ Step 3: Use AOS Attributes in JSX

Add data-aos attributes to any element:

<div 
 className='flex justify-start items-center mt-2 gap-2' 
 data-aos="fade-up"
>
 <span className='outfit text-[16px] md:text-[24px] font-medium text-[#4C9EC5] leading-none'>
   Agnesh Rathor
 </span>
 <div className='flex gap-1'>
   <Star className='text-[#ffcb0f] h-6 w-6' />
   <Star className='text-[#ffcb0f] h-6 w-6' />
   <Star className='text-[#ffcb0f] h-6 w-6' />
   <Star className='text-[#ffcb0f] h-6 w-6' />
   <Star className='text-[#ffcb0f] h-6 w-6' />
 </div>
</div>
 

🔥 Popular AOS Animation Types

TypeDescription
fade-upFades in and moves up
fade-downFades in and moves down
fade-leftFades in from left
fade-rightFades in from right
zoom-inZooms in
zoom-outZooms out
flip-leftFlip from left
flip-rightFlip from right
slide-upSlides up
slide-downSlides down

⚙️ Custom AOS Attributes

You can customize each animation with these optional attributes:

data-aos="fade-up"
data-aos-delay="200"         <!-- Delay in milliseconds -->
data-aos-duration="1500"     <!-- Duration of the animation -->
data-aos-offset="120"        <!-- Trigger offset -->
data-aos-easing="ease-in-out"
 

Share this article

sndp bag

Sandipan Kr Bag

I'm a dedicated full-stack developer, entrepreneur, and the proud owner of ocec.org.in , hailing from the vibrant country of India. My passion lies in creating informative tutorials and sharing valuable tips that empower fellow artisans in their journey. With a deep-rooted love for technology, I've been an ardent enthusiast of PHP, Laravel, Angular, Vue, Node, JavaScript, jQuery, Codeigniter, and Bootstrap from their earliest days. My philosophy revolves around the values of hard work and unwavering consistency, driving me to continuously explore, create, and share my knowledge with the tech community.

* Hire Me

0 Comments

Load more Comments

Post a Comment

Hint: Please enter between 80 - 300 characters.
ocec.org.in

helllo