DEV Community

Sh Raj
Sh Raj

Posted on

Add Typing Animation Effect using JavaScript - Enhancing Your Website ❤

Typed.js

To add a typing animation effect to your website, you can utilize JavaScript libraries like Typed.js or create a custom implementation. Here's a step-by-step guide on how to implement a typing animation using Typed.js:

  1. Include the Typed.js library:

    • Download the Typed.js library from the official website (https://mattboldt.com/demos/typed-js/).
    • Include the Typed.js script in your HTML file by adding the following code within the <head> section:
     <script src="path/to/typed.js"></script>
    
  2. Create an HTML element to display the typing animation:

    • Add an HTML element, such as a <span>, to your webpage where you want the typing animation to appear:
     <span id="typed-text"></span>
    
  3. Initialize Typed.js and configure the animation:

    • Create a new JavaScript file or include the following code within a <script> tag in your HTML file:
     var typed = new Typed('#typed-text', {
       strings: ['Hello, World!', 'Welcome to my website!'],
       typeSpeed: 50,
       loop: true
     });
    
  • In the strings array, define the phrases or sentences you want to display in the typing animation.
  • Adjust the typeSpeed to control the speed of the typing effect (measured in milliseconds).
  • Setting loop to true will make the animation repeat indefinitely. You can set it to false if you want the animation to stop after displaying the defined strings once.
  1. Save your files and open the HTML file in a web browser.
    • You should see the typing animation effect in the specified HTML element, with the text gradually appearing as if being typed out.

Note: Make sure to adjust the paths and IDs in the code snippets based on your specific HTML structure.

Customization:
Typed.js offers various customization options to modify the appearance and behavior of the typing animation. You can explore the official documentation (https://mattboldt.com/demos/typed-js/) for more details on customizing the animation's speed, backspacing, cursor style, callbacks, and more.

Remember to add appropriate styling using CSS to make the typed text visually appealing and blend seamlessly with your website's design.

With these steps, you can easily incorporate a typing animation effect into your website and enhance the visual experience for your users.


TypewriterJS

  1. Include the TypewriterJS library:

    • Download the TypewriterJS library from the official website (https://safi.me.uk/typewriterjs/).
    • Include the TypewriterJS script in your HTML file by adding the following code within the <head> section:
     <script src="path/to/typewriter.js"></script>
    
  2. Create an HTML element to display the typing animation:

    • Add an HTML element, such as a <span>, to your webpage where you want the typing animation to appear:
     <span id="typewriter"></span>
    
  3. Initialize TypewriterJS and configure the animation:

    • Create a new JavaScript file or include the following code within a <script> tag in your HTML file:
     var typewriter = new Typewriter('#typewriter', {
       strings: ['Hello, World!', 'Welcome to my website!'],
       autoStart: true,
       loop: true
     });
    
  • In the strings array, define the phrases or sentences you want to display in the typing animation.
  • Set autoStart to true to automatically start the typing animation.
  • Setting loop to true will make the animation repeat indefinitely. You can set it to false if you want the animation to stop after displaying the defined strings once.
  1. Save your files and open the HTML file in a web browser.
    • You should see the typing animation effect in the specified HTML element, with the text gradually appearing as if being typed out.

Note: Ensure that you adjust the paths and IDs in the code snippets based on your specific HTML structure.

Customization:
TypewriterJS provides various customization options to modify the animation's speed, backspacing, cursor style, delay, and more. You can explore the official documentation (https://safi.me.uk/typewriterjs/) to learn more about the available configuration options.

Remember to add appropriate styling using CSS to make the typed text visually appealing and to match your website's design.

By following these steps, you can easily incorporate a typing animation effect into your website using the TypewriterJS library. Enjoy creating engaging and dynamic content for your users!

Top comments (0)