
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to create a typing effect with JavaScript?
To create a typing effect with JavaScript, the code is as follows −
Example
<!DOCTYPE html> <html> <head> <style> body{ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } button{ padding:10px; font-size: 18px; background-color: rgb(128, 19, 218); color:white; border:none; } .heading{ color:crimson; } </style> </head> <body> <h1>typeText</h1> <button class="typeButton">Click me</button> <h2 class="heading"></h2> <script> document.querySelector('.typeButton').addEventListener('click',typeText); var i = 0; var text = 'This text is currently being typed across... It is still typing..'; var speed = 50; function typeText() { if (i < text.length) { document.querySelector('.heading').innerHTML += text.charAt(i); i++; setTimeout(typeText, speed); } } </script> </body> </html>
Output
The above code will produce the following output −
On clicking the “Click me” button −
- Related Articles
- Typing and Deleting Effect with JavaScript and CSS
- How to create a transition effect with CSS?
- How to create a smooth scrolling effect with CSS?
- How to create a "parallax" scrolling effect with CSS?
- How to create fading effect with CSS
- How to Create a Parallax Effect using HTML, CSS, and JavaScript?
- How to create an overlay effect with CSS?
- How to create image overlay hover effect with CSS?
- How to set the shadow effect of a text with JavaScript?
- How to create image overlay icon effect on hover with CSS?
- How to Design a Calculator with Neumorphism Effect/Soft UI in JavaScript?
- How to Create a Parallax Scrolling Effect in CSS
- How to create a line break with JavaScript?
- How to create a filter table with JavaScript?
- How to create a countdown timer with JavaScript?

Advertisements