This sort lines alphabetically tool puts any list in order. Paste names, subjects, keywords or file names, one per line, and sort them A to Z or Z to A.
How to sort lines alphabetically online
- Paste your list in the top box, one item per line.
- Click A to Z or Z to A.
- Choose options: ignore case, sort numbers by value, remove empty lines, remove exact duplicates.
- Click Copy result.
Sort options explained
| Option | On | Off |
|---|---|---|
| Ignore case | apple, Banana, cherry | Banana, apple, cherry |
| Sort numbers by value | item 2, item 10 | item 10, item 2 |
| Remove empty lines | Blank lines dropped | Blank lines sorted to the top |
| Remove exact duplicates | Each line once | Repeats kept side by side |
Z to A simply reverses the A to Z result.
Alphabetical order and character codes
Computers store each character as a number. In ASCII and Unicode, the digits come first, then capital letters, then small letters:
| Characters | Codes |
|---|---|
| 0 to 9 | 48 to 57 |
| A to Z | 65 to 90 |
| a to z | 97 to 122 |
So a plain sort in most languages puts "Banana" before "apple". Ignore case sorts the way a dictionary does instead. You can see these codes in the text to binary converter.
Common mistake: A common mistake is sorting numbers as text. In JavaScript,
[10, 9, 1].sort()gives[1, 10, 9], because the default sort compares them as strings. Pass a compare function, such as(a, b) => a - b, to sort numbers.
Sort text lines in Python
names = ['cherry', 'apple', 'Banana']
print(sorted(names))
print(sorted(names, key=str.lower))
print(sorted(names, key=str.lower, reverse=True))
Output:
['Banana', 'apple', 'cherry']
['apple', 'Banana', 'cherry']
['cherry', 'Banana', 'apple']
The first line sorts by character code, the second ignores case, and the third is Z to A. JavaScript's sort() and toSorted() are covered in JavaScript array methods, and SQL sorts rows with ORDER BY, explained in SQL ORDER BY and LIMIT.
How sorting works
Behind the button is a sorting algorithm. Learn how they work step by step with bubble sort, insertion sort and merge sort, and compare their speed in time complexity and Big O.
Pro tip: To get a clean, unique, sorted list, first run the remove duplicate lines tool with "Ignore case" on, then sort the result here.
Your text stays in your browser. This tool does not send or save it.
