Text Tools

Sort Lines Alphabetically

Sort any list of lines alphabetically, A–Z or Z–A.

Rate this tool

How to use the Sort Lines Alphabetically

  1. Paste your list, one item per line.
  2. Choose A–Z or Z–A.
  3. Copy the sorted result.

About the Sort Lines Alphabetically

Sorting here is alphabetical, not numeric, and that distinction catches more people than anything else. Lines are compared as text, character by character, so “10” lands before “9”: the comparison reaches 1 against 9, sees that 1 is lower, and stops. A list of 1 to 20 comes back as 1, 10, 11 … 19, 2, 20, 3. No text sorter can guess otherwise, because “10” is a string, not a number. The fix is to pad your numbers to equal width — 01, 02, 09, 10 — after which alphabetical order and numeric order are the same thing.

Comparison is locale-aware rather than a raw code-point sort, so it behaves the way a person expects rather than the way a naive computer sort does. Accented letters file next to their base letter: “résumé” sorts right after “resume” instead of being exiled past “z”. Case does not dominate either, so “apple” and “Apple” come out adjacent rather than in separate uppercase and lowercase blocks — a raw sort would put every capitalised word ahead of every lowercase one.

Z→A simply reverses the sorted list. Leading whitespace is part of the line and sorts ahead of letters, so indented and blank lines cluster at the top; trim them with the extra spaces remover if that is not what you want. Sorting also brings duplicates next to each other, which pairs naturally with the duplicate line remover. It all runs in your browser.

Frequently asked questions

Why does 10 come before 9?

Because the sort is alphabetical, not numeric. Lines are compared character by character as text, and the character "1" comes before "9". Pad your numbers to the same width (01, 02, 09, 10) and alphabetical order will match numeric order.

Is the sort case-sensitive?

It uses locale-aware comparison, so case does not split the list into separate blocks — "apple" and "Apple" end up next to each other rather than in two groups. This is different from a raw computer sort, which would place all capitalised words before all lowercase ones.

Where do accented words end up?

Next to their unaccented equivalent. "résumé" sorts immediately after "resume", not at the end of the list. A naive sort based on character codes would push every accented word past z.

Why are some lines at the top before the letters?

Blank lines and lines starting with a space or tab sort ahead of lines starting with a letter, because the leading whitespace is part of the line. Trim the lines first if you want them sorted by their visible content.

Does it remove duplicates while sorting?

No. Every line you put in comes back out, just reordered. Sorting does place duplicates next to each other, which makes them easy to spot — run the duplicate line remover if you want them gone.