You are currently viewing Palindrome Checker using HTML, CSS and JavaScript

Palindrome Checker using HTML, CSS and JavaScript

Palindrome Checker using HTML, CSS and JavaScript

Hello everyone. Welcome to today’s tutorial on Codewithrandom. We’ll learn how to make a Palindrome which is a term that indicates if you reverse the word the pronunciation will be the same while calling out.

In Today’s session, We will use HTML, CSS, and JavaScript to complete this Project.

The HTML (Hypertext Markup Language) will help us to create the structure for the list with some necessary attributes and elements to make Image Slider.

Then we will use CSS (Cascading Stylesheet) which will help us to style or design the project with suitable padding and alignment in the Image Slider project.

At last we will use JS (JavaScript) which will add a logic to make the Palindrome project responsive from the user end.

I hope you have got an idea about the project.

HTML Code for Palindrome

<html lang="en">
<head>
    <title>Palindrome Checker</title>
    <!--Google Font-->
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500&display=swap" rel="stylesheet">
    <!--Stylesheet-->
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="container">
        <input type="text" id="input-text" placeholder="Enter a word to check">
        <button id="btn">Check</button>
        <p id="result"></p>
    </div>
    <script src="script.js"></script>
</body>
</html>

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

5+ HTML CSS Projects With Source Code

CSS Code for Palindrome

*,
*:before,
*:after{
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}
body{
    background-color: #b156fe;
}
.container{
    width: 35%;
    min-width: 450px;
    background-color: #ffffff;
    padding: 50px 30px;
    position: absolute;
    transform: translate(-50%,-50%);
    left: 50%;
    top: 50%;
    border-radius: 8px;
    box-shadow: 0 20px 25px rgba(0,0,0,0.18);
}
.container *{
    font-family: "DM Sans", sans-serif;
    outline: none;
    font-size: 16px;
}
input{
    width: 60%;
    border: none;
    border-bottom: 2px solid #d5d5d5;
    padding: 10px 5px;
    font-weight: 400;
}
input:focus{
    border-bottom: 2px solid #b156fe;
}
button{
    width: 25%;
    float: right;
    padding: 10px 20px;
    background-color: #b156fe;
    border: none;
    border-radius: 3px;
    color: #ffffff;
    font-weight: 400;
}
p{
    margin-top: 30px;
    text-align: center;
    color: #b156fe;
    font-weight: 500;
}*

Second comes the CSS code in which we have styled for the structure we have padded as well as aligned the Palindrome 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.

50+ Html ,Css & Javascript Projects With Source Code

JavaScript Code for Palindrome

document.getElementById("btn").addEventListener("click",function(){
    let txt = document.getElementById("input-text").value;
    checkPalindrome(txt);
});

function checkPalindrome(txt){
    let txt_new = txt.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
    let len = txt_new.length;
    let halfLen = Math.floor( len/2 );
    let result =document.getElementById("result");
    let i;

    for( i = 0; i < halfLen; i++){
        if( txt_new[i] !== txt_new[len-1-i]){
            result.textContent = "Nope! Not a palindrome";
            return;
        }
        result.textContent = "Yes! It's a palindrome"
    }
}

The last stage of the project the JavaScript in which we added the logic and coded as per the requirement with some conditions that will check whether the following word entered by the user is a palindrome or not. Let us see the Final Output of the project Palindrome Checker using HTML, CSS, and JavaScript.

100+ JavaScript Projects With Source Code ( Beginners to Advanced)

Final Output Of Palindrome Checker using HTML, CSS, and JavaScript


We have successfully created our Palindrome 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