This tool reverses text in your browser; nothing leaves your machine. The interesting question is what “reverse” means — three different operations all called “reverse” can produce very different results.
Three kinds of reversal
| Mode | Input → Output |
|---|---|
| Character reverse | "Hello" → "olleH" |
| Word reverse | "Hello world" → "world Hello" |
| Line reverse | "line 1\nline 2\nline 3" → "line 3\nline 2\nline 1" |
The tool above does character reverse two ways — Whole text, or Per line (each line reversed in place) — plus word reverse and sentence reverse. For line reverse (flipping the order of lines), use the Reverse order option in sort lines.
Character reverse and Unicode
For ASCII (and any Latin-script characters that fit in one Unicode code point), character reverse is straightforward:
"Hello, world!" → "!dlrow ,olleH"
But naive character reverse breaks for combining characters and astral-plane Unicode:
"café" → "éfac" or "éfac"?
"👨👩👧" → ??? (family emoji is multiple code points joined by ZWJ)
"🇺🇸" → flipped letters making no sense
Three tiers of “what counts as a character”:
- UTF-16 code units. JavaScript’s default;
string.lengthcounts these. A reversed surrogate pair becomes two invalid code units, producing garbage. - Code points. Combining surrogate pairs into single units before reversing.
"café"(4 code points) reverses cleanly. - Grapheme clusters. What a human perceives as one character.
"👨👩👧"is one cluster; reversing keeps it intact."é"written as"e" + combining-acute(two code points) reverses to"acute-combining + e", which renders weirdly — grapheme reverse keeps theéintact.
The tool above reverses grapheme clusters (via Intl.Segmenter), so flags, emoji sequences and accented letters survive the trip.
Word reverse
"The quick brown fox" → "fox brown quick The"
Splits on whitespace, reverses the resulting list of words, joins with spaces. The trap:
- Multiple spaces.
"hello world"reverses to"world hello"if you preserve spacing, or"world hello"if you normalize. - Tabs and newlines. Are they word separators? Usually yes for whitespace-aware split.
- Punctuation attached to words.
"Hello, world."— does the period stay withworld? Most tools treat punctuation as part of the adjacent word.
The tool above splits on whitespace runs and keeps each run as it was, so double spaces and line breaks stay between the same words.
Line reverse
Reverses the order of lines:
Input:
First line
Second line
Third line
Output:
Third line
Second line
First line
The line content is unchanged. Useful for:
- Reading log files in chronological order when the file is appended-to (latest at bottom).
- Reversing a list that’s already line-separated.
- Inverting any operation that produces output in reverse-chronological order.
Equivalent to Unix tac or tail -r (or awk '{a[NR]=$0} END {for(i=NR;i>=1;i--) print a[i]}').
When character reverse is useful
Honestly, almost never as a serious operation. Character reverse is mostly:
- Toy / educational. Showing how strings work.
- Puzzle solving. CTF challenges, brain teasers.
- Debugging text rendering. Verifying a renderer handles RTL or bidirectional text.
- Generating mirror-image text for design (with appropriate font support).
Real systems rarely need to reverse strings. If you find yourself reaching for character reverse in a serious context, double-check the actual requirement.
When word reverse is useful
- Some natural-language processing tasks. Last-word-first analysis.
- Generating Yoda-speak for fun.
Mostly novelty.
When line reverse is useful
This one’s actually useful:
- Log file inspection.
tail -r logfile.logshows newest entries first. - Reversing sorted output. Sometimes a
sortthentacis faster thansort -r. - Building palindrome-like structures.
Common pitfalls
- Surrogate pair corruption. Naive character reverse on a string with emoji or astral-plane characters produces invalid UTF-16. Use code-point or grapheme-cluster reverse.
- Combining-character ordering. A string with
e+ combining-acute reversed character-by-character has the combining mark before the base — visually wrong. - Right-to-left scripts. Hebrew and Arabic are stored in logical order (first character first); the rendering reverses for display. Reversing the storage produces something that displays in left-to-right order — opposite of what you’d expect.
- CRLF vs LF in line reverse. A file with mixed line endings might produce odd results. Normalize first.
- Empty string. Reverse of empty is empty; the tool should not crash.
- Whitespace-only input. Word reverse of a whitespace-only string yields empty (no words). Some tools return the original instead.
For other text manipulation, see text case, sort lines, find & replace.