Skip to content
Processing locally — files never leave your device

Sort Lines Alphabetically or Numerically Online

Sort lines of text alphabetically, in reverse, numerically, or by line length. Optionally trim whitespace and drop empty lines.

How to use Sort Lines

  1. Paste your list with one item per line — names, tasks, numbers, file paths, or any values.
  2. Leave "Trim whitespace" and "Drop empty lines" on to clean the list before sorting (recommended for most lists).
  3. Pick a sort: A → Z or Z → A for text, Numeric for figures, By length for shortest-to-longest, or Reverse to flip the current order.
  4. Read the sorted result in the output box and adjust the toggles if blank lines or stray spaces affected the order.
  5. Click Copy to grab the sorted list. The ordering is computed in this tab, so a list of private names or internal data never leaves your screen.

Sorting a list of lines

Putting a list in order is a deceptively common chore: alphabetising names, ranking numbers, tidying imports, or arranging tags. Spreadsheets can do it but require pasting into a column first, and most code editors only offer a basic A → Z. This tool gives you five sort modes plus cleanup options, all on the raw lines you paste, with the result one click away.

Alphabetical sorting that respects language

The A → Z and Z → A modes use locale-aware comparison, so accented and non-English letters sort the way a human would expect rather than by raw byte value. This avoids the classic bug where "Zoë" or "Ångström" lands in a surprising place because its accented character has a high code point.

Numeric vs alphabetical: a crucial difference

Sorting numbers alphabetically gives the wrong answer: "100" comes before "9" because the comparison is character by character. Numeric mode parses each line as a number, so 2, 9, 10, and 100 sort in true order. Always pick numeric mode for prices, quantities, IDs, scores, or any column of figures.

The same list, three different sorts

It helps to see one input run through each mode. Take these five lines:

9
100
2
Ångström
apple
  • A → Z (locale-aware) orders them 100, 2, 9, Ångström, apple. The numbers sort as text — "100" comes before "2" because 1 precedes 2 — while the accented Å files next to plain a rather than being banished to the end by its high code point.
  • Numeric reads each line with parseFloat, giving Ångström, apple, 2, 9, 100. The two word lines parse as 0 and sink to the bottom, and the figures finally sort by value so 100 lands after 9 — the whole reason numeric mode exists.
  • By length ranks by character count: 9, 2, 100, apple, Ångström (1, 1, 3, 5, 8 characters), with equal-length lines keeping their original relative order.

The takeaway: if your lines mix words and numbers, decide first whether you are sorting them as labels (A → Z) or as quantities (Numeric), because the two produce visibly different results on the very same data.

Sort by length and reverse

By length orders lines from shortest to longest, which is great for finding outliers or arranging items by size. Reverse simply flips the current order of the lines without otherwise sorting them — useful when your data is already in a meaningful sequence and you just need it inverted.

Clean before you sort

The Trim whitespace and Drop empty lines toggles handle the two things that most often spoil a sort. Trailing spaces make otherwise identical lines sort apart, and blank lines clump at the top of an alphabetical sort. Leaving both on produces the clean, predictable ordering you usually want; turn them off only when the whitespace or blank lines carry meaning.

A note on duplicates

Sorting groups duplicates together but does not remove them. If your goal is a clean, unique, ordered list, dedupe first and then sort — the two tools are designed to be used together.

Related text tools

Frequently asked questions

What does the A → Z sort use under the hood?
It uses the browser’s localeCompare, which sorts according to language rules rather than raw character codes. That means accented letters land in their expected places and the order matches what a dictionary or phone book would do, across many languages.
How does numeric sort handle non-numbers?
Each line is parsed with parseFloat, so "10" sorts after "2" rather than before it (the trap with plain alphabetical sorting). Lines that do not start with a number are treated as 0 and grouped at the low end. Use numeric mode for prices, scores, IDs, and any list where 100 must come after 9.
Why does alphabetical sort put 100 before 9?
Alphabetical sorting compares character by character, and "1" comes before "9", so "100" sorts before "9". That is correct for text but wrong for quantities — switch to Numeric mode when your lines are numbers and you want true numerical order.
What is "By length" useful for?
It orders lines from fewest to most characters. It is handy for spotting outliers — the shortest or longest entries in a list — and for visual tidiness, like arranging a menu or a set of tags from short to long.
Will sorting remove duplicate lines?
No. Sorting only reorders lines; identical entries simply end up next to each other. To remove repeats, run the Remove Duplicate Lines tool first and then sort the unique result.
What do the trim and drop-empty toggles change?
Trim whitespace strips leading and trailing spaces so that " banana" and "banana" sort together instead of clumping all space-prefixed lines at the top. Drop empty lines removes blank rows so they do not pile up at the start of an A → Z sort. Both are on by default because that is what most lists need.
Can it sort thousands of lines?
Yes. The sort runs locally and comfortably handles long lists — thousands of lines reorder near-instantly because there is no upload or server round-trip.
Is my list sent to a server?
No. The comparison and reordering are done by your browser on a list it already holds, so private names, internal data, and confidential records are sorted without any of them being uploaded.

More tools you might find useful in the same flow.

Built by Muhammad Tahir · About