Sort Lines Alphabetically
Sort lines of text alphabetically (A–Z or Z–A).
How to use this tool
- Enter text and order in the fields above.
- Results update instantly as you type — or click Calculate.
- Read your sorted text and the full breakdown beneath it.
Sort lines of text alphabetically (A–Z or Z–A).
How it works
This tool sorts the lines of your text in alphabetical order, either A to Z or Z to A, using a case-insensitive comparison so that lines beginning with uppercase and lowercase letters are interleaved naturally rather than grouped by case. Each line of the input is treated as a single sortable unit.
Paste any list — countries, names, ingredients, file names, CSS properties, dictionary entries — into the Text field, choose the direction, and receive the sorted list. This is faster than sorting by hand and more reliable than spreadsheet sorting when your data is plain text rather than tabular.
The sort is lexicographic for text. Numbers at the start of lines are sorted as strings by default, which means '10' comes before '2'. If you need numeric sort order, prefix numbers with leading zeros before sorting.
Worked example
Alphabetise a grocery list
- Paste the list with one item per line: milk, Apples, broccoli, Zucchini, eggs.
- Select Order: A to Z.
- The tool sorts case-insensitively.
- Read the sorted result.
Apples broccoli eggs milk Zucchini
Common mistakes to avoid
- Sorting a numbered list and finding '10' appears before '2' — this is correct lexicographic behaviour; add leading zeros to fix it.
- Sorting lines that have trailing spaces, which can cause inconsistent grouping — run the Remove Extra Spaces tool first.
- Expecting the sort to be stable for lines that compare equal — equal lines may appear in any order in the output.
Key terms
- Lexicographic order
- Alphabetical ordering based on character codes, used here for sorting text lines.
- Case-insensitive sort
- A sort that treats uppercase and lowercase versions of the same letter as equal, so 'apple' and 'Apple' sort together.
Frequently asked questions
- Does sorting preserve blank lines?
- Yes — blank lines are treated as empty strings and sort before any letter.