Introducing Magic UI Pro - 50+ blocks and templates to build beautiful landing pages in minutes.


Docs
Word Fade In

Word Fade In

Text animation which fades in word by word

Word Fade In

Installation

Copy and paste the following code into your project.

components/magicui/word-fade-in.tsx
"use client";
 
import { cn } from "@/lib/utils";
import { Variants, motion } from "framer-motion";
 
interface WordFadeInProps {
  words: string;
  className?: string;
  delay?: number;
  variants?: Variants;
}
 
export default function WordFadeIn({
  words,
  delay = 0.15,
  variants = {
    hidden: { opacity: 0 },
    visible: (i: any) => ({
      y: 0,
      opacity: 1,
      transition: { delay: i * delay },
    }),
  },
  className,
}: WordFadeInProps) {
  const _words = words.split(" ");
 
  return (
    <motion.h1
      variants={variants}
      initial="hidden"
      animate="visible"
      className={cn(
        "font-display text-center text-4xl font-bold tracking-[-0.02em] text-black drop-shadow-sm dark:text-white md:text-7xl md:leading-[5rem]",
        className,
      )}
    >
      {_words.map((word, i) => (
        <motion.span key={word} variants={variants} custom={i}>
          {word}{" "}
        </motion.span>
      ))}
    </motion.h1>
  );
}

Props

PropTypeDescriptionDefault
classNamestringThe class name to be applied to the component
delaynumberThe Delay between each word animation0.15
wordsstringA Text that is animated word by word"word fade in"
variantsVariantsAn object containing framer-motion animation props