Natural typing animations

Typecadence is a JavaScript library that provides an animated typing effect that automatically simulates natural human typing, including speed variations and mistakes. It applies the animation to any HTML element with the class typecadence, which plays only when the element is visible to the user.

<span class="typecadence">This is Typecadence with its default settings.</span>
This is Typecadence with its default settings.

Installation Options

CDN (Recommended)

Include the following script tag in your HTML document:

<script src="https://cdn.jsdelivr.net/npm/typecadence@^1"></script>

NPM

Install Typecadence using NPM in your project directory via the command line:

npm install typecadence

Then import Typecadence into your TypeScript/JavaScript project:

import Typecadence from 'typecadence';

Download

Download the latest version of Typecadence from the GitHub repository and include the /dist/typecadence.js file in your project.

Typing

Typing: Speed

The minimum and maximum typing speed. The value is a single number of milliseconds or a range in milliseconds separated by a comma. Each new keystroke is typed at the specified speed or a random speed within the specified range.

  • Attribute: data-typecadence-speed
  • Value: Number[,Number]
  • Default: 50,100
<span class="typecadence" data-typecadence-speed="200,1400">This is Typecadence with a custom speed.</span>
This is Typecadence with a custom speed.

Typing: Delay

The delay before typing starts. The value is a number of milliseconds.

  • Attribute: data-typecadence-delay
  • Value: Number
  • Default: 0
<span class="typecadence" data-typecadence-delay="3000">This is Typecadence with a three-second start delay.</span>
This is Typecadence with a three-second start delay.

Mistakes

Mistakes: Chance

The chance of a mistake being made with each keystroke. The value is a percentage.

  • Attribute: data-typecadence-mistakes
  • Value: Number
  • Default: 5
<span class="typecadence" data-typecadence-mistakes="25">This is Typecadence with a 25% chance of a mistake being made with each keystroke.</span>
This is Typecadence with a 25% chance of a mistake being made with each keystroke.

Mistakes: Present

If there is a chance for mistakes, this is the maximum number of mistakes that can be present before backspacing to correct the earliest mistake.

  • Attribute: data-typecadence-mistakes-present
  • Value: Number
  • Default: 1
<span class="typecadence" data-typecadence-mistakes-present="3">This is Typecadence with a maximum of three mistakes present before backspacing to correct the earliest mistake.</span>
This is Typecadence with a maximum of three mistakes present before backspacing to correct the earliest mistake.

Mistakes: Keyboard Layout

If there is a chance for mistakes, this is the keyboard layout used to determine which keys are adjacent to each other for mistakes.

  • Attribute: data-typecadence-mistakes-keyboard
  • Value: String
  • Options: qwerty, qwertz, or azerty
  • Default: qwerty
<span class="typecadence" data-typecadence-mistakes-keyboard="azerty">This is Typecadence with a AZERTY keyboard layout.</span>
This is Typecadence with a AZERTY keyboard layout.

Caret

If displayed, the caret is a <span> with a class of typecadence-caret.

Caret: Display

Disable the caret.

  • Attribute: data-typecadence-caret
  • Value: Boolean
  • Default: true
<span class="typecadence" data-typecadence-caret="false">This is Typecadence with caret.</span>
This is Typecadence without a caret.

Caret: Character

The caret character.

  • Attribute: data-typecadence-caret-char
  • Value: String
  • Default: |
<span class="typecadence" data-typecadence-caret-char="_">This is Typecadence with a custom caret character.</span>
This is Typecadence with a custom caret character.

Caret: Color

The caret color.

  • Attribute: data-typecadence-caret-color
  • Value: String
  • Default: inherit
<span class="typecadence" data-typecadence-caret-color="#cc2127">This is Typecadence with a custom caret color.</span>
This is Typecadence with a custom caret color.

Caret: Blink

Disable the caret's blinking animation.

  • Attribute: data-typecadence-caret-blink
  • Value: Boolean
  • Default: true
<span class="typecadence" data-typecadence-caret-blink="false">This is Typecadence without a blinking caret.</span>
This is Typecadence without a blinking caret.

Caret: Blink Speed

The caret blink speed. The value is in milliseconds.

  • Attribute: data-typecadence-caret-blink-speed
  • Value: Number
  • Default: 500
<span class="typecadence" data-typecadence-caret-blink-speed="1000">This is Typecadence with a slower blinking caret.</span>
This is Typecadence with a slower blinking caret.

Caret: Remain

The caret can be set to permanently remain at the end of the text.

  • Attribute: data-typecadence-caret-remain
  • Value: Boolean
  • Default: false
<span class="typecadence" data-typecadence-caret-remain="true">This is Typecadence with a caret that permanently remains at the end of the text.</span>
This is Typecadence with a caret that permanently remains at the end of the text.

Caret: Remain Timeout

The caret can be set to remain at the end of the text for a specific amount of time. The value is in milliseconds.

  • Attribute: data-typecadence-caret-remain-timeout
  • Value: Number
  • Default: 0
<span class="typecadence" data-typecadence-caret-remain-timeout="5000">This is Typecadence with a caret that remains at the end of the text for five seconds.</span>
This is Typecadence with a caret that remains at the end of the text for five seconds.