Placeholder Typing Effect in HTML CSS & JavaScript

In this article you will learn how to create place holder typing effect using HTML CSS and JavaScript.

Earlier I have shared with you many more types of animated place holder designs. But this Textbox Placeholder Typing Effect is made a bit differently. The place holder here is typing.

To make this Placeholder With Typing Animation I created an input box using basic HTML and used CSS to design it. At the end, I added the typing effect to this place holder using JavaScript.

Placeholder Typing Animation in HTML, CSS, Javascript

A Placeholder Typing Effect is a visual enhancement applied to HTML form input elements using JavaScript to simulate the appearance of someone typing within the input field. 

This effect is often employed to create a dynamic and engaging user interface, especially in scenarios where you want to draw attention to a form field or provide a hint to the user.

See the Pen Untitled by Growthpanda (@Growthpanda) on CodePen.

As you can see in the above demo of Input placeholder typing animation I have created a box in which I have created an input box using HTML’s input function. Then here I added a kind of place holder animation.

Earlier I have shared with you many other types of text animation designs. If you want to know how to create typing animation then you can see those articles.

Step 1: Structure of the placeholder typing effect

We will create the structure of this project (Placeholder Typing Effect in JavaScript) using the following html. I used the input box and a label to create the placeholder.

<div class="container">
    <label for="email-id">Email</label>
    <input type="email" id="email-id">
</div>

Step 2: Animated placeholder CSS Code

Now designed the Animated placeholder using some CSS. Basically this code is used to design input boxes and placeholders.

*,
*:before,
*:after{
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}
body{
    height: 100vh;
    background: linear-gradient(
        135deg,
        #ff5b84,
        #eb3461
    );
}
.container{
    background-color: #1c1c27;
    padding: 50px;
    position: absolute;
    transform: translate(-50%,-50%);
    top: 50%;
    left: 50%;
    border-radius: 5px;
    box-shadow: 0 15px 25px rgba(0,0,0,0.15);
}
label,
input{
    font-family: "DM Sans",sans-serif;
    font-size: 18px;
    letter-spacing: 0.5px;
}
label{
    display: block;
    position: relative;
    color: #eb3461;
    font-weight: 500;
    margin-bottom: 10px;
}
input{
    position: relative;
    width: 300px;
    padding: 10px 0;
    background-color: transparent;
    border: none;
    border-bottom: 1.5px solid #eb3461;
    outline: none;
    color: #e5e5e5;
    font-weight: 400;
}

Step 3: Placeholder Typing Effect JavaScript Code

Now we need to activate the Placeholder Typing Effect using some JavaScript. Here below javascript will help basically for text typing.

let i = 0;
let placeholder = "";
const txt = "[email protected]";
const speed = 120;

function type(){
    placeholder += txt.charAt(i);
    document.getElementById("email-id").setAttribute("placeholder",placeholder);
    i++;
    setTimeout(type,speed);
}

type();

By combining HTML, CSS, and JavaScript, you can easily implement a placeholder typing effect to add a touch of dynamism to your web pages. This subtle animation not only enhances the visual appeal of your forms but also contributes to a more engaging and interactive user experience.

Comment how you like this Placeholder With Typing Animation in JavaScript. If you want to download the source code then use the download button below.

Animating placeholders in input fields can provide a more dynamic and user-friendly experience. You can achieve this using HTML, CSS, and JavaScript. Below is an example of how you can create a dynamic animated placeholder for an input field:

 
<style>
body {
font-family: ‘Arial’, sans-serif;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #f4f4f4;
}

.input-container {
position: relative;
}

input {
width: 300px;
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 5px;
outline: none;
}

label {
position: absolute;
top: 50%;
left: 10px;
transform: translateY(-50%);
color: #888;
pointer-events: none;
transition: 0.3s;
}

input:focus + label, input:not(:placeholder-shown) + label {
font-size: 12px;
top: 0;
color: #333;
}
</style>
<div class=”input-container”>
<input type=”text” id=”inputField” placeholder=” “>
<label for=”inputField”>Your Placeholder</label>
</div>

<script>
// Add event listener to handle input focus
document.getElementById(‘inputField’).addEventListener(‘focus’, function () {
this.placeholder = ”;
});

// Add event listener to handle input blur
document.getElementById(‘inputField’).addEventListener(‘blur’, function () {
this.placeholder = ‘ ‘;
});
</script>

To create a typing animation for an input placeholder using HTML, CSS, and JavaScript, you can simulate the typing effect by gradually revealing the characters. Here’s an example:


<style>
body {
font-family: ‘Arial’, sans-serif;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #f4f4f4;
}

.input-container {
position: relative;
}

input {
width: 300px;
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 5px;
outline: none;
}

.placeholder-text {
position: absolute;
top: 50%;
left: 10px;
transform: translateY(-50%);
color: #888;
white-space: nowrap;
overflow: hidden;
animation: typing 2s steps(28) infinite;
}

@keyframes typing {
from {
width: 0;
}
to {
width: 100%;
}
}
</style>

<div class=”input-container”>
<input type=”text” id=”inputField” placeholder=””>
<div class=”placeholder-text”>Your Placeholder</div>
</div>

<script>
const inputField = document.getElementById(‘inputField’);
const placeholderText = document.querySelector(‘.placeholder-text’);

// Update placeholder text based on input value
inputField.addEventListener(‘input’, function () {
placeholderText.textContent = this.value || ‘ ‘;
});
</script>

 

Leave a Comment