How to use this Text Reverser
Paste or type your text into the input box, choose the type of reversal you want, and get
the transformed output instantly. You can then copy the result for your workflow.
- Enter text into the input box.
- Choose Reverse Characters, Reverse Words, or Reverse Lines.
- Review the output in the result box.
- Copy the transformed output if needed.
Example reversal
Input: hello world
Characters: dlrow olleh
Words: world hello
Common use cases
- String experiments
- Puzzles and games
- Formatting checks
- Text-processing practice
- Quick browser-based transformations
Reversing a string is where Unicode gets brutal
"Reverse the characters" sounds like the simplest possible string operation, and for
plain ASCII it is. It is also the single most common way developers discover that a
JavaScript "character" is not what they think. The snippet everyone reaches for —
str.split('').reverse().join('') — is broken for anything outside
ASCII, because split('') splits on UTF-16 code units, not
on characters.
An emoji like 😀 lives above U+FFFF, so JavaScript stores it as
a surrogate pair: two 16-bit code units, a high one followed by a low one.
Reversing by code units swaps them into an invalid low-then-high order, producing lone
surrogates that render as the replacement character �. Reverse
"a😀b" that way and you don't get "b😀a" — you get a broken
emoji in the middle. This page is a hands-on demonstration of that distinction; its
character reversal deliberately avoids the split('') bug, as the next section
explains.
Code unit vs code point vs grapheme cluster
There is a ladder of correctness, and each rung fixes a different class of bug:
- Code units —
str.split(''). Splits surrogate pairs and
corrupts every astral character. Never use it to reverse text.
- Code points —
[...str].reverse().join('') or
Array.from(str). The spread and Array.from iterate by code
point, so surrogate-pair emoji stay intact. This is what this tool's
Reverse Characters uses, which is why a plain 😀
survives here. It still splits combining marks off their base letter, though.
- Grapheme clusters —
Intl.Segmenter with
granularity: 'grapheme'. Collect the grapheme segments, reverse
that array, then join. This is the only fully correct reversal: it keeps
accented letters, emoji with skin-tone modifiers, flag emoji, and joined sequences
whole.
Why an accent jumps onto the wrong letter
Even code-point reversal — the correct-looking middle rung — mangles combining marks. A
letter such as é can be stored in decomposed (NFD) form as two code points:
a base e followed by U+0301, a combining acute accent that
renders on top of whatever precedes it.
Reverse by code point and the order becomes accent-then-e, so the combining
mark re-attaches to the previous character instead of its own. Reverse a
decomposed café and the accent can end up floating over the wrong letter, or
over a space. The base letter and its marks have to move together as one unit — which is
exactly what a grapheme cluster is, and exactly what code-point reversal fails to respect.
Why a family emoji splits into separate people
Some emoji are built from several other emoji glued together. A family like
👨👩👧 is actually multiple person code points joined by
zero-width joiners (U+200D). Reverse it by code point and
the joiners land in the wrong places, so the single family shatters into separate people
in reversed order — the ZWJ sequence is destroyed.
Flag emoji have the same shape of problem: each flag is a pair of regional-indicator code
points, and reversing them either swaps the pair into a different country or breaks it
entirely. Only grapheme-cluster reversal via Intl.Segmenter keeps ZWJ
sequences and flags whole, because it treats each complete cluster as one indivisible
character.
Reversing characters is not reversing word order
These two operations get conflated, but they are different and produce different output.
Character reversal flips the entire sequence, so
hello world becomes dlrow olleh. Word-order
reversal keeps each word readable and only flips their sequence, so
hello world becomes world hello.
This tool offers both, plus line-order reversal, which flips the order of lines while
preserving each line's own text — handy for inverting a chronological log or a stacked
list. Pick the one that matches the structure you actually want to change: characters
within a string, words within a sentence, or lines within a block.
Frequently Asked Questions
Why does reversing text scramble my emoji?
Because the common one-liner str.split('').reverse().join('') splits on
UTF-16 code units, not characters. An emoji above U+FFFF is stored as
two code units (a surrogate pair), and reversing them puts the pair in an invalid
order, so it renders as �. Iterate by code point or grapheme cluster
instead.
Does [...str].reverse() fix it?
Partly. The spread operator iterates by code point, so surrogate-pair emoji stay
intact — this is what fixes the basic 😀 case. But it still splits
combining accent marks off their letters and breaks zero-width-joiner sequences like
family emoji, so it is not fully correct.
How do I reverse text 100% correctly?
Segment by grapheme cluster with Intl.Segmenter using
granularity: 'grapheme', collect the segments into an array, reverse that
array, and join it. Only this treats accented letters, emoji with modifiers, flags,
and ZWJ sequences as single units.
Why did an accent jump to the wrong letter after reversing?
Because the text held a combining mark. In decomposed (NFD) form, é is a
base e plus a separate combining accent that attaches to whatever
precedes it. Reversing at the code-point level moves the accent ahead of its letter,
so it lands on the wrong character.
Why did a family emoji split into separate people?
A family emoji is several person code points joined by zero-width joiners
(U+200D). Reversing by code point scatters the joiners, so the single
glyph breaks into individual people in reversed order. Grapheme-cluster reversal keeps
the joined sequence whole.
Is reversing characters the same as reversing word order?
No. Character reversal flips the whole sequence
(hello world → dlrow olleh), while word-order reversal
keeps each word readable and only flips their sequence
(hello world → world hello). This tool provides both, plus
line-order reversal.