Sort Lines Alphabetically, by Length or by Number

Paste a list with one item per line, choose an order and the sorted lines appear straight away, ready to copy back into your document or spreadsheet.

TextFreeNo sign-upWorks on phones
––
–Lines in
–Lines out
–Empty lines removed
–Duplicates removed
Sorted lines
First line–
Last line–
Lines with no leading number (placed last)–

This tool runs in your browser. Nothing you type is uploaded or saved, and there is nothing to install or sign up for.

What this line sorter does

A list is easier to scan, compare and check once its lines sit in a predictable order. This page takes any block of text, treats every line as one item and rearranges those items for you. Nine orders are built in: A to Z, Z to A, shortest first, longest first, by leading number in both directions, natural order, a straight reverse and a shuffle.

It is meant for whole lines, such as names, vocabulary terms, file names, reading lists or rows copied out of a spreadsheet column. If your items sit on one line with commas between them, the alphabetical order sorter is the better fit, because it can split on commas as well.

Sorting a list step by step

  1. Paste or type your list into Your lines, one item on each line.
  2. Open Sort order and pick the order you want. The result box updates the moment you choose.
  3. Tick or clear the four options. Trim spaces at the start and end of lines and Remove empty lines start switched on, because stray spaces and blank rows are the usual reason a pasted list sorts strangely.
  4. Press Copy sorted lines to put the result on your clipboard. Reset brings back the sample list.

The four tiles under the headline count the lines that went in, the lines that came out, the empty lines dropped and the duplicates dropped, so you can tell at a glance whether anything went missing.

A worked example with seven lines

The page opens with this short list: banana, Apple, cherry, file10, file2, 10 grapes and 9 kiwis, each on its own line. The same seven lines come out very differently depending on the order you choose:

Sort orderResult, top to bottom
A to Z10 grapes, 9 kiwis, Apple, banana, cherry, file10, file2
Natural order9 kiwis, 10 grapes, Apple, banana, cherry, file2, file10
By leading number, smallest first9 kiwis, 10 grapes, banana, Apple, cherry, file10, file2
Shortest line firstApple, file2, banana, cherry, file10, 9 kiwis, 10 grapes
Reverse the current order9 kiwis, 10 grapes, file2, file10, cherry, Apple, banana

Look at the first row. In a plain A to Z sort, 10 grapes lands above 9 kiwis and file10 lands above file2. That is not a bug. It is what alphabetical order means for digits, and the next section explains why.

How each order compares two lines

A to Z and Z to A

Lines are compared one character at a time from the left. The digit 1 comes before the digit 9, so anything starting with 1 is placed first, even when the full number is larger. Spaces and most punctuation come before digits, digits come before letters, and accented letters come after z because the comparison uses plain character codes, not the dictionary rules of a particular language.

With Capital letters before small letters left clear, Apple and apple are treated as the same word for ordering. Tick the box and every capital letter is placed ahead of every small one, so Zebra would come before apple.

Natural order

Natural order splits each line into runs of digits and runs of everything else. Digit runs are compared as whole numbers, which is why file2 comes before file10 and chapter 9 before chapter 10. Leading zeros are ignored, so 007 and 7 count as equal. A line that starts with a digit goes ahead of a line that starts with a letter.

By leading number

Here only the number at the very start of a line matters. Minus signs and decimals are understood, so a list of −2, 1.5 and 3 sorts the way a number line runs. Lines that do not begin with a number go to the bottom in the order they arrived, and an extra row tells you how many there were. In the sample that count is 5.

Length, reverse and shuffle

The two length orders count characters, including spaces inside the line, and settle ties alphabetically. Reverse flips the list without sorting anything. Shuffle uses a Fisher-Yates shuffle, so every possible order is equally likely; type a whole number into the seed box if you need to get the same shuffle again later, and press Shuffle again for a fresh one.

Whenever two lines are equal under the chosen rule, the one that was higher in your original list stays higher.

Why a sorted list sometimes looks wrong

  • Numbers in A to Z mode. Scores, dates and numbered items need natural order or a leading-number order.
  • Dates written as words. March will always come before May but after June. Write dates as year-month-day digits, such as 2026-03-14, and A to Z puts them in calendar order.
  • Hidden spaces. A line that begins with a space sorts ahead of everything else when trimming is off.
  • Titles that start with The or A. The tool does not skip leading articles. Move the article to the end of the line first if your style guide asks for that.
  • Very large lists. The box accepts up to 100,000 characters. Split anything bigger into parts.

Removing duplicates here ignores capital letters unless the capital-letters box is ticked, and it keeps the first copy it meets.

Handy uses in class and at a desk

Teachers can paste a class roster typed as Last name, First name and get a register in seconds, then shuffle the same roster with a seed to produce a fair presentation order that can be shown again if anyone asks. Students can put a bibliography or glossary into A to Z order before handing work in, or sort vocabulary shortest first to start revision with the easy words.

For office jobs, natural order is the one to use on file names and version numbers, and largest-number-first quickly ranks a pasted list of scores that begin with the points.

If you want a detailed report of which entries repeat, run the list through the duplicate line remover. Untidy spacing inside the lines is a job for the extra space remover, and the case converter will make capitals consistent before you sort. To draw a single random entry instead of reordering all of them, try the random name picker.

More helpers are listed with the other text tools, and the complete collection of free online tools covers math, dates and classroom jobs as well.

Frequently asked questions

How do I sort lines alphabetically online?

Paste the list with one item per line, leave the sort order on A to Z and copy the result. The sample list of seven lines comes out as 10 grapes, 9 kiwis, Apple, banana, cherry, file10, file2.

Why does 10 come before 9 when I sort A to Z?

Alphabetical sorting compares one character at a time, and the digit 1 comes before the digit 9. Switch to natural order or to a leading-number order and 9 is placed before 10.

What is natural sort order?

Natural order reads runs of digits as whole numbers instead of separate characters. That puts file2 before file10, which is the order most people expect for numbered names.

Does the sorter treat capital letters differently?

Not by default: Apple and apple are ordered as the same word. Tick the capital letters option and all capital letters are placed before all small letters.

Can I get the same shuffle twice?

Yes. Choose Shuffle and type a whole number from 0 to 999,999,999 into the seed box. The same list with the same seed always gives the same order, while an empty seed box gives a new order each run.

Is there a limit on how many lines I can sort?

The text box takes up to 100,000 characters in one go, which is several thousand ordinary lines. Longer lists need to be sorted in parts.

Related tools

Browse all free tools →