Home/Text tools/Reverse text

Text tool

Reverse Text

Reverses the whole string, the order of the words, or the letters inside each word — built to keep emoji and accented characters intact where a naive character-reverse would corrupt them.

Result

café 🇬🇧 world olleH

Why split('').reverse().join('') is broken

The obvious one-liner for reversing a string in JavaScript treats a string as an array of 16-bit code units (UTF-16). That works for plain ASCII, but plenty of real characters are made of more than one code unit, or are meant to attach to the character before them — reversing those independently scrambles them.

The naive method versus what actually happens
Inputsplit('').reverse().join('')What went wrong
🇬🇧 (UK flag)🇧🇬 (a different flag — Bulgaria)A flag emoji is two "regional indicator" code points; reversing them individually swaps which country it represents
👨‍👩‍👧 (family emoji)broken glyphs, often three separate emojiThe family is three person emoji joined by invisible zero-width-joiner characters; reversing separates them and reverses the joiners' position too
é (as e + ◌́ combining accent)the accent mark detaches and appears before the eSome é characters are two code points — a plain "e" and a separate combining accent mark that must stay immediately after its base letter

Try the UK flag in a naive reverser and you can end up with the flag of a different country entirely, because 🇬🇧 is stored as two separate "regional indicator" code points (G and B) that only combine into a flag when adjacent and in the right order. Reverse them independently and you get 🇧🇬 — Bulgaria.

What this tool does instead

Word and string reversal here use Intl.Segmenter, a browser API built specifically to split text into the units a human actually perceives as "one character" — called grapheme clusters — rather than raw code units. A flag emoji, a family emoji, and a letter with a combining accent each count as one cluster and get moved as a single, unsplit block. On the rare older browser without Intl.Segmenter, this tool falls back to reversing by Unicode code point (Array.from(text)) rather than UTF-16 code unit, which still fixes ordinary accented letters and most single emoji, just not multi-part ones like flags and family groups.

Questions people ask

Does "reverse word order" also reverse the letters inside each word?

No. That mode only changes which word comes first — "the quick fox" becomes "fox quick the", with each word left completely intact. Use "reverse each word in place" if you want the letters inside every word flipped while the word order stays the same.

What counts as a "word" for word-order reversal?

Runs of non-whitespace characters separated by whitespace. Punctuation attached to a word, like a trailing comma, travels with that word rather than being treated as its own token.

Will this break right-to-left text, like Arabic or Hebrew?

The reversal itself works correctly at the character level, but be aware that reversing right-to-left text produces a string that may display in a visually confusing order due to how browsers apply bidirectional text rendering on top of the reversed character sequence — the underlying text is reversed correctly even if the display looks unexpected.

Is my text uploaded anywhere?

No. Everything happens in this browser tab, with no server call and nothing stored once you leave the page.

Playing with text for somewhere else?

Case conversion, word counting and diffing sit right next door.

See all text tools →