Create Dynamic Typing Effects With Typed.js: A Step-by-Step Guide

Learn how to easily implement captivating typing effects on your website using Typed.js: A comprehensive step-by-step guide for engaging user experiences.

Tara Prasad Routray
Level Up Coding

--

In today’s ever-evolving world of web development, where competition for user attention is intense, it has become increasingly important to go beyond static text and create immersive and engaging experiences for website visitors. One powerful technique that has gained popularity is the implementation of animated typing effects. These effects simulate the process of text being typed out in real time, adding a sense of dynamism and interactivity to the content.

To achieve these captivating animated typing effects, developers can turn to Typed.js, a versatile and lightweight JavaScript library purpose-built for this very task. Typed.js offers a seamless solution for integrating animated typing effects into web pages, empowering developers to craft visually impressive and attention-grabbing experiences that leave a lasting impression on users.

In this comprehensive guide, we will dive into Typed.js and explore its diverse options. We will take you step-by-step through the process of creating animated typing effects, from getting started with the library to customizing the behaviour and appearance of the animations. By the end of this guide, you will have a solid understanding of how to leverage Typed.js to enhance your web projects with the magic of animated typing.

Throughout this journey, we will equip you with the knowledge and skills necessary to breathe life into your website’s text content. Whether you want to create a captivating hero headline, simulate a command-line interface, or add subtle yet impactful animations to your paragraphs, Typed.js will be your trusty companion.

Integrate Typed.js In Your Website In 4 Easy Steps

  1. Set Up the HTML Structure
  2. Include the CDN Assets of the Typed.js Library
  3. Initialize the Typed.js Library
  4. Customize the Animations

Step 1: Set Up the HTML Structure

Begin by setting up the HTML structure for the element that will contain the typing effect. For example, you can use an <h1> element:

<!DOCTYPE html>
<html>
<head>
<title>Using Typed.js</title>
</head>
<body>
<h1 id="typed-text"></h1>
</body>
</html>

Step 2: Include the CDN Assets of the Typed.js Library

To start using Typed.js, you need to include the necessary JavaScript and CSS files in your web page. You can either download the library files and host them locally or include them using a Content Delivery Network (CDN).

Here’s an example of how to include Typed.js using a CDN:

<!DOCTYPE html>
<html>
<head>
<title>Using Typed.js</title>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/typed.js@2.0.12/lib/typed.min.css" />
</head>
<body>
<h1 id="typed-text"></h1>

<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/typed.js@2.0.12/lib/typed.min.js"></script>
</body>
</html>

Step 3: Initialize the Typed.js Library

Next, you need to initialize Typed.js and configure its behaviour. In the script section of your HTML file, add the following code:

<script>
const typed = new Typed('#typed-text', {
strings: ['Hello, World!', 'Welcome to Typed.js!'],
typeSpeed: 50,
loop: true
});
</script>

In the code above, we create a new instance of Typed.js by passing the ID of the element that will contain the typing effect (‘#typed-text’). We also provide an array of strings that will be typed out (‘Hello, World!’ and ‘Welcome to Typed.js!’). The typeSpeed option determines the speed at which each character is typed. By setting loop to true, the animation will repeat indefinitely.

Step 4: Customize the Animations

Typed.js provides a wide range of options and callbacks that allow you to customize the appearance and behaviour of the typing effect according to your needs. Here are some commonly used options:

  • backSpeed: The speed at which characters are erased during the backspace effect.
  • startDelay: The delay before typing starts.
  • loop: Whether the animation should loop.
  • showCursor: Whether to display a blinking cursor during typing.
  • cursorChar: The character to use for the cursor.
  • onComplete: A callback function to be called when typing is complete.

These options can be added to the initialization code, allowing you to tailor the animation to your specific requirements. For example:

const typed = new Typed('#typed-text', {
strings: ['Hello, World!', 'Welcome to Typed.js!'],
typeSpeed: 50,
backSpeed: 30,
startDelay: 1000,
loop: true,
showCursor: true,
cursorChar: '|',
onComplete: function() {
console.log('Typing animation complete!');
}
});

Kudos! You have completed learning how to utilize Typed.js to create stunning animated typing effects. Armed with this powerful tool, you can now bring your text content to life and incredibly engage your website’s visitors. Whether it’s for impressive hero headlines, interactive command-line simulations, or subtle paragraph animations, Typed.js offers endless possibilities. So go ahead, unleash your creativity, and transform your web pages into immersive experiences that leave a lasting impact. Happy coding!

If you enjoyed reading this article and have found it useful, then please give it a clap, share it with your friends, and follow me to get more updates on my upcoming articles. You can connect with me on LinkedIn. Or, you can visit my official website: tararoutray.com to know more about me.

Level Up Coding

Thanks for being a part of our community! Before you go:

🚀👉 Join the Level Up talent collective and find an amazing job

--

--