Text Sorter
Sort lines A–Z, by length, reverse or shuffle.
100% private — runs in your browser, nothing is uploaded.
How to use the Text Sorter
- 1Paste your lines
Add your lines, one item per row.
- 2Pick a sort order
Sort A–Z, Z–A, by shortest or longest, reverse the order, or shuffle randomly.
- 3Copy the result
Copy the reordered lines with one click.
Examples
| Input | Output |
|---|---|
banana
apple
cherry | apple
banana
cherry |
one
two
three | three
two
one |
Free online text sorter
This line sorter arranges lines of text alphabetically (A–Z or Z–A), by length, in reverse, or in random (shuffled) order. It is handy for organising lists, names, keywords, CSV columns and any line-based data.
Sorting options
- A → Z / Z → A — alphabetical order.
- Shortest / Longest first — by line length.
- Reverse — flip the current order.
- Shuffle — randomise the lines.
How alphabetical sorting works
Sorting a list alphabetically sounds like the least interesting task in computing. Then you sort your files and find file10 sitting between file1 and file2, or all the capitalised names clumped above the lowercase ones, and it stops being obvious. The computer is not broken — it is doing exactly what it was told. This guide explains what “alphabetical” actually means to a machine, and how to get the order you meant.
How computers really compare text
A computer does not know the alphabet. It knows numbers.
Every character has a numeric code — A is 65, B is 66, a is 97, 0 is 48. To sort, the computer compares these codes, character by character, left to right. The first position where two strings differ decides the order. If one string runs out first, it sorts earlier.
For plain lowercase English words this produces exactly what you expect. Everything else in this article is a consequence of it producing something you did not expect.
Why 10 comes before 2
The single most common sorting complaint. You sort a list and get:
item1, item10, item11, item2, item20, item3
This looks like a bug. It is not. Remember: the comparison is character by character, and it does not know that 10 is a number. It compares item1 against item2 one character at a time, reaches the fourth character, and finds 1 versus 2. Since 1 sorts before 2, everything starting with item1 — including item10 and item19 — comes before anything starting with item2.
The computer is treating 10 as the characters one then zero, not as the value ten. Which is precisely what alphabetical sorting means.
There are two ways to get the order you actually wanted:
- Natural sort. A smarter algorithm that recognises runs of digits and compares them as numbers. This gives
item1, item2, item3, item10, item20. It is what file managers use, and it is what humans mean by “in order.” - Zero-pad your names. Rename to
item01, item02, item10. Now plain alphabetical sorting gives the right answer, because all the numbers are the same width. This is the trick to use when you control the naming — and it is why professionals name filesscan001.pdfrather thanscan1.pdf.
The zero-padding habit is worth adopting permanently. It makes every tool you ever use — sorting, merging, batch processing — behave correctly with no special handling.
Why capitals sort first
Sort apple, Banana, cherry and a naive sort returns Banana, apple, cherry. The capital jumped to the front.
The reason is in the character codes: all uppercase letters (65–90) come before all lowercase letters (97–122). So Z (90) sorts before a (97). Every capitalised word outranks every lowercase one, regardless of the actual letters.
This is case-sensitive sorting, and it is almost never what you want for a list of names or words. The fix is a case-insensitive sort, which compares as if everything were lowercase and gives you apple, Banana, cherry.
Keep case-sensitive sorting for code, identifiers and anything where ABC and abc are genuinely different values.
Accented and non-English letters
Accented characters have high numeric codes, so a naive sort exiles them to the end of the list — after z. That gives you apple, zebra, éclair, which no human would accept.
Proper sorting uses a locale-aware collation, which knows that é belongs with e. And the correct order genuinely differs by language, which is a lovely illustration of why this is harder than it looks:
- In Swedish,
äandöcome afterz— they are distinct letters at the end of the alphabet. - In German,
äis sorted as if it werea.
Same character, different correct answer, depending on who is reading. There is no universal alphabetical order.
Other sorting orders worth knowing
- Reverse alphabetical (Z–A) — for finding the end of a list quickly.
- By length — surprisingly useful for keyword lists, since short keywords tend to be high-competition head terms and long ones are long-tail.
- Numerically — treating each line as a number rather than text.
- Randomly (shuffle) — for drawing names or randomising an order.
- Reverse the current order — no sorting, just flipping what you have.
Stable sorting
A worthwhile piece of jargon. A sort is stable if items that compare equal keep their original relative order. If two lines are identical, a stable sort leaves the one that was first still first.
It matters when you sort by one field and then another: sorting by surname, then by department, a stable sort leaves each department's people still in surname order. An unstable sort scrambles them, and you have to start over.
Clean before you sort
Sorting exposes messy data rather than fixing it. Trailing whitespace, in particular, quietly ruins the result — a leading space has a very low character code, so a line beginning with a space jumps to the top of the list for no visible reason.
So: trim the whitespace, remove the empty lines, and deduplicate before sorting. The output will make far more sense.
Next steps
Clean up duplicates first with Remove Duplicate Lines, or compare two sorted lists with the Text Diff Checker.
Frequently Asked Questions
How do I sort a list of lines?
Paste your lines (one per row) and click A → Z or Z → A. You can also sort by length, reverse the order, or shuffle the lines randomly.
Does it change my text?
It only reorders whole lines — the content of each line stays the same. Everything runs in your browser.
Is the sorting case-sensitive?
Sorting uses your browser's locale comparison, which generally groups upper and lower case together in a natural order rather than putting all capitals first.
Can I randomise a list?
Yes. Click Shuffle to put the lines in a random order — handy for picking a random winner or randomising quiz questions.
Why does alphabetical sorting put 10 before 2?
Plain text sorting compares character by character from left to right, so '1' comes before '2'. Zero-pad numbers (01, 02, 10) or use a numeric/natural sort when sorting numbered names.
Why is a blank-looking line sorted to the very top?
It almost certainly begins with a leading space, which has a lower character code than letters. Trim leading whitespace or remove blank lines before sorting.
Can I sort by the second word in each line?
A line sorter sorts from the first character of each line. To sort by a second column or last name, swap or isolate that column first.