How to Add Animation Duration, Delay and Easing Support to Tailwind CSS (v3)
Published: / Updated:
Itโs important to mention that you can use JIT for one-off classes, such as:
[animation-duration:_2s][animation-delay:_0.5s][animation-timing-function:_linear]
It may seem strange that Tailwind CSS doesnโt include this, but letโs proceed.
Adding Animation Duration Classes to Tailwind CSS
To do this, add the following to your tailwind.config.js:
const plugin = require('tailwindcss/plugin')
module.exports = {
plugins: [
plugin(function ({ matchUtilities, theme }) {
matchUtilities(
{
'animate-duration': (value) => ({
animationDuration: value,
}),
},
{ values: theme('transitionDuration') }
)
}),
],
}
This will add the duration classes used for transitions to animations with the
animate- prefix:
animate-duration-0animate-duration-75animate-duration-100animate-duration-150animate-duration-200animate-duration-300animate-duration-500animate-duration-700animate-duration-1000
Adding Animation Delay Classes to Tailwind CSS
Add the following to your tailwind.config.js:
const plugin = require('tailwindcss/plugin')
module.exports = {
plugins: [
plugin(function ({ matchUtilities, theme }) {
matchUtilities(
{
'animate-delay': (value) => ({
animationDelay: value,
}),
},
{ values: theme('transitionDelay') }
)
}),
],
}
This will add the delay classes used for transitions to animations with the
animate- prefix:
animate-delay-0animate-delay-75animate-delay-100animate-delay-150animate-delay-200animate-delay-300animate-delay-500animate-delay-700animate-delay-1000
Adding Animation Easing Classes to Tailwind CSS
Add the following to your tailwind.config.js:
const plugin = require('tailwindcss/plugin')
module.exports = {
plugins: [
plugin(function ({ matchUtilities, theme }) {
matchUtilities(
{
'animate-ease': (value) => ({
animationTimingFunction: value,
}),
},
{ values: theme('transitionTimingFunction') }
)
}),
],
}
This will add the ease classes used for transitions to animations with the
animate- prefix:
animate-easeanimate-ease-linearanimate-ease-inanimate-ease-outanimate-ease-in-out
Check out the Tailwind Play example.
The added classes will appear in Tailwind CSS IntelliSense.
This also means you can use JIT, for example:
animate-duration-[5s]animate-delay-[0.25s]animate-ease-[cubic-bezier(.17,_.67,_.83,_.67)]
And thatโs it.
Thatโs all you need to do to add animation duration, delay, and easing support to Tailwind CSS while itโs not yet part of the core. Perhaps it will be included in the future.