Letter Sorter

Sorts the letters within each individual word alphabetically (so 'hello' becomes 'ehllo'), leaving word order, spaces, and punctuation exactly in place. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-23

Overview

Introduction

Sorting the letters inside each word alphabetically is a fun way to preview an anagram-style transformation, generate puzzle text, or check letter composition at a glance.

This tool applies the sort to every word in a passage at once.

What Is Letter Sorter?

A letter sorter that alphabetizes the letters within every contiguous run of letters in the text, leaving word order and any non-letter characters exactly in place.

It runs entirely client-side as part of this site's String Tools collection, so nothing you paste is ever uploaded to a server.

How Letter Sorter Works

The input is tokenized into alternating runs of letters and non-letters; each letter run has its characters sorted with localeCompare(), while non-letter runs (spaces, digits, punctuation) pass through unchanged, and everything is rejoined in its original order.

The transformation happens synchronously in JavaScript the moment you type, with no network round trip involved.

When To Use Letter Sorter

Use it to generate anagram-style puzzle text, or to quickly see the sorted letter composition of every word in a passage.

It's a fast way to get the answer without opening a code editor, a REPL, or writing a one-off script just to check.

Often used alongside Text Sorter and Letter Randomizer.

Features

Advantages

  • Preserves word boundaries and punctuation exactly, only touching the letters themselves.
  • Works across an entire passage at once, not just a single word.
  • Sorts with localeCompare rather than raw code point order, so uppercase and lowercase letters interleave alphabetically instead of all the capitals sorting first.

Limitations

  • Treats each contiguous run of letters as one unit, so a word with an embedded apostrophe (like "don't") is sorted as two separate letter runs rather than one.
  • Sorts only within each letter run, so it cannot alphabetize the words themselves or the passage as a whole.

Examples

Sorting the letters of a word

Input

hello world

Output

ehllo dlorw

Each word's letters are sorted alphabetically while the space between them stays put.

Best Practices & Notes

Best Practices

  • Use Letter Randomizer instead if you want a shuffled, unpredictable letter order rather than a sorted one.
  • Use it to test two words for anagram equivalence: sort both and check whether the results come out identical.
  • Strip apostrophes and hyphens first when you want a contraction treated as one word rather than as two separate letter runs.

Developer Notes

Tokenization uses `input.match(/[A-Za-z]+|[^A-Za-z]+/g)`; each letter-only token is split into characters, sorted with `(a, b) => a.localeCompare(b)`, and rejoined, while non-letter tokens pass through unmodified.

Letter Sorter Use Cases

  • Generating anagram-style puzzle text
  • Previewing the sorted letter composition of words for word games
  • Creating a novelty transformation of a passage

Common Mistakes

  • Expecting apostrophes or hyphens inside a word to be treated as part of the same letter run; they act as separators.
  • Expecting the words themselves to be reordered; only the letters inside each word move, never the words.

Tips

  • Pair with Letter Randomizer to compare a sorted vs. shuffled version of the same text.
  • Sorting is idempotent, so running it a second time produces the same result and confirms the first pass completed properly.

References

Frequently Asked Questions