Sort Lines

Sort lines alphabetically online: put a list of names, words or lines into A to Z order (capitals first), with duplicates kept side by side.

Runs in your browser. Files never leave your device.
9 words · 54 chars

About the Sort Lines

Sort lines alphabetically, A to Z, whether they hold names, words, keywords, file names or anything else. Paste the list with one item per line and the sorted version appears straight away. People use it to alphabetize a guest list or a glossary, to order the imports in a code file, and to line up two lists before comparing them.

The sort follows character codes, so capital letters come before small letters and numbers are compared digit by digit. The table and examples below show where that puts blank lines, numbers and accented words. Sorting happens in your browser.

How the lines are ordered

The text is split at each line break, the lines are sorted, and they are joined again with line breaks. Each line moves as a whole and its contents are not changed. Duplicate lines are kept, side by side.

Lines are compared character by character using their Unicode code values, the same order a plain JavaScript sort uses. A space comes before punctuation such as # and -, then the digits 0 to 9, then capital A to Z, then a few symbols like the underscore, then small a to z, and finally accented and non-Latin letters. The first character that differs between two lines decides which comes first.

Two results catch people out. Case matters: "Zara" sorts above "ali" because every capital letter comes before every small letter. And numbers are sorted as text, so "10 items" comes before "2 items" (the first digit 1 is lower than 2). The examples and FAQs show how to get around both.

Assumptions and limits

  • A to Z only. There is no Z to A, numeric or length option; for Z to A, sort here and then flip the result with Reverse Lines.
  • Case-sensitive: all lines that start with a capital come before all lines that start with a small letter.
  • Numbers are text: 1, 10, 100, 2, 20. Pad them with leading zeros (01, 02, 10) to get number order.
  • Accented letters (é, Ö) and non-Latin scripts sort after z, not next to their plain letter.
  • Blank lines, including the one created by a final line break, and lines starting with a space all move to the top.

Worked examples

Alphabetize a mixed list

Nine lines with a trailing line break. Look at where the blank line, the indented line, the numbers, the capitals and the accented word end up.

banana
Apple
cherry
apple
Éclair
zebra
10 items
2 items
  indented

→ (blank line)
  indented
10 items
2 items
Apple
apple
banana
cherry
zebra
Éclair

Sort names when some are lowercase

"Zara", "ali", "Ali", "ahmed", "Bilal" sort to Ali, Bilal, Zara, ahmed, ali. To get a true A to Z regardless of case, run the list through Text to Lowercase or Text to Title Case first, then sort.

Order numbered file names

item 1, item 10, item 2 stays in that order, because 1 then 0 is compared with 2. Renaming to item 01, item 02, item 10 sorts them 01, 02, 10 as expected.

Sort order of the first character

Lines are ranked by their first character in this order; ties are broken by the next character.

RankCharactersExample lines
1Empty line, then tab and space(blank), Hassan
2Punctuation ! " # $ % & ' ( ) * + , - . /#tag, -dash
3Digits 0 to 910 items, 2 items
4Symbols : ; < = > ? @@mention, :note
5Capital letters A to ZAli, Bilal, Zara
6Symbols [ \ ] ^ _ `_under
7Small letters a to zahmed, ali, zebra
8Symbols { | } ~{block}, ~temp
9Accented and other scriptsÖmer, éclair

How to use the Sort Lines

  1. Enter one item per line. Paste the list into the Input Text box in place of the sample sentence, with each name or word on its own line.
  2. Check the sorted list. The Result box shows the lines in A to Z order. Look at the top for blank lines and at the bottom for accented words.
  3. Copy the alphabetical list. Use Copy to grab the ordered lines and paste them back into your document, spreadsheet column or code file.

Frequently asked questions

How do I alphabetize a list of words online?

Type or paste the words with a line break after each one. The ordered version shows up in the Result box immediately, and pressing Copy gives you the alphabetical list to paste back where it came from.

Why are capital letters sorted before lowercase?

Because the sort compares character codes, and every capital letter A to Z has a lower code than every small letter. Convert the list to one case first, for example with Text to Lowercase, to get a case-insensitive alphabetical order.

Why does 10 come before 2 when I sort numbers?

Because lines are compared as text, one character at a time, and the character 1 sorts before 2. Add leading zeros so every number has the same number of digits (02, 10) and the text order matches the number order.

Can I sort lines Z to A or by length?

Not here: this tool only sorts A to Z. For Z to A, sort the list and then paste the result into Reverse Lines, which flips the order. There's no way to sort by line length.

Does sorting remove duplicate lines?

No. Repeated lines are kept and end up next to each other, which makes them easy to spot. To keep one copy of each line, run the sorted text through the Duplicate Line Remover.

Where do blank lines go when I sort text?

To the top. Empty lines sort first, so they all collect at the start of the result. A final line break after the last item also counts as an empty line, which is why the sorted list can start with a blank line.

This tool runs entirely in your browser. What you enter or upload stays on your device and is never sent to our servers.