How to Sort Lines of Text — A-Z, Numeric, and Natural Sort
Sort a list alphabetically, numerically, by length, or with natural sort order (so item2 comes before item10) — without opening a spreadsheet.
By QR Ivify Team
Sorting a short list feels like it shouldn't need a dedicated tool — until you hit "item10" sorting before "item2," or a numeric list sorting as text ("10" before "9"), or a mixed-case list where "Apple" and "apple" end up nowhere near each other. Here's what's actually going on, and how to sort correctly.
Why Plain Alphabetical Sort Gets Numbers Wrong
Standard alphabetical sorting compares text character by character. That means "item10" and "item2" get compared starting from "item1" vs. "item2" — and since "1" sorts before "2" as a character, "item10" comes before "item2," even though anyone reading the list would expect the opposite. This is one of the most common "why is my sort broken" moments, and it's not actually broken — it's doing exactly what character-by-character comparison does.
Natural sort fixes this by reading embedded numbers as numbers, not as a sequence of digit characters. With natural sort, "item2" correctly comes before "item10."
The Seven Sort Modes
- A → Z / Z → A — standard alphabetical, ascending or descending.
- Numeric ascending/descending — reads each line as a number; anything that isn't a valid number gets pushed to the end rather than sorting confusingly at the top or bottom.
- Length: shortest → longest / longest → shortest — sorts by how many characters each line has, not what it says.
- Natural sort — the fix for the "item2 vs item10" problem described above.
Step by Step
- Open the Text Sorter.
- Paste your list, one item per line.
- Choose a sort order.
- Optionally turn on case sensitivity, trim whitespace, remove empty lines, or remove duplicates before sorting.
- Copy or download the result, or Reset to start over.
A Worked Example
Input:
banana
Apple
orange
apple
Sorted A → Z with case sensitivity off (the default — ignoring case):
Apple
apple
banana
orange
Notice "Apple" comes before "apple" even though they're otherwise identical — sorting is stable, so when two lines are equal under case-insensitive comparison, they keep their original relative order rather than being shuffled arbitrarily.
Frequently Asked Questions
What is natural sort, exactly? A sort order that reads embedded numbers as numbers rather than character-by-character — so "item2" correctly sorts before "item10," which plain alphabetical sorting gets wrong.
What happens to non-numeric lines in a numeric sort? They're placed at the end, since they have no valid numeric value to sort by — regardless of ascending or descending order.
Can I remove duplicates or empty lines while sorting? Yes — both are optional toggles applied before sorting, so the result is deduplicated and/or has no blank lines if you want that.
Is sorting case sensitive by default? No — it ignores case by default, but you can turn on "Case sensitive" for strict, case-aware ordering.
Does this upload my list anywhere? No. Sorting happens entirely in your browser.
Try It
Need to sort a list properly — including numbers that sort the way people actually expect? QR Ivify's free Text Sorter covers alphabetical, numeric, length, and natural sort. Have duplicates to remove first? Try Remove Duplicate Lines.
Related articles
How to Change Text Case Online — UPPERCASE, Title Case & More
Convert text between UPPERCASE, lowercase, Title Case, Sentence case, and more, without losing line breaks — and what actually separates Title Case from Capitalize Each Word.
How to Clean Up Messy Text (Extra Spaces, Blank Lines, Tabs)
Fix text that came through with irregular spacing, blank lines, or tabs — from pasting out of a PDF, a webpage, or a spreadsheet — with cleanup options you control individually.
How to Compare Two Texts and See What Changed
Compare two versions of a document, email, or config file line by line and see exactly what was added or removed — the algorithm behind it, explained simply.