Sort Lines Alphabetically

Lines—
First line—

How Sort Lines Alphabetically is calculated: A to Z = lines in alphabetical order; Z to A = reversed; numeric = by leading number; by length = shortest first.

What a line sorter does

A line sorter puts the lines of a list into order. Paste in a list of names, words, or numbers, and it returns them sorted. The default list on this page — banana, apple, cherry, date — comes back as apple, banana, cherry, date in A to Z order, with apple first.

The need comes up wherever a list has to be checked or used. A sorted list is easy to scan: you can see at a glance whether an item is there, whether it appears twice, and whether anything is missing. An unsorted list of a hundred items is a chore; a sorted one is a lookup.

This sorter shows two results — the line count and the first line after sorting — plus the full sorted list in the output box. Four modes are offered: A to Z, Z to A, numeric, and by length. Every result updates live as you type, and everything runs in your browser, so your list never leaves your device.

How line sorting works

The method is a standard sort on the lines. Split the text on line breaks, compare the lines two at a time, and arrange them in order. A to Z compares letters from the left: “apple” comes before “banana” because a comes before b, and “cherry” comes before “date” because c comes before d. Z to A is the same comparison with the result flipped.

Numeric mode sorts by the number at the start of each line, not by the characters. The lines 10, 2, 30, 1 become 1, 2, 10, 30 — the right numeric order. A plain alphabetical sort would give 1, 10, 2, 30, because it compares the character “1” with the character “2” and never sees the values. Lines with no number go last, in alphabetical order.

By-length mode sorts by how long each line is, shortest first. For the default list, “date” has 4 letters, “apple” has 5, and “banana” and “cherry” have 6 each — so the order is date, apple, banana, cherry. Lines of the same length keep their original order, so banana stays ahead of cherry because it was ahead before sorting.

Sorting has an order for characters too. In plain character order, digits come before letters, and upper-case letters come before lower-case ones, so “10” sorts before “2”, and “Zebra” sorts before “apple”. This tool compares lines as plain text, which is why numeric mode exists for numbers and why a case converter helps before sorting a mixed-case list. Different languages sort differently — in some, accented letters have their own place — and this tool uses simple English ordering.

The four modes — which one to pick

Pick A to Z for the everyday job: names, words, places, titles. It is the mode most people mean when they say “sort this list”, and it is the default on this page. A sorted list of names is how you check attendance, find a duplicate, or merge two lists without missing anything.

Pick Z to A when you want the newest or biggest first. A list of dates written newest-first, or a list of scores with the highest at the top, is a Z to A sort. It is the same work as A to Z with the order flipped, so switching between them costs nothing.

Pick numeric when the lines start with numbers — quantities, prices, roll numbers, version numbers. Alphabetical sorting puts 10 before 2, which is wrong for numbers and right for nothing. Numeric mode reads the values, so 1, 2, 10, 30 comes out in the order a human expects.

Pick by length when length is the point: shortest word first for a spelling list, shortest line first for a layout test, longest last for a puzzle. It is the least used mode and the most useful when the job is about shape rather than meaning. A word counter tells you how long the list is before you sort it.

A worked example: one list, four orders

Take the default list: banana, apple, cherry, date. That is 4 lines. A to Z gives apple, banana, cherry, date, with apple first. Z to A gives date, cherry, banana, apple, with date first. By length gives date, apple, banana, cherry, with date first because it is the shortest at 4 letters.

Now take numbers: 10, 2, 30, 1. A to Z gives 1, 10, 2, 30, which looks wrong the moment you read it. Numeric mode gives 1, 2, 10, 30, which is the order anyone would write by hand. The difference is the whole reason numeric mode exists — characters and values are not the same thing.

Try it on names. A class list of Rahul, Priya, Amit, Sneha becomes Amit, Priya, Rahul, Sneha in A to Z order. Finding “Priya” in the sorted list takes a glance; finding her in the unsorted list takes a scan of every line. A case converter can make the whole list one case first, so the sort is not thrown off by a capital letter.

Who uses a line sorter, and why

Teachers use it to sort class lists, word lists, and results. A spelling list sorted by length goes from easy to hard. A result list sorted Z to A puts the top scorer first. A vocabulary list sorted A to Z is a dictionary in miniature.

Office workers use it to sort names, places, and items. A list of suppliers, a list of cities, a list of product codes — all of them are easier to use sorted than in the order they were typed. Sorting is the cheapest organisation there is: one click, and the list is usable.

Developers use it to sort test data, log lines, and configuration entries. A sorted config file is easy to diff against the last version, and a sorted list of IDs makes a missing entry obvious. A json formatter does a similar tidy-up job for JSON data, and an ascii converter shows the code behind every character in the sorted lines.

Alphabetical order is the oldest information system still in use. Library catalogues, phone books, dictionaries, and indexes all rely on it, and they all work the same way: put the entries in order, and finding one takes a glance instead of a search. A sorted list is a lookup table, and an unsorted list is a pile. The computer did not invent sorting — it just made it instant.

Line sorter vs duplicate remover

A line sorter and a duplicate remover do different jobs, and they work well together. The sorter rearranges lines and keeps everything, including duplicates. The remover deletes repeats and keeps the order. A list that is both repeated and unordered needs both: remove the duplicates, then sort what is left.

Use the sorter when the list is unique but out of order. Use the remover when the list has repeats. Sorting first makes duplicates sit next to each other, which makes them easy to spot — but the remover is faster than spotting them by eye, so run the remover first and sort second.

For filler text to practise with, a lorem ipsum generator gives you a passage to split into lines and sort. And a word counter tells you how many words the sorted list holds once it is in order.

Common line-sorting mistakes

The first mistake is sorting numbers alphabetically. A to Z puts 10 before 2, because it compares characters, not values. If your lines start with numbers, use numeric mode — that is what it is for, and it is the mistake this tool exists to prevent.

Second: case. Upper-case letters sort before lower-case ones in a plain comparison, so “Zebra” can come before “apple”. If your list mixes cases, make it one case first with a case converter, or accept that capitals will cluster at the top.

Third: leading spaces. A line that starts with a space sorts before a line that starts with a letter, because a space comes before letters. If your sorted list starts with a blank-looking line, a leading space is the reason. Trim the lines first.

Fourth: expecting by-length to break ties. Two lines of the same length keep their original order — banana stays ahead of cherry because it was ahead before. If you want ties broken alphabetically as well, sort A to Z first, then sort by length: the stable sort keeps the alphabetical order inside each length.

How to use this line sorter

Using this line sorter is simple. Paste your list into the box, one item per line, or type it directly. Pick a mode — A to Z, Z to A, numeric, or by length — and the sorted list appears in the output box instantly, with the line count and the first line beside it. There is no button to press and no form to submit.

To sort a different list, select all, delete, and paste the new one. The output updates live. If the list came from a spreadsheet, paste one column at a time, and remember that blank lines count as lines — remove them first if you do not want an empty line at the top of the sorted list.

Everything runs in your browser. No sign-up, no account, no data sent anywhere — your list never leaves your device. It works offline once the page has loaded. Try it with something real before you need it: paste a list you actually use, sort it A to Z, and see how much easier it is to read.

Lines with numbers and units sort by their leading number in numeric mode. “10kg” parses as 10 and “2kg” as 2, so 2kg comes first, which is right. “10 kg” with a space parses as 10 too, because the number is read from the start of the line. A line that starts with a word and has a number later, like “box 10”, has no leading number, so it goes last with the other non-numeric lines, in alphabetical order.

Frequently Asked Questions

The default list is banana, apple, cherry, date. A to Z gives apple, banana, cherry, date, with apple first. Z to A gives date, cherry, banana, apple. By length gives date, apple, banana, cherry, because date is the shortest at 4 letters.

No. A to Z compares characters, so it puts 10 before 2 — the character “1” comes before “2”. Numeric mode reads the values, so 10, 2, 30, 1 becomes 1, 2, 10, 30. Use numeric mode whenever your lines start with numbers, and lines with no number go last.

They keep their original order. In the default list, banana and cherry both have 6 letters, so banana stays ahead of cherry because it was ahead before sorting. To break ties alphabetically, sort A to Z first, then sort by length.

Yes. Everything runs in your browser — your text is never uploaded, stored, or sent anywhere. You can use it offline once the page has loaded, and you can paste a sensitive list like names or codes without worrying about who sees it.

More free tools

More calculators and utilities from Sortrun — free, no sign-up.