AnimText is a JavaScript library for letter, word, & line animations. Easily create dynamic text effects with simple HTML data attributes.
npm install animtext tag.
bash
npm i animtext
`
Then import and initialize AnimText in your JS:
`js
import animtext from "animtext";
`
$3
Just include the script before the closing tag:
`
html
`
DOMContentLoaded
AnimText will automatically run on — no manual init needed in most cases.
`
Animation Classes Powered by {css}animation
AnimText is designed to work hand-in-hand with the animation classes from {css}animation. These CSS classes are required to make the AnimText actually animate elements, so be sure to include them in your project.
Install the animation library:
bash
`
npm install @hellouxpavel/cssanimation
`
Then import it in your JavaScript:
js
`
import "@hellouxpavel/cssanimation";
`
Or include it via CDN:
html
`
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@hellouxpavel/cssanimation@latest/dist/cssanimation.min.css" />
`
Without the cssanimation classes, AnimText can still spilt the text, but no animation will play.
Getting Started
To start using AnimText, all you need is a simple HTML element with the right attributes.
html
`Hello AnimText!
class="cssanimation"
What’s Happening Here
-
data-at-sequence="ca__fx-fadeIn"
This class is required. It activates the AnimText and ensures the element is styled correctly.
It also enables animation styles from the {css}animation library.
-
ca__fx-fadeIn
This tells AnimText to animate the text letter by letter, using the animation class.
ca__fx-fadeIn
Letters will appear one after another in sequence.
You can replace with any animation class from the {css}animation library. For the animation class check this demo and copy simply.
data-at-*
Once this setup is in place, AnimText handles the rest!
Supported Attributes
Below is a quick reference table for all the attributes you can use with AnimText:
data-at-sequence
| Attribute | Description |
| ----------------------- | -------------------------------------------------------------------------------------------- |
| | Animates letter-by-letter, in order from first to last. |
data-at-random
| | Animates letters in a randomized order. |
data-at-reverse
| | Animates letters in reverse order (last letter animates first). |
data-at-word
| | Animates word-by-word, one word at a time. |
data-at-line
| | Animates line-by-line, based on or \n or custom separators. |
data-at-delay
| | Sets delay (in ms) before each unit starts animating. Accepts one or multiple values. |
data-at-base-duration
| | Sets a default animation duration (in ms) for each unit. Overrides CSS or internal defaults. |
data-at-separator
| | Optional. Use "dot" to split lines on periods (.). Default is or line breaks. |
`
---
$3
html
`
class="cssanimation"
data-at-word="ca__fx-fadeIn ca__fx-fadeInLeft ca__fx-slinkyDrop ca__fx-jiggleTransform"
data-at-delay="200 300 400"
data-at-base-duration="1000">
Animate each word smoothly
200ms
In this example:
- Each word gets its own animation class (cycled or repeated).
- Words animate with delays of , 300ms, then 400ms (last delay repeats if more words).
1000ms
- Each word’s animation lasts , regardless of what's in your CSS.
data-at-sequence
This lets you easily create custom animation flows without writing JavaScript.
Letter-by-Letter Animation
You can animate text letter by letter using different animation orders.
Just add one of these attributes to your element:
$3
Use to animate each letter one after another in order.
`
html
`Letters Animate
data-at-random
$3
Use to animate the letters in a shuffled, randomized order.
`
html
`
Randomized entry!
data-at-reverse
$3
Use to animate the last letter first, moving backward to the start.
`
html
`
Backwards Flow
ca__fx-fadeIn
đź’ˇ You can customize the animation effect by replacing the class (e.g. ) with any animation class from {css}animation}.
data-at-word
Word-by-Word Animation
To animate each word in your text individually, use the attribute:
`
html
`
Each word animates uniquely
ca__fx-fadeIn
In this example, all the words will animate one by one using the animation class.
ca__fx-fadeIn
In this example:
- Each word will animate one after another.
- All words use the same animation class: .
data-at-line
đź’ˇ You can assign multiple animation classes or delay values if you want each word to behave differently. See Multiple Animation Classes for more.
Line-by-Line Animation
To animate each line of text separately, use the attribute:
`
html
`
First line
Second line
Third line
By default, AnimText splits lines using
tags or actual line breaks (\n) .
( . )
Splitting by Periods (Dot Separator) You can also split text into lines using periods, to do that, just add data-at-separator="dot".
`
html
`
Step 1. Step 2. Step 3.
.
Each sentence (ending in a ) will be treated as a separate line and animated one after another.
data-at-separator
Notes
- You don’t need to set if you're using
or line breaks - that’s the default behavior.
- Just like with words, you can assign multiple animation classes and delay values for lines too!
🔥 You can assign different animation classes to each word or line to create more dynamic effects.
Just space-separate the class names inside the data-at-word or data-at-line attributes:
``html
`
class="cssanimation"
data-at-word="ca__fx-fadeIn ca__fx-moveFromTop ca__fx-moveFromBottom ca__fx-moveFromRight">
Each word animates uniquely
ca__fx-fadeIn
In this case, each word will use a different animation in order:
- "Each" - animate with
ca__fx-moveFromTop
- "word" - animate with
ca__fx-moveFromBottom
- "animates" - animate with
ca__fx-moveFromRight
- "uniquely" - animate with
`
If there are more words than classes, the last class will automatically be reused for the remaining words.
#### Line Example
html
class="cssanimation"
data-at-line="ca__fx-blurIn ca__fx-bounceFromTop ca__fx-bounceX">
First line
Second line
Third line
`
ca__fx-blurIn
Here:
- "First line" - animate with
ca__fx-bounceFromTop
- "Second line" - animate with
ca__fx-bounceX
- "Third line" - animate with
data-at-delay
đź’ˇ This lets you mix and match effects to make your animations feel more playful or dramatic.
Animation Delay
You can control the delay between each animated unit (letter, word, or line) using the attribute.
data-at-delay
The values are in milliseconds (ms).
The attribute specifies the delay before each animated unit (letter, word, or line) begins its animation. The values are in milliseconds (ms).
`
#### Single Value
If you use a single value, that delay will apply to every unit equally.
html
`
Each letter delays by 100ms
`
All letters will animate one after another, each with a 100ms delay.
#### Multiple Values:
You can also provide multiple delay values, separated by spaces.
Each value is used for the next unit in order. If you have more units than delays, the last delay value repeats.
html
`
First word, then 200ms, then 400ms, then 400ms
data-at-base-duration
This gives you full control over timing rhythm, such as staggered or pulsed animations.
---
đź’ˇ Tip
This pattern works with letters, words, and lines.
Example: data-at-delay="50 100 100" means:
- First unit → 50ms delay
- Next unit → 100ms
- Remaining units → 100ms
You can create subtle or dramatic timing effects just by changing the delay pattern.
Animation Base Duration
The attribute lets you set a default animation duration (in milliseconds) for all animated units — whether they’re letters, words, or lines.
`
This value overrides any duration found in your CSS animation classes.
html
`
class="cssanimation"
data-at-sequence="ca__fx-fadeIn"
data-at-base-duration="750">
Global base duration
animation-duration
In this example, all letters will animate with a base duration of 750ms - no need to set in CSS.
data-at-base-duration
How Duration is Chosen (Precedence)
1. (your manual override)
data-at-base-duration
2. CSS-defined duration (auto-detected from your animation class if is absent)
1000ms
3. Internal default (fallback if nothing is defined - usually )
data-at-base-duration
This means gives you full control: you can set durations directly in HTML without modifying your CSS.
.cssanimation
Developer Tips
- The class is required for AnimText to work, it activates the logic and provides default styles.
data-at-base-duration
- You can assign fewer animation classes or delay values than total units, the last value will repeat for the rest.
- If you assign more classes or delay values than units, the extra values are ignored, and a warning is logged to your console to help with debugging.
- All values (delays, durations) are parsed safely — invalid numbers are ignored and fall back to safe defaults.
- Duration logic follows this order:
-
animation-duration
- CSS-detected
1000ms
- Internal default ()
`
This setup makes AnimText flexible for both quick prototypes and polished production use.
Debugging AnimText
AnimText includes a simple debug mode that logs useful info to the browser console.
Enable Debug Mode
Set the following in your browser console or JavaScript file:
js
`
window.__ANIMTEXT_DEBUG = true;
`
This will show:
- Which elements are being processed
- What attributes were parsed
- Fallback warnings (e.g. invalid delay values)
Re-Init on Dynamic Content
If you inject new elements after page load, call:
js
`
animtext.init();
.cssanimation
This will scan the DOM again and animate any new elements.
`
Test Example
Put this in your index.html:
html
rel="stylesheet"
href="node_modules/@hellouxpavel/cssanimation/dist/cssanimation.css" />
Hello AnimText!