Sort Text

Alphabetize and sort lines of text any way you need.

Sorting lines of text

Paste a list and sort it alphabetically, in reverse, by length, or numerically. Sorting looks simple until you meet numbers stored as text, accented characters or mixed case — each of which produces a result that is technically correct and completely unhelpful.

Alphabetical is not as obvious as it looks

A naive sort compares character codes, which puts all uppercase letters before all lowercase ones because A is 65 and a is 97. That gives:

Apple, Banana, apple, banana

rather than the case-insensitive ordering most people expect:

apple, Apple, banana, Banana

Proper alphabetical sorting uses locale-aware collation, which also places accented characters next to their base letters rather than after Z, and applies language-specific rules — in Swedish, for instance, certain accented vowels sort after Z as distinct letters rather than alongside A and O. This tool uses the browser's built-in collator, which follows Unicode collation rules rather than raw character codes.

Numbers stored as text

This is the trap that catches everyone. Sorting numbers as strings compares them character by character, so 10 comes before 9 because 1 is less than 9:

String sortNumeric sort
1, 10, 100, 2, 20, 31, 2, 3, 10, 20, 100
file1, file10, file2file1, file2, file10
v1.10, v1.2, v1.9v1.2, v1.9, v1.10

The numeric mode handles plain numbers. For mixed strings like file10, what you want is natural sort, which recognises digit runs inside text and compares them as numbers — the ordering file managers use so that chapter2 precedes chapter10.

The version-number row is a related and slightly different problem: version strings need each dot-separated component compared numerically and independently, which is why 1.10 is a later release than 1.9 despite being a smaller decimal.

The sort modes

ModeBehaviourGood for
A to ZLocale-aware alphabeticalNames, words, general lists
Z to AReverse alphabeticalNewest-first labels
NumericCompares values, not charactersFigures, IDs, quantities
By lengthShortest to longestFinding outliers, cleaning data

Sorting by length is more useful than it sounds for data cleaning — unusually short or long entries in a column of supposedly uniform values are usually the malformed ones.

Leading whitespace and blank lines

A leading space sorts before every letter, so lines that look like they belong together end up separated at the top of the output. Since whitespace is invisible, this is a confusing failure. Trim your lines before sorting if the list came from a copy and paste. Blank lines likewise cluster at the start of an ascending sort.

Sorting stability

A stable sort keeps equal elements in their original relative order. This matters when sorting the same list repeatedly on different keys: sort by surname, then by department, and a stable sort leaves each department's surnames still alphabetical. An unstable sort would scramble them. JavaScript's sort has been required to be stable since ES2019, so results here are stable and repeated sorts compose predictably.

Everything happens locally

Sorting runs in your browser with no upload. That is worth noting because sorted lists are so often personal data — names, email addresses, customer records. You can verify it in the Network tab of your developer tools. Long lists sort quickly; the browser's built-in sort runs in n log n time, so even tens of thousands of lines complete near-instantly.

Frequently asked questions

Why does 10 sort before 9?

Because a text sort compares character by character, and the character "1" comes before "9". Use the numeric mode, which compares the values rather than the characters.

Why are capitalised words separated from lowercase ones?

A raw character-code sort puts all uppercase letters before all lowercase, since A is 65 and a is 97. This tool uses locale-aware collation instead, which interleaves them the way a dictionary does.

How do I sort filenames like file2 and file10 correctly?

That needs natural sorting, which detects digit runs within text and compares them numerically. A plain alphabetical sort puts file10 before file2 because it compares "1" against "2" one character at a time.

Why did some lines end up at the top unexpectedly?

Usually leading whitespace, which sorts before every letter and is invisible. Blank lines do the same. Trim the list before sorting.

Where are accented characters placed?

Next to their unaccented base letters, following Unicode collation rules, rather than after Z as a raw character-code sort would put them. Some languages treat certain accented letters as separate letters entirely, which locale-aware collation respects.

🔗 Related tools

🔤Case Converter📄Lorem Ipsum🧹Remove Duplicate Lines🔄Reverse Text🔗Slug Generator🔢Word Counter