Sort Lines Alphabetically

Paste any list, one item per line, and put it in alphabetical, natural, numeric, length or random order in one click.

Runs entirely in your browser. Nothing you add is sent to us.

Create a free account to use the Sort Lines Alphabetically

Free forever for this tool. Takes a few seconds — then you come straight back here.

  • All 150 free tools, one login
  • Free website audit with fixes
  • Search Console dashboard
  • Free keyword rank tracker

Already have an account? Sign in

Sort Lines Alphabetically — sort alphabetically

Sort alphabetically, in reverse, by length or by number with one click. Paste any list, one item per line, and this free tool puts it in order using British English alphabetical rules. Natural sort keeps file2 before file10, numeric sort orders prices and quantities properly, and shuffle uses your browser's secure random generator for a fair random order. You can ignore capital letters, trim stray spaces, remove empty lines and drop duplicates in the same step. Your list is sorted on your device and never uploaded.

How to use the Sort lines

  1. 1 Paste your listPut one item per line in the box. A column copied from Excel or Google Sheets pastes as one line per cell.
  2. 2 Pick a sort methodChoose A–Z, Z–A, natural, by length, longest first, numeric, reverse order or shuffle. A short note under the buttons explains what each one does.
  3. 3 Set the optionsIgnore case so capitals do not jump ahead, trim spaces, remove empty lines, and remove duplicates if you only want each item once.
  4. 4 Check the resultThe sorted list appears on the right straight away, with a line count. Press Shuffle again for a new random order.
  5. 5 Copy or downloadCopy the sorted lines, download them as a text file, or press Use as input to sort again with different settings.

How alphabetical sorting works here

Computers do not naturally sort text the way people expect. A simple sort compares the numeric codes behind each character, which puts every capital letter before every lower-case letter, so "Zebra" comes before "apple", and sends accented letters such as é to the end after z. That is rarely what anyone wants for a list of names or products.

This tool uses the Unicode collation rules for British English that are built into your browser. Letters are compared the way a dictionary or a phone book would compare them: accented letters sort next to their plain versions, so "Émilie" sits among the E names, and with Ignore case on, capitals and lower case are treated as the same letter. Punctuation and spaces are handled sensibly rather than by their character codes.

With Ignore case turned off, words that differ only in capitals are put in a consistent order with the capitalised version first, so "Smith" comes just before "smith" rather than dozens of lines away.

Natural sort: why file10 should come after file2

Ordinary alphabetical sorting compares text one character at a time, so "file10" comes before "file2" because the character 1 comes before 2. The same thing happens with invoice numbers, chapter titles, version numbers and house numbers, giving orders such as "Flat 1, Flat 10, Flat 11, Flat 2".

Natural sort recognises runs of digits inside the text and compares them as whole numbers. The result is the order a person would choose: file1, file2, file3 and so on up to file10 and file11. It is the best choice for file names, photo names such as IMG_9 and IMG_10, product codes, flat and unit numbers, and any list where numbers appear inside words.

Every sort method explained

Each method suits a different kind of list. You can switch between them freely, because the original text in the left-hand box is never changed until you press Use as input.

  • A–Z and Z–A sort alphabetically using British English rules, in ascending or descending order. Use them for names, towns, keywords, glossaries and reading lists.
  • Natural sort is A–Z with numbers inside the text compared by value, so item 2 comes before item 10.
  • By length puts the shortest lines first, and longest first does the opposite. Lines of equal length are sorted A–Z. This is handy for spotting overly long titles, finding short keywords, or ordering redirect rules so specific paths come before general ones.
  • Numeric sort orders lines by the first number found in each line, from smallest to largest. Negative numbers, decimals and thousands separators such as 1,250 are understood. Lines with no number are placed at the end in alphabetical order.
  • Reverse order flips the list upside down without sorting it, which is useful for turning an oldest-first log into newest first.
  • Shuffle puts the lines in a random order using the browser's cryptographic random number generator and an unbiased shuffle, so every order is equally likely.

Shuffling fairly for draws and rotas

Random order is useful for more than games. People use it to draw raffle winners, pick a running order for presentations, split staff into teams, allocate desks or rotate who takes the next support ticket. For any of these, the shuffle needs to be genuinely fair, so nobody has a better chance of landing at the top.

This tool uses the Fisher–Yates shuffle, a well-known method that gives every possible order an equal chance when it is fed good random numbers. The random numbers come from the Web Crypto API in your browser, the same source used to generate encryption keys, rather than the simpler Math.random function, and they are drawn in a way that avoids the small bias some quick shuffles introduce. Press Shuffle again as many times as you like for a new order.

If a draw needs to be seen to be fair, for example a prize draw run by a charity or a business promotion, run it on a shared screen or with a witness present, and keep a copy of the list you used. For larger promotions, check the requirements that apply in the UK, including the CAP Code rules on prize promotions, before you start.

Tidying a list while you sort it

Lists copied from spreadsheets, emails and web pages are often untidy. Trimming removes spaces and tabs at the start and end of each line, which otherwise push those lines out of place because a space sorts before a letter. Remove empty lines deletes blank lines so they do not all gather at the top of the result.

Remove duplicates keeps only the first copy of each line, using the same case setting as the sort, so with Ignore case on, "London" and "london" count as one. For more control over duplicates, such as keeping the last copy or seeing a list of the lines that repeated, use our remove duplicate lines tool and then sort the result here.

Sorting in spreadsheets, Word and code

Excel, Google Sheets and Word can all sort, so why use a separate tool? Mostly for speed and control. Pasting a list here is quicker than opening a spreadsheet for a one-off job, and options such as natural sort, sort by length and a cryptographically fair shuffle are not built into most office software.

If your list is a set of spreadsheet rows with several columns, sort it in the spreadsheet instead, so each row stays together. If you are sorting data in code, note that JavaScript's default sort uses character codes rather than language rules, so use Intl.Collator or localeCompare with the en-GB locale, adding the numeric option for natural sorting, to get the same results as this tool.

Bear in mind that different programs follow slightly different rules for punctuation, spaces and symbols, so a list sorted here may not match a database or another program character for character at the edges, even when the letters are in the same order.

Examples you can copy

Alphabetical versus natural sort

A–Z:       file1.txt, file10.txt, file11.txt, file2.txt, file3.txt
Natural:   file1.txt, file2.txt, file3.txt, file10.txt, file11.txt

Numeric sort of mixed lines

Input:
Delivery £4.95
Sofa £1,250
Cushion £18
Gift wrap
Rug £129.99

Numeric:
Delivery £4.95
Cushion £18
Rug £129.99
Sofa £1,250
Gift wrap

Common mistakes to avoid

Using A–Z for numbered items

Plain alphabetical order puts 10 before 2. Use natural sort for text with numbers inside it, or numeric sort for lists of amounts.

Forgetting about leading spaces

A space sorts before any letter, so untrimmed lines end up at the top. Keep trimming on.

Sorting spreadsheet rows as text

If each line is a row with several columns, sorting here works on the whole line. Sort in the spreadsheet to keep columns together.

Relying on Math.random shuffles for draws

Quick shuffles in some apps are biased. This tool uses the browser's cryptographic generator and the Fisher–Yates method.

Expecting identical results in every program

Collation rules for punctuation and symbols vary between programs, so check edge cases if exact order matters.

Frequently asked questions

Natural sort compares numbers inside text by their value, so file2 comes before file10. Plain alphabetical sorting puts file10 first because 1 comes before 2.

Yes. Tick Remove empty lines and Remove duplicates, and the list is cleaned in the same step as it is sorted.

Simple sorts compare character codes, where all capitals come before lower case. This tool uses language-aware rules, so turn on Ignore case for a dictionary-style order.

Using British English collation, so é sorts with e and ö with o, rather than being pushed to the end of the list.

It places them after all the numbered lines, in alphabetical order.

It uses the Web Crypto API random generator with an unbiased Fisher–Yates shuffle, so every possible order is equally likely.

Not directly. The tool sorts by the whole line. For columns, sort in a spreadsheet, or use find and replace to move the part you want to sort by to the start of each line.

No. Sorting happens in your browser, so the list never leaves your device and is gone when you close the page.

Free website audit

See how your site scores, free

Speed, SEO, DNS, email (SPF/DKIM/DMARC) and security in one scan, with a prioritised fix list.