tw-animate-css

1.2.8 • Public • Published

tw-animate-css

npm version npm downloads MIT license GitHub stars

A collection of Tailwind CSS v4.0 utilities for creating beautiful animations. Includes ready-to-use animations accordion-down, accordion-up and caret-blink, as well as a set of utilities for creating your own animations.


This package is a replacement for tailwindcss-animate. It embraces the new CSS-first architecture, providing a pure CSS solution for adding animation capabilities to your Tailwind CSS project without relying on the legacy JavaScript plugin system or having to define all keywords from scratch.

Table of Contents

Getting Started

NPM

  1. Install the package with npm:

    npm install -D tw-animate-css
  2. Add the following line to your app.css or globals.css file:

    @import "tw-animate-css";
  3. Start using the animations!

    <!-- Add an animated fade and zoom entrance -->
    <div class="animate-in fade-in zoom-in">...</div>
    
    <!-- Add an animated slide to top-left exit -->
    <div class="animate-out slide-out-to-top slide-out-to-left">...</div>
    
    <!-- Control animation duration -->
    <div class="... duration-300">...</div>
    
    <!-- Control animation delay -->
    <div class="... delay-150">...</div>
    
    <!-- And so much more! -->

ℹ️ NOTE
The above guide works for esbuild, Vite and probably other bundlers too. If you are using a different bundler, the syntax may differ. Let me know how it works and I'll update the documentation.

Manual Download

  1. Download the tw-animate.css file from GitHub and place it next to your app.css or globals.css file.

  2. Add the following line to your app.css or globals.css file:

    @import "./tw-animate.css";
  3. Start using the animations!

    <!-- Add an animated fade and zoom entrance -->
    <div class="animate-in fade-in zoom-in">...</div>
    
    <!-- Add an animated slide to top-left exit -->
    <div class="animate-out slide-out-to-top slide-out-to-left">...</div>
    
    <!-- Control animation duration -->
    <div class="... duration-300">...</div>
    
    <!-- Control animation delay -->
    <div class="... delay-150">...</div>
    
    <!-- And so much more! -->

Usage

Enter/Exit Animations

To keep the README concise, I'll define a few variables:

  • <io>: Specify the type of animation. This can be in for enter or out for exit animations.
  • <dir>: Specify the direction of the slide. This can be in-from-top, in-from-bottom, in-from-left, in-from-right, out-to-top, out-to-bottom, out-to-left or out-to-right.
  • *: Specify a value to apply. See list of possible values.

Base Classes

Class Description
animate-<io> Base class for enter/exit animations. This needs to be applied in order for enter/exit animations to work.

Parameter Classes

To customize the animation parameters, use the following classes:

Class Description
duration-* Sets animation-duration. Uses --tw-duration, see Tailwind CSS docs. Defaults to duration-150.
ease-* Sets animation-timing-function. Uses --tw-ease, see Tailwind CSS docs. Defaults to ease-[ease].
delay-* Sets animation-delay. Possible values: Any <number>, initial, or any other [<value>].
repeat-* Sets animation-iteration-count. Possible values: Any <number>, infinite, initial or any other [<value>].
direction-* Sets animation-direction. Possible values: normal, reverse, alternate, alternate-reverse, initial or any other [<value>].
fill-mode-* Sets animation-fill-mode. Possible values: none, forwards, backwards, both, initial or any other [<value>].
running Sets animation-play-state to running.
paused Sets animation-play-state to paused.
play-state-* Sets animation-play-state. Possible values: initial or any other [<value>].

Transform Classes

Class Description
fade-<io> Fades the element in from or out to opacity: 0.
fade-<io>-* Fades the element in from or out to the specified value. Possible values: Any <number> (percentage) or any other [<value>].
zoom-<io> Zooms the element in from or out to scale3D(0,0,0).
zoom-<io>-* Zooms the element in from or out to the specified value. Possible values: Any <number> (percentage) or any other [<value>].
spin-<io> Spins the element in from or out to rotate(30deg).
spin-<io>-* Spins the element in from or out to the specified value. Possible values: Any <number> (degrees) or any other [<value>].
slide-<dir> Slides the element in from or out to the specified direction (100%).
slide-<dir>-* Slides the element in from or out to the specified value. Possible values: Any <number> (percentage) or any other [<value>].

Ready-to-Use Animations

Class Description
accordion-down Accordion down animation. Requires --radix-accordion-content-height or --bits-accordion-content-height to be set to the content's height.
accordion-up Accordion up animation. Requires --radix-accordion-content-height or --bits-accordion-content-height to be set to the content's height.
collapsible-down Collapsible down animation. Requires --radix-collapsible-content-height or --bits-collapsible-content-height to be set to the content's height.
collapsible-up Collapsible up animation. Requires --radix-collapsible-content-height or --bits-collapsible-content-height to be set to the content's height.
caret-blink Blinking animation for caret/cursor.

Examples

Basic usage:

<div class="animate-in fade-in slide-in-from-top-8 duration-500">
  Fade in from 0% opacity,<br />
  slide from top by 8 spacing units (2rem),<br />
  with a 500ms duration.
</div>

Advanced usage:

<div
  class="data-[state=show]:animate-in data-[state=hide]:animate-out fade-in slide-in-from-top-8 fade-out slide-out-to-top-8 duration-500"
  data-state="show"
>
  <p>
    If the element has the <code>data-state="show"</code> attribute,<br />
    fade in from 0% opacity,<br />
    slide from top by 8 spacing units (2rem),<br />
    with a 500ms duration.
  </p>
  <p>
    If the element has the <code>data-state="hide"</code> attribute,<br />
    fade out to 0% opacity,<br />
    slide to top by 8 spacing units (2rem),<br />
    with a 500ms duration.
  </p>
</div>

Notes on Compatibility

ℹ️ NOTE
I use only a small portion of the original plugin, so it might not be a 100% compatible drop-in replacement. If you notice any inconsistencies, feel free to contribute to this repository by opening a pull-request.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.2.8
188,098latest
1.3.0-canary.16
47canary

Version History

VersionDownloads (Last 7 Days)Published
1.2.8
188,098
1.3.0-canary.16
47
1.3.0-canary.15
57
1.3.0-canary.14
37
1.3.0-canary.13
28
1.2.7
30,271
1.3.0-canary.12
20
1.3.0-canary.11
18
1.3.0-canary.10
18
1.2.6
2,641
1.3.0-canary.9
20
1.3.0-canary.8
18
1.3.0-canary.7
15
1.2.5
342,308
1.3.0-canary.6
1
1.3.0-canary.5
1
1.3.0-canary.4
0
1.3.0-canary.3
0
1.3.0-canary.2
0
1.3.0-canary.1
0
1.3.0-canary.0
2
1.2.4
38,310
1.2.3
17
1.2.2
197
1.2.14
1.2.0220

Package Sidebar

Install

npm i tw-animate-css

Weekly Downloads

517,912

Version

1.2.8

License

MIT

Unpacked Size

35.3 kB

Total Files

5

Last publish

Collaborators

  • wombosvideo