Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A plugin for Tailwind CSS to generate text typing animations.

License

NotificationsYou must be signed in to change notification settings

MoritzBru/tailwind-plugin-typed

Repository files navigation

GitHub Actions Workflow StatusGitHub TagNPM VersionNPM DownloadsTailwind PlayTailwind Play

A plugin forTailwind CSS to generate text typing animations.

Live Demo

See it in action in the Tailwind Playground forTailwind CSS v3.x and forTailwind CSS v4.x

📦 Installation

Install the package with your preferred package manager (e.g.npm)

npm i -D tailwind-plugin-typed

🔧 Configuration

For Tailwind CSS v3.x

Add the plugin to yourconfiguration

/**@type {import('tailwindcss').Config} */module.exports={// ... other tailwind configplugins:[require('tailwind-plugin-typed'),// ... other plugins],}

For Tailwind CSS v4.x

Add the plugin to your CSS via the@plugin directive

@import"tailwindcss";@plugin"tailwind-plugin-typed";

⚙️ Options

This plugin exposes some optional options that can be passed in the tailwind configuration

namedescriptiondefault
delimitercharacter on which strings are split;
typeLetterDurationduration in seconds for typing one single character0.1
pauseAfterWordDurationpause in seconds after one whole string is typed2
deleteLetterDurationduration in seconds for deleting one single character0.05
pauseAfterDeletionDurationpause in seconds after one whole string is deleted1

Exmaple for Tailwind CSS v3.x

/**@type {import('tailwindcss').Config} */module.exports={// ... other tailwind configplugins:[// ... other pluginsrequire('tailwind-plugin-typed')({delimiter:';',typeLetterDuration:0.1,pauseAfterWordDuration:2,deleteLetterDuration:0.05,pauseAfterDeletionDuration:1,}),],}

Example for Tailwind CSS v4.x

@import"tailwindcss";@plugin"tailwind-plugin-typed" {delimiter:';',  typeLetterDuration:0.1,  pauseAfterWordDuration:2,  deleteLetterDuration:0.05,  pauseAfterDeletionDuration:1,}

💻 Usage

This plugin utilisesarbitrary values of Tailwind CSS on the base classtyped to generate a typing animation with CSS.

caret

This generates a blinking caret in an::after pseudo element.

<pclass="typed-caret">Typed</p>
caret typed

single string

This generates an infite looping typing and deleting animation of the stringworld.

<p>Hello<spanclass="typed-[world] typed-caret"></span></p>
one string typed

multiple strings

This generates a typing and deleting animation of multiple words one after another. The default delimiter of strings is; but can be configured in theplugin options.

<p>This is<spanclass="typed-[cool;awesome;superb] typed-caret"></span></p>
multiple strings typed

sentences

One or multiple sentences can be typed as well. Just write an underscore_ instead of a space as decribed in thetailwind docs.

<pclass="typed-[This_can_type_sentences.;And_then_delete_them…] typed-caret"></p>
senteces typed

adjust the caret

There are utilitiestyped-caret-color,typed-caret-width andtyped-caret-space to adjust the caret.

<p>Caret<spanclass="typed-[color;width;space] typed-caret typed-caret-color-emerald-400 dark:typed-caret-color-emerald-600 typed-caret-width-4 typed-caret-space-2"></span></p>
adjusted caret typed

escaping the delimiter and special chars

The delimiter can be escaped with a backslash\ in front of it. Then it will be typed out normally.If otherreserved characters (e.g. colon:) should be typed, the whole arbitrary value can be wrapped in backticks` which will be removed automatically

<pclass="typed-[`semi:_true\;;semi:_false\;`] typed-caret"></p>
escaped special chars typed

♿️ Notes on a11y

This plugin addsalternative text to thecontent of the pseudo element upon typing so that screen readers canhopefully read the whole text that is being typed at all times and are not affected by the animation.

Tailwind itself provides modfiers to adjust for theusers preference regardingreduced motion.

This example will render a typing animation of the stringno preference in case the user does not specify a preferences for reduced motion. In case the users preferes to have an experience with reduced motion the static textreduce will be rendered.

<p>  prefers-reduced-motion:<spanclass="motion-safe:typed-[no_preference] motion-safe:typed-caret"></span><spanclass="motion-safe:hidden">reduce</span></p>

💕 Thanks

This project is heavily inspired by other awesome projects like:


[8]ページ先頭

©2009-2025 Movatter.jp