Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
Palindrome in JavaScript
Next article icon

Build a Palindrome Checker App using JavaScript

Last Updated : 02 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

A palindrome is a word, phrase, or sequence that reads the same backwards as forward, ignoring spaces, punctuation, and capitalization. know as the palindrome.

What We Are Going to Create

We will create a simple web application where users can input a word or phrase to check if it’s a palindrome. The application will feature:

  • A clean and responsive design.
  • A text input for the user to enter text.
  • A button to trigger the palindrome check.
  • A result section that displays whether the input is a palindrome.

Project Preview

Palindrome
Build a Palindrome Checker App using JavaScript

Palindrome Checker App - HTML Structure

HTML
<html> <head></head> <body>     <div class="container">         <h1>Palindrome Checker</h1>         <p>Enter a word or phrase to check if it’s a palindrome.</p>         <input type="text" id="input" placeholder="Type here...">         <button id="check">Check Palindrome</button>         <div id="result"></div>     </div> </body> </html> 

In this example

  • The <div> with class container organizes the UI components.
  • <h1> displays the title "Palindrome Checker."
  • <p> provides a brief instruction for the user.
  • <input> accepts user input.
  • <button> triggers the palindrome check.
  • <div> with id="result" displays the output.

Palindrome Checker App - CSS Styles

CSS
body {     font-family: Arial, sans-serif;     display: flex;     justify-content: center;     align-items: center;     height: 100vh;     background-color: #f0f0f0;     margin: 0; } .container {     background-color: #ffffff;     padding: 20px;     border-radius: 10px;     text-align: center;     box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);     width: 90%;     max-width: 400px; } h1 {     font-size: 1.5em;     color: #333; } p {     font-size: 1em;     color: #666;     margin-bottom: 20px; } input {     width: 100%;     padding: 10px;     font-size: 1em;     border: 1px solid #ddd;     border-radius: 5px;     margin-bottom: 10px; } button {     width: 100%;     padding: 10px;     font-size: 1em;     background-color: #007BFF;     color: #fff;     border: none;     border-radius: 5px;     cursor: pointer; } button:hover {     background-color: #0056b3; } #result {     margin-top: 20px;     font-size: 1.1em; } 

In this example

  • The body is styled to center the application on the screen.
  • .container defines the application layout with padding and a shadow for aesthetics.
  • h1, p, input, and button are styled for clarity and usability.
  • #result is styled to display the output prominently.

Palindrome Checker App - JavaScript Functionality

JavaScript
document.getElementById("check").addEventListener("click", function () {     const input = document.getElementById("input").value.trim();     const result = document.getElementById("result");      if (input) {         // Normalize the text         const norm = input.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();         const rev = norm.split("").reverse().join("");          // Check if it’s a palindrome         if (norm === rev) {             result.textContent = `"${input}" is a palindrome!`;             result.style.color = "green";         } else {             result.textContent = `"${input}" is not a palindrome.`;             result.style.color = "red";         }     } else {         result.textContent = "Please enter some text.";         result.style.color = "orange";     } }); 

In this example

  • The addEventListener listens for a click on the button.
  • input fetches and trims user input.
  • norm removes non-alphanumeric characters and converts text to lowercase.
  • rev reverses the string for comparison.
  • Conditional checks determine if the input is a palindrome and updates the result.

Complete Code

HTML
<html> <head>     <style>         body {             font-family: Arial, sans-serif;             display: flex;             justify-content: center;             align-items: center;             height: 100vh;             background-color: #f0f0f0;             margin: 0;         }         .container {             background-color: #ffffff;             padding: 20px;             border-radius: 10px;             text-align: center;             box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);             width: 90%;             max-width: 400px;         }         h1 {             font-size: 1.5em;             color: #333;         }         p {             font-size: 1em;             color: #666;             margin-bottom: 20px;         }         input {             width: 100%;             padding: 10px;             font-size: 1em;             border: 1px solid #ddd;             border-radius: 5px;             margin-bottom: 10px;         }         button {             width: 100%;             padding: 10px;             font-size: 1em;             background-color: #007BFF;             color: #fff;             border: none;             border-radius: 5px;             cursor: pointer;         }         button:hover {             background-color: #0056b3;         }         #result {             margin-top: 20px;             font-size: 1.1em;         }     </style> </head> <body>     <div class="container">         <h1>Palindrome Checker</h1>         <p>Enter a word or phrase to check if it’s a palindrome.</p>         <input type="text" id="input" placeholder="Type here...">         <button id="check">Check Palindrome</button>         <div id="result"></div>     </div> <script>     document.getElementById("check").addEventListener("click", function () {         const input = document.getElementById("input").value.trim();         const result = document.getElementById("result");         if (input) {             const norm = input.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();             const rev = norm.split("").reverse().join("");             if (norm === rev) {                 result.textContent = `"${input}" is a palindrome!`;                 result.style.color = "green";             } else {                 result.textContent = `"${input}" is not a palindrome.`;                 result.style.color = "red";             }         } else {             result.textContent = "Please enter some text.";             result.style.color = "orange";         }     }); </script> </body> </html> 

Next Article
Palindrome in JavaScript

T

tanmxcwi
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • JavaScript-Projects

Similar Reads

  • Palindrome Checker App Using React Js
    In this article, we will walk you through the process of creating a Palindrome Checker App using React.js. A palindrome refers to a word, phrase, or sequence­ of characters that reads the same­ both forwards and backward, disregarding spaces, punctuation, and capitalization. Preview Image Prerequisi
    3 min read
  • Build a Spy Number Checker using HTML CSS and JavaScript
    In the realm of mathematics, Spy Numbers, also known as secretive numbers or cryptic numbers, possess a unique property. A spy number is defined as a number whose sum of digits is equal to the product of its digits. In this article, we will explore how to build a Spy Number Checker using HTML, CSS,
    3 min read
  • Check Whether a Year is a Palindrome Year using JavaScript
    A palindrome year is a year that remains the same when its digits are reversed. For example, 2002 is a palindrome year because it reads the same backward checks whether as forward. In this problem, we're tasked with checking whether a given year is a palindrome year. Table of Content Using string ma
    2 min read
  • Build a Anagram Checker App Using ReactJS
    In this article, we will create an Anagram Checker App using React. Anagrams are­ words or phrases that can be formed by re­arranging the letters of anothe­r word or phrase, using each lette­r exactly once. This app will enable users to enter two words or phrase­s and determine if they are anagrams
    4 min read
  • Palindrome in JavaScript
    We will understand how to check whether a given value is a palindrome or not in JavaScript. A palindrome is a word, phrase, number, or any sequence that reads the same forward and backward. For instance, "madam" and "121" are palindromes. To perform this check we will use the following approaches: T
    3 min read
  • How to check the given string is palindrome using JavaScript ?
    A palindrome is a word, sentence, or even number that reads the same from the back and from the front. Therefore if we take the input, reverse the string and check if the reversed string and the original string are equal, it means the string is a palindrome, otherwise, it is not. Approach: When the
    3 min read
  • How to create a Spy Number Checker Card using JavaScript and Tailwind CSS ?
    A Spy Number is a number whose sum of digits is equal to the product of its digits. Users can input a number and the application will determine whether it's a Spy Number or not. A spy number is a number whose sum of the digits is equal to the product of its digits. For example: 1124 is a spy number
    3 min read
  • Build a Password Generator App with HTML CSS and JavaScript
    In this article, we will build a password generator application using HTML, CSS, and JavaScript. This application will generate strong and secure passwords based on user preferences, such as password length and character types. It aims to provide a convenient tool for users to generate random passwo
    3 min read
  • Add Minimum Characters at Front to Make String Palindrome in JavaScript
    The minimum characters to add at the front to make the string palindrome means the smallest count of characters required to prepend to the beginning of a given string. It ensures that the resultant string reads the same forwards and backward. This process creates a palindrome from the original strin
    5 min read
  • Create a Prime Number Finder using HTML CSS and JavaScript
    In this article, we will see how to create a Prime Number Finder using HTML, CSS, and JavaScript. The main objective of this project is to allow users to input a number and check if it is a prime number or not. Prime numbers are those, that can only be divided by 1 and themselves. We'll develop a ba
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences