Reverse Text the Right Way: Five Ways to Flip a String
A practical guide to reverse text by character, word, line, or letters-in-place, plus upside-down flips — with one input run through all four modes and the Unicode trap to avoid.
Reverse Text the Right Way: Five Ways to Flip a String
"Reverse the text" sounds like one operation. It is actually five, and people reach for the wrong one constantly. Someone wants to flip a sentence's word order and ends up with every letter mirrored. Someone copies a one-line JavaScript snippet off Stack Overflow, runs it on a string with an emoji, and gets a row of broken squares. This guide walks through all five ways to reverse text, when each one is what you actually want, and the single Unicode mistake that breaks more reversal code than anything else.
I write puzzle clues for a small escape-room project, and I have made every one of these errors at least once. Below is the mental model I wish I had started with.
The five reversal modes, and what each is for
There are five distinct transforms hiding under the phrase "reverse text":
- By character — flip the entire string from the last character to the first. This is the true mirror. "hello" becomes "olleh". Use it for puzzle clues read in a mirror, for mirror-writing effects, or for testing.
- By word — keep each word spelled normally, but reverse the order of the words. "The cat sat" becomes "sat cat The". Use it to reorder a sentence's clauses without retyping.
- By line — keep each line intact, but flip the top-to-bottom order. Handy for a list pasted bottom-to-top, or a changelog you want oldest-first.
- Reverse each word in place — keep the word order, but flip the letters inside every word. "The cat sat" becomes "ehT tac tas". This is the one people confuse with "by word".
- Upside down — map each letter to a flipped Unicode lookalike and reverse the order, so the line reads correctly when rotated 180 degrees. "hello" becomes "ollǝɥ". This is the one you paste into a bio.
The reverse text generator runs all five and updates live as you type, so you can switch modes and immediately see which one matches what you pictured.
One sentence, four reversals side by side
Abstract definitions blur together, so here is a single input run through the first four modes. Input:
The quick brown fox
| Mode | Output | |------|--------| | By character | xof nworb kciuq ehT | | By word | fox brown quick The | | By line (single line) | The quick brown fox | | Reverse each word | ehT kciuq nworb xof |
Two things jump out. First, "by character" and "reverse each word" look similar at a glance but are not the same — by-character moves the words too, reverse-each-word does not. Second, line reversal does nothing to a single line; it only matters once you have multiple lines, where it flips their order without touching the words inside. Knowing which column you want before you start saves you the "that looks almost right but wrong" moment.
The Unicode trap that breaks naive reversals
Here is the bug that catches almost everyone. The classic one-liner is str.split('').reverse().join(''). It works fine on plain ASCII and fails the moment you feed it an emoji or certain accented characters.
The reason is encoding. JavaScript strings are sequences of UTF-16 code units, and any character outside the Basic Multilingual Plane — which includes most emoji — is stored as a surrogate pair: two code units that only mean something together. The Unicode standard reserves the range U+D800 to U+DFFF for these halves (per the Unicode surrogate-pair specification). When split('') cuts the string into individual code units, it slices a single emoji into two orphaned surrogates. Reverse them and they no longer form a valid pair, so the browser renders replacement squares.
Try it: reverse a😀b the naive way and you get garbage where the face was. The fix is to split on code points instead of code units. Array.from(str) and the spread operator [...str] both iterate by code point, so Array.from("a😀b").reverse().join('') correctly yields b😀a with the smiley intact. Combining accent marks and CJK characters survive the same way. This tool reverses by code point internally, which is why its output never shatters an emoji — and if you write your own reversal, copy that one habit and you are safe.
Real uses: puzzles, profiles, and string testing
These modes earn their keep in three places I keep coming back to.
Puzzles and games. For an escape-room card I want players to hold up to a mirror, I type the clue, switch to by-character, and print the result. Because the reversal is code-point safe, I can drop an emoji marker or an accented name into the clue and it stays whole when flipped.
Social profiles. Upside-down text makes a username or bio stand out in a comment thread. The output is real Unicode text, not an image, so it pastes anywhere that accepts Unicode and still works in search and mentions.
String testing. Developers reverse a mixed string of Chinese, Arabic, emoji, and Latin to check that a UI does not silently assume left-to-right Latin text. One caveat worth knowing: reversing right-to-left text like Arabic changes the logical character order, but the browser still applies bidirectional layout, so the on-screen direction may look unchanged even though the code points are correctly reversed. That surprise is itself a useful test of whether your rendering pipeline is bidi-aware.
Pairing reversal with other text cleanup
Reversal is often one step in a larger text edit. If a reversed result has the wrong capitalization — say you flipped an ALL-CAPS heading and now want title case — run it through the case converter afterward. And if you reversed line order to reorganize a list, the word counter gives you a quick character, word, and line tally before you paste it back into a document. None of these tools upload your text; every transform is plain JavaScript in your own tab.
So the next time someone says "just reverse it," ask which reverse. Pick by-character for a true mirror, by-word to reorder a sentence, by-line to flip a list, reverse-each-word for the in-place letter flip, and upside-down for the social trick — and split on code points so your emoji come out the other side in one piece.
Made by Toolora · Updated 2026-06-13