Sort Lines Alphabetically_
Paste a list and get it back in order. A to Z with numbers read as numbers, plain alphabetical, raw character order, by number, by length, by a column, or shuffled — ascending or descending, and nothing is deduplicated or rewritten on the way through.
The default is the one you probably meant: file2 comes before file10. Plain alphabetical does the opposite, because it compares digits as text, and that single choice is why so many sorted lists look wrong.
- Input
- Any list, one item per line. Every line-ending convention reads the same.
- Output
- The same lines in the order you asked for — nothing removed, nothing rewritten, ties left in their original order.
- Processing
- Sorted in this tab with the browser's own collator, which is the same machinery a spreadsheet uses.
- Limits
- Sorting only reorders. Removing repeats belongs to the duplicate remover; cleaning up the spacing belongs to the whitespace remover.
- Alphabetical is not one order
- file10 before file2 in plain A-to-Z. Every capital before every lowercase in raw order. Ä with A in German and after Z in Swedish. All three are correct answers to "sort this alphabetically".
Why your sorted list looks wrong
Alphabetical puts 10 before 2
Compare file2 and file10 as text and the machine looks at the first character that differs. That is 2 against 1, and 1 comes first, so file10 sorts above file2. Nothing is broken; text comparison has no idea those digits are a number. Natural order reads runs of digits as numbers before comparing them, which is why it is the default here and why it is what almost everybody actually wants.
Capitals first, or mixed in
In raw character order every capital sorts before every lowercase letter, because Z is code point 90 and a is 97. So Zebra lands above apple. That is exactly what sort does in a shell with LC_ALL=C set, and it is not what a spreadsheet does — a spreadsheet ignores case and interleaves them. Neither is wrong; they are answering different questions, and this page lets you pick which.
Alphabetical depends on the language
German files Ä under A. Swedish files it after Z, as the twenty-seventh letter. Czech treats ch as a single letter that sorts after H. Turkish has a dotless ı that is a different letter from i. So a list of names has no single alphabetical order — it has one per language, and picking the wrong one puts entries where your readers will not look for them. Change the Language control and watch the accented sample move.
Equal lines keep their place
Every sort here is stable: when two lines compare equal they stay in the order you pasted them. That is what makes sorting by two things possible without any extra feature — sort by the column you want as the tiebreaker first, then sort again by the main column, and the first ordering survives inside each group. It also means descending is not simply the list reversed: ties keep their original order rather than flipping, which is what you want and what a naive reverse gets wrong.
Paste, pick an order, take it back
- 01Paste the list, one item per line. It sorts as you type and nothing is removed — blank lines stay unless you ask otherwise.
- 02Leave the default if your items contain numbers. "A to Z, numbers in order" is the one that puts file2 before file10.
- 03Sorting names? Set the Language to match your readers. It genuinely changes where accented letters land.
- 04For a table, set Field to the column number and choose what to split on — then copy or download the result.
Four lists and the order each one needs
A folder listing
Plain alphabetical scatters the numbered files.
A to Z, numbers in order
file1, file2, file10, file20
A guest list to alphabetize
Surnames in the second column of a tab-separated table.
2, split on Tab
Hopper, Lovelace, Turing
Prices from a scraped page
Currency marks and thousands commas in the way.
By number
$9.99, $99.00, $230, $1,050
Picking a running order
A shuffle you can reproduce tomorrow.
Shuffle, seed 42
The same order every time for that seed
What each sort actually does
| Sort | Compares | Use it when |
|---|---|---|
| A to Z, numbers in order | Language rules, with digit runs read as numbers | Almost always — anything with a number in it |
| A to Z, plain | Language rules, digits as text | You want the order a spreadsheet gives with no numeric handling |
| Raw character order | Code points, nothing else | Matching what sort gives in a shell under LC_ALL=C |
| By number | The first number on each line | Prices, scores, measurements — lines with no number go last |
| By length | Characters per line, then alphabetically | Finding the outliers, or laying out a list by weight |
| Shuffle | Nothing — a seeded reorder | A random order you can reproduce by keeping the seed |
| Reverse input | Nothing — just flips the list | Undoing an order rather than imposing one |
Ascending and descending apply to all of them except Shuffle and Reverse, which have no direction to give.
The same five words in four orders
| Order | Result |
|---|---|
| A to Z, English | Apfel, Ärger, Öl, Oslo, Zoo — accents file with their base letter |
| A to Z, German | Apfel, Ärger, Öl, Oslo, Zoo — the same here, Ä with A and Ö with O |
| A to Z, Swedish | Apfel, Oslo, Zoo, Ärger, Öl — Ä and Ö are letters of their own, after Z |
| Raw character order | Apfel, Oslo, Zoo, Ärger, Öl — accents last, by code point |
English and German agree on this particular list; Swedish does not, and that is the point — the difference is real but it only shows up on the words where the rules disagree. Swedish and raw order match here by coincidence: Swedish puts those letters last deliberately, raw order does it only because their code points are high.
Getting the order you meant
- Leave the default alone unless you have a reason. Natural order is right for filenames, versions, invoice numbers and anything else with digits in it.
- To sort by two columns, sort by the secondary one first and then by the primary — every sort here is stable, so the first ordering survives inside each group.
- Set the Language when sorting names or anything a reader will scan. Where an accented letter lands is a matter of local convention, not of correctness.
- Keep the seed if a shuffle matters. The same seed reproduces the same order, which is the difference between a random draw and one you can show somebody.
- Sorting does not remove anything. If you want the repeats gone as well, the duplicate line remover does that and can sort at the same time.
- If lines refuse to sort where you expect, the culprit is usually invisible — a leading space or a no-break space. Turn on "Ignore outer space", or run the list through the whitespace remover first.
Where sorting misleads
A wrongly sorted list looks finished
This is the real hazard. An unsorted list obviously needs work; a list sorted with the wrong rule looks done and quietly hides entries where nobody will look — file10 above file2, or a surname filed under the wrong letter because the language was wrong. The panel under the output says when the choice you made visibly changes the result.
Numeric sorting reads only the first number
A line beginning with text has no number to read, so it goes to the end rather than being treated as zero — in both directions. If your numbers are in the middle of the line, sort by a field instead, or use natural order, which handles digits wherever they appear.
Descending is not the list reversed
Reversing an ascending sort also reverses the ties, which throws away the original order of equal lines. Descending here flips the comparison rather than the array, so equal lines stay as you pasted them. Use "Reverse input" when you genuinely want the list backwards.
Sorting a table by a field needs the right delimiter
A CSV whose fields contain commas inside quotes will split in the wrong places, because this splits on the character you choose and knows nothing about quoting. For real CSV, sort it in a spreadsheet or convert it first — the panel warns when lines come out with fewer fields than you asked for.
Case sensitivity changes more than you think
With it on, every capital groups before every lowercase in raw order, so "Apple, Banana, apple, banana" is the answer rather than "Apple, apple, Banana, banana". That is correct for a shell and surprising for a shopping list. It is off by default here for that reason.
Comparison, stability and fields
- Collation
- The browser’s own
Intl.Collatorfor the language-aware modes, which is the same collation machinery a spreadsheet and an operating system file listing use. Raw character order deliberately bypasses it and compares code points directly - Natural order
- The collator’s numeric option, so a run of digits anywhere in the line compares as a number. It handles versions like v1.9 against v1.10 as well as plain filenames
- Stability
- Guaranteed. Equal lines keep their input order, which makes a two-key sort possible by sorting twice, and which is why descending flips the comparison rather than the finished array
- Numeric mode
- Reads a leading number past whitespace, a currency mark and thousands commas, accepting signs, decimals and exponents. Lines with no number sort last in both directions rather than counting as zero
- Length mode
- Counts code points, not UTF-16 units, so an emoji counts as one character. Ties break alphabetically
- Shuffle
- Fisher-Yates driven by a seeded xorshift generator rather than
Math.random, so a seed reproduces an order exactly. A shuffle you cannot reproduce is one you cannot check - Fields
- Splits each line on the chosen delimiter and compares one part. A line with fewer parts sorts as empty, and the panel says how many did
- Scope
- Reordering only. Removing repeats is the duplicate line remover, and cleaning the spacing that stops lines matching is the whitespace remover
- Network
- None from tool code. A test sweep calls every function this page uses with
fetchandXMLHttpRequestreplaced by stubs that throw, so a stray request fails the build instead of shipping. Disconnect from the network and the page still works.
Questions about alphabetizing and sorting
How do I alphabetize a list?
Paste it above. It alphabetizes as you type, ignoring case, with numbers read as numbers so file2 comes before file10. Then copy or download the result. Nothing is removed or rewritten — the same lines come back in a different order.
Why is file10 sorting before file2?
Because plain alphabetical compares digits as text, and the first character that differs is 1 against 2. Text comparison has no idea those digits form a number. Choose "A to Z, numbers in order", which is the default here — it reads runs of digits as numbers before comparing them.
Why are capital letters sorting separately?
That happens in raw character order, where every capital comes before every lowercase because Z is code point 90 and a is 97. It is what a shell gives you with LC_ALL=C. Turn off Case sensitive, or use one of the A-to-Z modes, and capitals interleave the way a spreadsheet sorts them.
Does alphabetical order change between languages?
Yes, and it is not a rounding detail. German files Ä under A; Swedish files it after Z as a separate letter; Czech treats ch as one letter sorting after H; Turkish has a dotless ı distinct from i. Set the Language control to match your readers, or entries end up where nobody looks for them.
Can I sort by the second column?
Set Field to 2 and pick what the columns are split on — tab, whitespace, comma, semicolon or pipe. To sort by two columns, sort by the secondary one first and then by the primary; every sort here is stable, so the first ordering survives inside each group.
Will it remove duplicates too?
No, deliberately — sorting reorders and nothing else, so the list you get back has exactly the lines you pasted. The duplicate line remover handles repeats and can sort at the same time, and it also explains why two identical-looking lines sometimes refuse to match.
Is my list uploaded anywhere?
The work is JavaScript running in this tab. Every function it calls is covered by a test that stubs fetch and XMLHttpRequest to throw, so a request that slipped in would break the build rather than reach a server — and you can confirm it for yourself by disconnecting and carrying on.