Email Validation using HTML, CSS & JavaScript

Email Validation using HTML, CSS & JavaScript

Email Validation using HTML, CSS & JavaScript

Hello everyone. Welcome to today’s tutorial on Codewithrandom. We’ll learn how to make Email Validation which will check the email address of the user which is entered in the textbox is valid or not and matches the condition which an email has. In Today’s session, We will use HTML, CSS, and JavaScript to complete this Email Validation Project.

Project Description

Step 1
The HTML (Hypertext Markup Language) will help us to create the structure for the list with some necessary attributes and elements to make Email Validation Project.

Step 2
Then we will use CSS (Cascading Stylesheet) which will help us to style or design the project with suitable padding and alignment in the Email Validation Project.

Step 3
At last we will use JS (JavaScript) which will add a logic to make the Email Validation Project responsive from the user end.

I hope you have got an idea about the project.

HTML Code for Email Validation

First we’ll start with creating the structure of the Email Validation project for that as you can see the above code we have used all the necessary elements & attributes to setup the structure. Let us know code the CSS part to add styling and aligned the tags.

<html lang="en">
    <title>Email Validation</title>
    <!--FontAwesome Icons-->
    <link rel="stylesheet" href="">
    <!--Google Fonts-->
    <link href=";500&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="style.css">
    <div class="container">
        <label for="email-id">Email Id</label><br>
        <input type="email" id="email-id" oninput="checker()">
        <div id="icon">
        <p id="error-msg">Please Enter A Valid Email Id</p>
<script src="script.js"></script>

50+ HTML, CSS & JavaScript Projects With Source Code

CSS Code for Email Validation

Second comes the CSS code in which we have styled for the structure we have padded as well as aligned the Email Validation project so that it is properly situated and doesn’t get messy with suitable CSS elements. Now lets code the JavaScript part to make responsive.

    padding: 0;
    margin: 0;
    box-sizing: border-box;
    height: 100vh;
    background: linear-gradient(
    width: 400px;
    background-color: #ffffff;
    padding: 50px 30px;
    position: absolute;
    transform: translate(-50%,-50%);
    top: 50%;
    left: 50%;
    border-radius: 10px;
    box-shadow: 25px 25px 30px rgba(0,0,0,0.15);
    color: #111111;
    font-family: 'Poppins',sans-serif;
    display: inline-block;
    font-weight: 500;
    margin-bottom: 10px;
    display: inline-block;
    border: 2px solid #d1d3d4;
    width: 88%;
    height: 50px;
    border-radius: 5px;
    outline: none;
    letter-spacing: 0.5px;
    font-weight: 400;
    float: right;
    height: 50px;
    position: relative;
    font-size: 25px;
    padding-top: 10px;
    display: none;
    color: #ff2851;
    font-size: 14px;
    margin-top: 10px;

JavaScript Code for Email Validation

Last stage of the project the JavaScript in which we have added the logical and coded as per the requirement with some conditions. Let us see the Final Output of the project Email Validation using HTML, CSS & JavaScript (Source Code).

// Regex Pattern: /^[a-zA-Z][a-zA-Z0-9\-\_\.]+@[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}$/

let emailId = document.getElementById("email-id");
let errorMsg = document.getElementById("error-msg");
let icon = document.getElementById("icon");
let mailRegex = /^[a-zA-Z][a-zA-Z0-9\-\_\.]+@[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}$/;

function checker(){"inline-block";
        icon.innerHTML = '<i class="fas fa-check-circle"></i>'; = '#2ecc71'; = 'none'; = '2px solid #2ecc71';
    else if(emailId.value == ""){ = 'none'; = 'none'; = '2px solid #d1d3d4';
        icon.innerHTML = '<i class="fas fa-exclamation-circle"></i>'; = '#ff2851'; = 'block'; = '2px solid #ff2851';


10+ Javascript Projects For Beginners With Source Code

Final Output

We have Successfully created our Email Validation using HTML, CSS & JavaScript (Source Code). You can use this project for your personal needs and the respective lines of code are given with the code pen link mentioned above.

If you find out this Blog helpful, then make sure to search code with random on google for Front End Projects with Source codes and make sure to Follow the Code with Random Instagram page.

Code Idea – codingartist

Written By – Harsh Sawant

Code By – @harshh9

Leave a Reply