A lightweight, customizable glitch text effect library with zero dependencies. Framework-agnostic core with React wrapper.
npm install glitch-text-effectA lightweight, customizable glitch text effect library with zero dependencies. Framework-agnostic core with React wrapper.



- ðŠķ Lightweight: < 3KB gzipped, zero dependencies
- ðŊ Framework Agnostic: Works with React, Vue, Svelte, or vanilla JS
- ð§ Highly Customizable: Multiple trigger types, intensity levels, and effects
- ðą Accessible: Respects prefers-reduced-motion
- ðĻ Multiple Triggers: Hover, click, intersection observer, or manual control
- ⥠Performance First: RAF-based animations, no DOM thrashing
- ðïļ Tree Shakeable: Import only what you need
- ðĶ TypeScript: Full type definitions included
``bash`
npm install glitch-text-effect
`jsx
import { GlitchText } from 'glitch-text-effect/react';
function App() {
return (
to="Glitch Effect!"
trigger="hover"
className="text-2xl font-bold"
/>
);
}
`
`js
import { glitch } from 'glitch-text-effect';
const element = document.querySelector('#my-text');
glitch(element, {
from: 'Hello World',
to: 'Glitch Effect!',
duration: 1000,
trigger: 'hover'
});
`
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| from | string | required | Source text to transform from |to
| | string | required | Target text to transform to |duration
| | number | 1200 | Animation duration in milliseconds |trigger
| | 'hover' \| 'click' \| 'intersection' \| 'manual' | 'hover' | How the animation is triggered |intensity
| | 'low' \| 'medium' \| 'high' | 'medium' | Intensity of the glitch effect |
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| characters | CharacterSet \| string | 'letters' | Character sets for randomization |timing
| | TimingFunction | 'easeOut' | Animation timing function |revealRate
| | number | 0.5 | Rate at which characters are revealed (0-1) |glitchRate
| | number | 0.6 | Frequency of character randomization (0-1) |effects
| | VisualEffects | {} | Visual effects to apply |respectReducedMotion
| | boolean | true | Respect user's motion preferences |
- letters - A-Z, a-znumbers
- - 0-9 symbols
- - Special characters (!@#$%^&*)alphanumeric
- - Letters + numbersall
- - Everything combined
- Custom string - Use your own characters
jsx
`$3
`jsx
`$3
`jsx
`$3
`jsx
import { useGlitchText } from 'glitch-text-effect/react';function ManualExample() {
const glitch = useGlitchText({
from: 'Manual',
to: 'Control!'
});
return (
Manual
);
}
`ð Visual Effects
`jsx
from="Effects"
to="Awesome!"
effects={{
shake: true, // Subtle trembling
flicker: true, // Opacity variation
colorShift: true, // Color cycling (default colors)
scalePulse: true // Size pulsing
}}
/>
`$3
Customize the colors and animation speed for color shifting:
`jsx
from="Custom Colors"
to="Rainbow!"
effects={{
colorShift: {
enabled: true,
colors: ['#ff6b6b', '#4ecdc4', '#45b7d1', '#96ceb4', '#feca57'],
speed: 2 // Animation speed multiplier
}
}}
/>
`#### ColorShift Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
|
enabled | boolean | true | Enable color shifting |
| colors | string[] | ['#ff0080', '#00ff80', '#8000ff', '#ff8000', '#0080ff', '#ffffff'] | Array of hex colors to cycle through |
| speed | number | 1 | Animation speed multiplier (higher = faster) |ðïļ Vanilla JavaScript API
$3
`js
import { glitch } from 'glitch-text-effect';// Promise-based
await glitch(element, { from: 'Hello', to: 'World' });
// With callbacks
glitch(element, {
from: 'Hello',
to: 'World',
onStart: () => console.log('Started'),
onComplete: () => console.log('Done')
});
`$3
`js
import { createGlitch } from 'glitch-text-effect';const instance = createGlitch(element, {
from: 'Hello',
to: 'World',
duration: 2000,
intensity: 'high',
effects: {
colorShift: {
enabled: true,
colors: ['#ff0080', '#00ff80', '#8000ff'],
speed: 1.5
}
}
});
// Control manually
instance.start();
instance.stop();
instance.reset();
instance.destroy();
`ðĶ Bundle Optimization
Import only what you need:
`js
// React only
import { GlitchText } from 'glitch-text-effect/react';// Vanilla JS only
import { glitch } from 'glitch-text-effect/core';
// Everything
import { GlitchText, glitch } from 'glitch-text-effect';
`ðŊ TypeScript
Full TypeScript support with comprehensive type definitions:
`tsx
import type { GlitchConfig, IntensityLevel } from 'glitch-text-effect';const config: GlitchConfig = {
from: 'Typed',
to: 'Safe!',
intensity: 'high' as IntensityLevel,
effects: {
shake: true,
colorShift: true
}
};
`ð§ Development
`bash
Install dependencies
npm installBuild the library
npm run buildRun type checking
npm run type-checkRun linting
npm run lint
``MIT ÂĐ Jose Maria Molina
Contributions are welcome! Please feel free to submit a Pull Request.
Check out the examples directory for more usage patterns and integrations.
---
Made by Jose Maria Molina