What counts

A palindrome reads identically forwards and backwards. The interesting question is what you ignore before comparing. Standard practice discards case, spaces and punctuation, which is why these all pass:

TextNormalisedPalindrome
racecarracecarYes
A man, a plan, a canal: PanamaamanaplanacanalpanamaYes
Was it a car or a cat I saw?wasitacaroracatisawYes
Never odd or evenneveroddorevenYes
Step on no petssteponnopetsYes
Almost a palindromealmostapalindromeNo

The algorithm

Reversing the string and comparing works, but the efficient version walks two pointers inward from both ends and stops at the first mismatch:

i = 0, j = length − 1; while i < j: if s[i] ≠ s[j] return false; i++, j−−

This does at most n/2 comparisons and exits early on most non-palindromes, whereas reversal always allocates a whole second string first. For a 21-character phrase the difference is irrelevant; for a megabyte of text it is not.

The Unicode problem

This is where almost every implementation quietly breaks, and it is worth knowing even if you never write the code.

Text in JavaScript and many other environments is stored as UTF-16 code units, not characters. Anything outside the basic range — emoji, many CJK extension characters, mathematical symbols — occupies two code units called a surrogate pair. Reverse the string naively and you reverse the halves of that pair, producing an invalid sequence that renders as a replacement box. So a string containing an emoji can fail a palindrome test that it should pass, or emerge corrupted.

Accents add a second layer. The letter é can be a single code point, or the letter e followed by a separate combining acute accent. Those two representations look identical on screen and compare as unequal. Reversing the second form moves the accent onto the wrong letter entirely. The fix is Unicode normalisation — canonically composing the text first — before any comparison.

Then there are grapheme clusters: a family emoji or a flag is several code points joined by invisible connectors, and even correct code-point handling splits them apart. A fully correct checker segments by grapheme cluster, which most do not.

Beyond letters

Numeric palindromes ignore all of this: 12321, 7, 1001. There are 9 single-digit, 9 two-digit and 90 three-digit palindromes. A curious fact — every palindrome with an even number of digits is divisible by 11.

Palindromic dates depend on the format, which makes most claimed ones parochial. But 2 February 2020 is genuinely palindromic in every common ordering: 02/02/2020, 2020-02-02, and 20200202. The previous date to manage that was in the eleventh century.

Word-level palindromes reverse word order rather than letters, as in the sentence you can build where each word mirrors its counterpart. Semordnilaps — the word semordnilap is itself palindromes reversed — spell a different valid word backwards: stressed and desserts, stop and pots, diaper and repaid. Those are not palindromes and a checker will correctly reject them.

Honest limits

The checker applies one normalisation policy. Whether to strip digits, whether to treat ß as ss, whether the Turkish dotless i should match a plain i, and how to handle right-to-left scripts are all defensible choices with no single correct answer. For most uses the standard letters-only, case-insensitive policy is what people expect, but if you are checking text in a language with heavy diacritics, verify the result rather than trusting it.

Questions people actually ask

Is a single letter a palindrome?

Yes, trivially, as is the empty string. Both read the same in either direction.

What is the longest known palindrome?

Constructed palindromic texts run to tens of thousands of words, but they are exercises rather than readable prose. The longest commonly cited single palindromic word in English is a nineteen-letter chemical term; among ordinary words, level, rotator and redivider are the practical champions.

Why did my emoji palindrome fail?

Almost certainly surrogate-pair or grapheme-cluster splitting, as described above. It is a genuine limitation of naive string reversal rather than a judgement about your text.

Is the text I check stored?

No. Everything you paste is processed in your browser and nothing is transmitted or logged.

Keep exploring Gen Code Tools

Every tool comes with a written guide, and every category is one click away.