What does the Sort Lines tool do?
Paste a list — one item per line — and the tool returns the same list reordered. Alphabetical, numerical, or by length. Ascending or descending. The output replaces the original order; nothing is added or removed.
A five-line list of unsorted names becomes the same five names in A-to-Z order. A list of prices becomes the same prices from lowest to highest. A list of URLs becomes the same URLs from shortest to longest. Whatever you paste, you get back, just rearranged.
This is one of those operations that's trivial in a shell (sort filename.txt) and surprisingly clumsy everywhere else. The tool exists for the moment you have a list in your clipboard, you don't want to open a terminal or a spreadsheet, and you need it sorted in the next ten seconds.
A worked example
Here are five unsorted lines:
oranges
apples
bananas
grapes
cherries
Paste them in, pick Alphabetical and Ascending, and the output is:
apples
bananas
cherries
grapes
oranges
Five items, A to Z, no items lost. Switch to Descending and the order reverses: oranges, grapes, cherries, bananas, apples. Same five items, opposite direction.
This is the most common case — alphabetical, ascending, default behavior. The interesting questions come up when the items aren't pure words.
The numeric sort gotcha
Here's where most quick-and-dirty sort tools fall over. Suppose your list is numbers:
10
2
1
20
3
If you sort this alphabetically — the way nearly every default sort works — you get:
1
10
2
20
3
That's wrong, or at least probably not what you wanted. The reason is that alphabetical sorting compares characters one at a time, left to right. "1" comes before "2" because the character 1 comes before the character 2. Then "10" also starts with 1, so it goes near "1", not near "9" or "11". The same rule that puts apple before banana puts "10" before "2".
The Sort Lines tool fixes this when you pick Numerical as the sort type. In numerical mode, the tool parses each line as a number and compares the actual values. Now the output is:
1
2
3
10
20
That's the right answer for a list of quantities, prices, IDs, or anything else where the digits represent values rather than labels.
When to use alphabetical vs numerical sort. If your list is words, names, file paths, or anything text-shaped, use alphabetical. If your list is prices, quantities, scores, IDs, or anything number-shaped, use numerical. The trap is mixed lists like product codes ("A1", "A10", "A2") — those sort alphabetically by default, which gives the wrong order. There's no perfect answer for mixed text-and-numbers content; the best you can do is normalize to a fixed digit width (A01, A02, A10) before sorting.
Sort by length
The third option is sorting by length — the number of characters on each line. Short lines first (ascending) or long lines first (descending). This is useful in a few specific situations:
- Reviewing a list of titles or headlines when you want to spot the outliers — the unusually long one that needs trimming, or the unusually short one that needs more detail.
- Cleaning up a URL list to put the short clean URLs at the top and the long messy ones (with query strings, tracking parameters) at the bottom.
- Curating tweets, headlines, or other length-bound content — when you want to see at a glance which entries are well under the limit and which are crowding it.
- Picking words for a crossword or other length-constrained puzzle, where you want to see all 5-letter candidates grouped together.
Length sort doesn't care what the characters are — letters, digits, spaces, punctuation all count equally toward the length. "Hi!" is three characters. "Hello" is five. "Hi there" is eight.
Ascending vs descending
Every sort type comes with a direction. The two options are simple:
| Sort type | Ascending order | Descending order |
|---|---|---|
| Alphabetical | A → Z (apple, banana, cherry) | Z → A (cherry, banana, apple) |
| Numerical | Smallest → Largest (1, 2, 10) | Largest → Smallest (10, 2, 1) |
| Length | Shortest → Longest (hi, hello, hi there) | Longest → Shortest (hi there, hello, hi) |
Ascending is the default because it's what we read top-to-bottom when scanning a list. Descending is what you want when the "winner" — the largest number, the most recent date, the longest entry — should sit at the top.
When you'll use it
The tool earns its keep when you need a list sorted right now and the source isn't already in a database or spreadsheet:
- Dictionary order for documentation — Building a glossary or an index and want the entries in alphabetical order. Paste, sort, paste back.
- CSV column sorting — Copy one column out of a spreadsheet, sort it independently, paste it back. Often quicker than wrestling with the spreadsheet's own sort UI, especially for one-off cleanups.
- Sorting a list of imports — In code, having imports in alphabetical order makes diffs cleaner and merge conflicts rarer. Many linters enforce this; some don't, and a manual sort fills the gap.
- Log analysis — Sorting timestamps to find the earliest and latest events. The tool handles ISO 8601 timestamps (2026-01-15T09:30:00) correctly under alphabetical sort because that format was specifically designed to be string-sortable.
- Email list cleanup — Combined with Remove Duplicate Lines, sorting an email list makes it easy to spot near-duplicates that the strict dedup missed (different domains for the same user, for example).
- Inventory and parts lists — Sorting by part number, SKU, or quantity to get a view that matches whatever you're trying to do with the list next.
- Word puzzles — Sorting candidate words by length is the fastest way to find the right-length entry for a crossword clue or a Wordle guess.
How the sort works
Under the hood, the tool splits your input on newlines into an array, applies the JavaScript sort comparator that matches your chosen sort type, and joins the results back with newlines.
For alphabetical sort, it uses the browser's built-in localeCompare, which means it respects your browser's locale settings. On an English-locale browser, a through z sort normally and accented characters land near their unaccented equivalents (é sorts near e, not at the end). On a Swedish-locale browser, å sorts after z, which is correct for Swedish.
For numerical sort, each line is parsed with parseFloat. Lines that parse to a valid number sort by their numeric value. Lines that don't parse (text content) sort after the numeric lines, alphabetically among themselves. This is the right behavior for a mixed list where you have some numbers and some labels — the labels don't pretend to be huge numbers, they just go after.
For length sort, each line's character count is compared. Ties (lines of equal length) maintain their original relative order, which is called a stable sort. In practice this means if you have two lines of exactly five characters, the one that came first in your input also comes first in the sorted output.
Empty lines are filtered before the sort and re-inserted at their original relative positions in the output. This is a small touch that matters: if your input had a blank line between two sections, the output still has a blank line in roughly the same place.
Edge cases worth knowing
- Mixed case in alphabetical sort. "Apple", "apple", and "APPLE" sort together rather than in three separate clumps. The tool uses locale-aware comparison, which generally treats them as the same letter for ordering and only uses case as a tiebreaker.
- Leading whitespace. Spaces and tabs at the start of a line are kept and counted in length sort. They also affect alphabetical sort — a line starting with a space sorts before a line starting with the letter a.
- Negative numbers. Numerical sort handles negatives correctly. -5 sorts before -1, which sorts before 0, which sorts before 5.
- Decimal numbers. Numerical sort handles decimals correctly. 1.5 sorts between 1 and 2.
- Scientific notation. 1e3 is parsed as 1000 in numerical mode. Lines like "version 1e3" won't parse as numbers (because of the leading text) and sort alphabetically among the non-numeric entries.
- Dates in ISO format. Strings like 2026-01-15 sort correctly under alphabetical mode because the format goes year-month-day, which is both alphabetically and chronologically sorted.
- Dates in US format. Strings like 01/15/2026 don't sort chronologically under alphabetical mode because the month comes first. Convert to ISO format before sorting if chronological order matters.
A second worked example: sorting a leaderboard
You've got a tab-separated mini-leaderboard pasted from a chat message:
Alice 340
Bob 125
Carol 890
Dave 45
Erin 220
Sorting this alphabetically gives Alice, Bob, Carol, Dave, Erin — the names in order. That's the roster view.
Sorting numerically does something interesting: the tool tries to parse each whole line as a number, fails (because each line starts with a name), and falls back to alphabetical. So you get the same result as alphabetical.
To sort by score, you'd need to either rearrange your data so the number comes first (340 Alice, 125 Bob, etc.) and then numerical sort, or paste only the scores column, sort it, and re-join. This is one of the rare cases where a spreadsheet is the better tool. The Sort Lines tool sorts whole lines, not columns within lines.
Related text tools
Sort Lines is most useful in combination with the other list-cleanup tools:
- Remove Duplicate Lines — The classic pairing. Dedupe first to remove repeats, then sort to put the unique entries in order. This is the standard workflow for cleaning up an email list, a URL list, or a glossary.
- Case Converter — Lowercase your list before sorting if case-different copies should sort together rather than potentially landing far apart.
- Reverse Text — Reverse each line before sorting if you want to sort by the end of each entry rather than the start. Useful for sorting filenames by extension or domain names by TLD.
- Whitespace Remover — Strip leading and trailing spaces before sorting so they don't influence the order in unexpected ways.
- Character Counter — Useful for sanity-checking how many lines you're working with before and after a sort.
Frequently asked questions
Does the Sort Lines tool change the content of my lines?
No. The tool only reorders lines. The text within each line is preserved exactly as you pasted it, including capitalization, punctuation, and internal spacing.
How does numerical sort handle lines that aren't numbers?
Non-numeric lines sort after the numeric lines, in alphabetical order among themselves. So a list like "10, 2, hello, world, 1" sorts numerically as 1, 2, 10, hello, world. The numbers come first in numeric order, then the text in alphabetical order.
Are blank lines kept?
Blank lines are filtered out of the sort and re-inserted at roughly their original relative positions in the output. If you had a blank line between two sections, the output still has a blank line as a section separator.
Is the sort case-sensitive?
Alphabetical sort uses locale-aware comparison, which generally treats "Apple" and "apple" as equal for ordering purposes (with case as a tiebreaker). If you need a strict case-sensitive sort where all uppercase letters sort before any lowercase ones, run the list through the Case Converter first.
Can I sort lines in reverse order?
Yes. Pick Descending as the order. This works for all three sort types — alphabetical descending gives Z-to-A, numerical descending gives largest-to-smallest, and length descending puts the longest lines first.
What's the longest list the tool can handle?
The sort runs in your browser and handles lists of tens of thousands of lines in milliseconds. Hundreds of thousands work too, just with a slight delay. The practical limit is whatever your browser can hold in memory — usually well into the millions of characters.
Is my data uploaded anywhere?
No. The Sort Lines tool runs entirely in your browser using JavaScript. Your list never leaves your machine, which makes the tool safe for sorting confidential customer lists, internal documents, or anything else you'd rather not send to a server.