Text & Developer tool

Sort Lines Alphabetically Online

Paste a list and sort it A to Z or Z to A, then copy the result.

  • Instant results
  • Working shown
  • No sign-up
  • Runs in your browser
ToolUpdates as you type

9 lines in, 9 lines out.

Your text stays in your browser. Nothing is sent or saved.

How it works

This tool sorts the lines of a list in alphabetical order, A to Z or Z to A. By default it ignores upper and lower case and sorts numbers by value, so 'item 2' comes before 'item 10'. You can also remove empty lines and exact duplicates, then copy the sorted list.

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

  1. Paste your list in the top box, one item per line.
  2. Click A to Z or Z to A.
  3. Choose options: ignore case, sort numbers by value, remove empty lines, remove exact duplicates.
  4. 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.

Frequently asked questions

How do I put a list in alphabetical order?
Paste the list with one item per line and click 'A to Z'. The sorted list appears in the result box. Click 'Copy result'.
Why do capital letters come first when I turn off 'Ignore case'?
With case on, lines are sorted by character code, as a plain sort in code does. All capital letters (A to Z) have smaller codes than small letters (a to z), so 'Banana' comes before 'apple'.
Why does 'item 10' come before 'item 2'?
Text sorting compares one character at a time, and '1' comes before '2'. Turn on 'Sort numbers by value' to compare whole numbers, so 2 comes before 10.
Can I sort and remove duplicates together?
Yes. Tick 'Remove exact duplicates'. For more control, such as ignoring case when removing repeats, use the remove duplicate lines tool first.
Is my list saved?
No. Sorting runs in your browser and nothing is sent or stored.

Try another tool

See all free tools
Chat with us