Natural sort: why item10 keeps landing before item2
Alphabetical sorting compares one character at a time. item10 and item2 match for four characters, then 1 loses to 2, so item10 lands first. Every file list, version number and numbered chapter hits this.
Natural sort reads a run of digits as one number, so 10 compares against 2 as numbers. Windows Explorer and the macOS Finder do this, which is why a folder listing looks right and a sorted text file does not. Use it for file names, version strings like v1.9.0 and v1.10.0, and invoice numbers.
Why a plain comparison sorts your list wrong
JavaScript's array.sort() with no comparator compares UTF-16 code units, not letters. Every capital sorts before every lowercase, so Zebra beats apple, and every accented letter sorts after z, so ä lands past zulu. Both are wrong in every human language.
This tool uses Intl.Collator, which implements the Unicode Collation Algorithm against CLDR per-language data, because there is no single correct answer. German sorts ö with o; Swedish puts it at the end of the alphabet; Czech treats ch as one letter between h and i; Turkish has a dotted and a dotless i. Case is a tiebreaker only, never a fallback to code-unit order: apple stays before Zebra either way.
Numeric sort and shuffle
Numeric reads the number at the start of each line, sign, decimal point and exponent notation included; anything after it rides along. A decimal comma is not read as a decimal point, since 1,5 is one and a half in Dutch and one thousand five hundred in English. Lines with no leading number collect at the end in the order you wrote them, in both directions, which is what a totals row wants.
Shuffle uses Fisher-Yates, so every order is equally likely. The one-liner people reach for, sort(() => Math.random() - 0.5), hands the sort an inconsistent comparator and leaves the result biased toward the original order. If you are picking a winner or assigning a running order, that bias is the problem.
Common problems
- A line is off by one position. Look for a leading space: a character that sorts before every letter and is invisible. Lines are not trimmed here, since a tool that claims to reorder should not also edit.
- The sort looks wrong for your language. The Language control defaults to the language this page is in, not the language your list is in.
Frequently asked questions
Does sorting remove duplicate lines?
No. Lines in matches lines out. Removing duplicates is a separate tool, linked below.
Can it sort a numbered or bulleted list?
An existing 1. or - prefix takes part in the comparison and holds the old order in place. Strip the numbers with the line numbering tool, sort, then number again.
Are the line endings preserved?
They are never part of what is compared, and a file that is all LF or all CRLF comes back the same way. A file that mixes the two comes back all CRLF, because a line that has moved no longer belongs to the ending it arrived with. Mode, direction, case sensitivity and language go in the URL; the text does not.
Why does my list sort differently here than in a spreadsheet?
Almost always the locale. A plain code-point sort puts every capital before every lowercase letter and files accented letters after z, while a locale-aware comparison puts them where a reader of that language expects. This page uses Intl.Collator, which is why a sorts next to a with an accent.