Sort Lines Alphabetically
Sort any list of lines A–Z or Z–A, with options to ignore case and remove duplicates.
Dictionary order, not computer order
Lines are sorted A to Z using your browser's language-aware comparison, the same kind of ordering a dictionary uses. That gives sensible results where a plain character-code sort would not:
- Capitals don't split the list.
Appleandapplesit together, with the lowercase one first, instead of every capitalised line coming before every lowercase one. - Accented letters sort with their base letter.
Éclairgoes next toeclair, not afterzebra.
A real run:
| Input | Output |
|---|---|
| banana Apple apple cherry Éclair eclair zebra | apple Apple banana cherry eclair Éclair zebra |
There is no Z to A or ignore-case setting, and repeated lines are all kept. For a Z to A list, sort here and then flip the result with Reverse List Order. For a list without repeats, run the result through Remove Duplicate Lines.
Numbers sort as text
Digits are compared one character at a time, so 10 comes before 2 because 1 comes before 2:
That is the sorted output of item10, item2, item1, Item3. To get numeric order, pad the numbers with leading zeros so they are all the same length (item01, item02, item10), or sort numbers in a spreadsheet, which treats them as values.
Lines that start with a digit come before lines that start with a letter.
Hidden characters that move lines to the top
- Leading spaces and tabs sort before any letter or digit, so an indented line jumps to the top. Run the list through Remove Extra Spaces first to strip them.
- A trailing line break adds an empty line, and empty lines sort first. If your result starts with a blank line, that's why. Remove Empty Lines clears it.
- Files saved on Windows sort correctly. The browser converts them to plain line feeds when you paste, so no hidden carriage return ends up at the end of a line and changes its position.
The order depends on your browser's language
Because the comparison follows language rules, a few letters sort differently depending on the language your browser is set to. In English or German, Örebro sorts next to Oslo. In a browser set to Swedish, where Ö is a separate letter at the end of the alphabet, it sorts after zebra. Plain A to Z text without accents sorts the same everywhere. If you share a sorted list across countries, sort it once and send the result rather than asking everyone to sort their own copy.
Frequently asked questions
Does it sort by last name?+
No. It compares each line from its first character, so John Smith sorts under J. To sort by surname, rewrite the names as Smith, John first, then sort.
How are lines starting with a symbol or quote sorted?+
Most punctuation and symbols come before digits and letters, so lines that start with a quote mark, a bracket or a hash sign usually end up near the top. Remove those characters first if you want the lines sorted by their first word.
Can I sort a list of emails or URLs?+
Yes. Each line is sorted as text, which groups addresses by their first characters. Sorting URLs puts http and https versions in separate groups, since the comparison looks at the scheme first.
Embed this tool on your website
Free to use on blogs, school sites and intranets. Paste this code into your page's HTML; please keep the credit line.
<iframe src="https://utilityapp.lat/embed/text/sort-lines-alphabetically" title="Sort Lines Alphabetically" width="100%" height="600" style="border:0;max-width:760px" loading="lazy"></iframe> <p style="font-size:13px"><a href="https://utilityapp.lat/text/sort-lines-alphabetically">Sort Lines Alphabetically</a> by UtilityApp</p>