1

I'm trying to create a custom animation in Next.js with tailwindcss but not working, I'm following the docs but no luck

link: https://tailwindcss.com/docs/animation#customizing-your-theme

  • Next.js v15.1.4
  • Tailwindcss: v3.4.1

Component

note: the builtin tailwind animation working but the custom one doesn't

import '@/app/globals.css';

const SomeComponent: React.FC = () => {
  return (
    <>
      <p className={'animate-bounce'}> This is animated with builtin tailwind utility </p>
      <p className={'animate-wiggle'}> This should be animated </p>
    </>
  );
};

export default SomeComponent;

globals.css

@tailwind base;
@tailwind components;
@tailwind utilities;

@theme {
  --animate-wiggle: wiggle 1s ease-in-out infinite;
  @keyframes wiggle {
    0%,
    100% {
      transform: rotate(-3deg);
    }
    50% {
      transform: rotate(3deg);
    }
  }
}

The 'ugly' solution it to duct tape it with vanilla css but come on tailwind you can do it :)

0

1 Answer 1

2

You're trying to use v4 configuration syntax but you are using Tailwind v3. So, as per the v3 docs, you should apply the following in your tailwind.config.js file:

module.exports = {
  // …
  theme: {
    extend: {
      animation: {
        wiggle: 'wiggle 1s ease-in-out infinite',
      },
      keyframes: {
        wiggle: {
          '0%, 100%': { transform: 'rotate(-3deg)' },
          '50%': { transform: 'rotate(3deg)' },
        },
      },
    },
  },
};
Sign up to request clarification or add additional context in comments.

1 Comment

Or they can update the version they're using to v4: tailwindcss.com/docs/upgrade-guide

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.