# Sort Lines Online - A to Z, Numeric, by Length, Reverse or Shuffle

Page: https://hirantha.me/tools/sort-lines-tool
Part of: Hirantha Sandaruwan Lakshan free tools (https://hirantha.me/tools)
Updated: 2026-10-13

Sort lines A to Z, Z to A, by number or by length, or reverse and shuffle them. Natural number order, case options and language-aware sorting, live as you type.

This is a free tool that runs in the browser: open the page to use it. File tools process files on the visitor's own device; files are never uploaded or stored. No account, sign-up, payment or watermark.

Paste a list and sort it as you type: A to Z, Z to A, by the number at the start of each line, by length, in reverse, or shuffled. Numbers inside text can be put in numeric order so item2 comes before item10, case and spaces can be ignored, and text is ordered by the rules of the language you choose. Hundreds of thousands of lines are fine, and nothing is uploaded.

Lines are split at every line break: Windows, Unix and old Mac endings, and the Unicode line and paragraph separators. A single break at the very end of the text ends the last line. It is not sorted as an empty line, and it is put back at the end of the result. In A to Z order empty lines come first unless you tick 'Remove empty lines'. Lines that compare as equal keep their original order, because JavaScript's sort has been required to be stable since ECMAScript 2019.

Text is ordered with Intl.Collator, the language-aware comparison built into your browser. By default it compares base letters first, then accents, then case. For English and most other languages it puts lower case before upper case when everything else is equal (a before A), as the default table of the Unicode Collation Algorithm does (UTS #10, section 6.6, gives 'a' and 'A' different tertiary weights with a first). A few languages, such as Danish, reverse that and put capitals first, and UTS #10 section 9.6 notes that this varies by language. Pick a language to change the rules: in Swedish the letters å, ä and ö come after z, while in German ä sorts with a. 'Ignore upper and lower case' makes a and A equal. If your browser has no rules for the language you pick, the tool says so and uses its default language, and if it cannot build a collator at all it falls back to code point order.

'None: Unicode code point order' compares plain Unicode values. Every capital letter comes before every lower case letter (Z before a), accented letters come after z, and with 'Ignore spaces' and 'Ignore case' off the result matches what the Unix sort command gives in the C locale. It is predictable but not what a reader expects of an alphabetical list. This mode compares real code points. JavaScript's own default sort compares UTF-16 code units, which puts characters outside the Basic Multilingual Plane, such as most emoji, before some characters that have a lower code point.

'Numbers inside text in numeric order' compares each run of digits by its value, so item2 comes before item10 (natural sort order). The two 'Numbers' orders read the number at the start of each line instead: an optional sign, thousands commas, a decimal point and an exponent, so -10 comes before -5 and 1,200 comes after 999. Lines with no number at the start go last in their original order. Numbers are read as ordinary decimals, so digits beyond about 15 lose precision; for long IDs use the numeric option on text. 'Shortest first' and 'Longest first' count Unicode characters, so an emoji is one, and lines of equal length are in A to Z order. Shuffle is a Fisher-Yates shuffle driven by the seed you can see, so a shuffle can be repeated; it uses a fast 32-bit generator, which is fine for rearranging a list and not for a draw that must be unpredictable.

Zebra, apple, Éclair, item10, item2, Apple and 9 in four orders (English rules except the last):
| Order | Result |
| --- | --- |
| A to Z | 9, apple, Apple, Éclair, item10, item2, Zebra |
| A to Z, natural numbers | 9, apple, Apple, Éclair, item2, item10, Zebra |
| A to Z, ignore case | 9, apple, Apple, Éclair, item10, item2, Zebra |
| Unicode code point order | 9, Apple, Zebra, apple, item10, item2, Éclair |

Q: How do I sort lines alphabetically?
A: Paste the lines into the box and leave the order on 'A to Z'. The result is ready at once. 'Z to A' reverses the order, and 'Reverse order' simply turns the list upside down without sorting it.

Q: Why does item10 come before item2?
A: Plain text order compares one character at a time, and the character 1 comes before 2. Tick 'Numbers inside text in numeric order' and each run of digits is compared as a whole number, so item2 comes before item10. This is called natural sort order.

Q: Why do some tools put all capitals before lower case?
A: They compare Unicode values, where every capital letter is lower than every small letter, so Zebra comes before apple. This tool uses language rules by default, which mix the cases like a dictionary. Choose 'None: Unicode code point order' if you want the plain comparison.

Q: How do I sort numbers?
A: Choose 'Numbers, smallest first' or 'Numbers, largest first'. The tool reads the number at the start of each line, with a sign, thousands commas and decimals allowed. A line such as '10 apples' sorts by 10. Lines with no number at the start go last.

Q: How do I sort accented or Sinhala text properly?
A: Pick the language under 'Language rules for text'. The tool then uses your browser's ordering rules for it. If the browser has none for that language, a message says so. Different languages order the same letters differently, for example Swedish puts ä after z and German does not.

Q: Can I sort and remove duplicates together?
A: Sort the list here, then paste it into Remove duplicate lines. For exact duplicates the order of the two steps does not matter. If you also ignore case or spaces, the copy that stays can differ: Remove duplicate lines keeps the first copy in the order it receives, so sorting first keeps the first copy in sorted order.

Q: Is the shuffle truly random?
A: It is a fair Fisher-Yates shuffle, repeatable from the seed shown, and 'Shuffle again' picks a new seed with your browser's secure random generator. The shuffle itself uses a 32-bit generator, so do not use it for a prize draw or anything else that must be unpredictable.

Q: How many lines can it sort?
A: Up to 5 million characters at once, about 5 MB of plain text. In testing on a small server, 200,000 random lines of 5 to 34 characters sorted in under a second. A longer text is refused with a message and nothing is changed.

Q: Is my list uploaded?
A: No. Sorting happens in your browser and nothing is sent anywhere. You can also open a text file from your device, which is read locally.

Sources: Intl.Collator() constructor - MDN Web Docs (sensitivity, numeric, caseFirst), checked 13 October 2026 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator); Array.prototype.sort() - MDN Web Docs (stable since ECMAScript 2019; default order is by UTF-16 code units), checked 13 October 2026 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort); Unicode Technical Standard 10, Unicode Collation Algorithm (section 6.6: a sorts before A by default), checked 13 October 2026 (https://unicode.org/reports/tr10/); Natural sort order - Wikipedia (file1.txt, file2.txt, file10.txt example), checked 13 October 2026 (https://en.wikipedia.org/wiki/Natural_sort_order); Swedish alphabet - Wikipedia (the alphabet ends with z, å, ä, ö), checked 13 October 2026 (https://en.wikipedia.org/wiki/Swedish_alphabet)

Related tools:

- [Remove duplicate lines](https://hirantha.me/tools/remove-duplicate-lines.md): Remove duplicate lines from a list and see how many were removed. Keep the first or last copy, ignore case or spaces, or show only the repeated or only the unique lines.
- [Remove line breaks and extra spaces](https://hirantha.me/tools/remove-line-breaks.md): Join lines into one: replace line breaks with a space, comma or your own text, collapse extra spaces, keep paragraphs, and rejoin words split by hyphens in PDF text.
- [Diff checker](https://hirantha.me/tools/diff-checker.md): Compare two blocks of text and see what changed, line by line.
- [Text reverser](https://hirantha.me/tools/text-reverser.md): Reverse text by characters, words or lines without breaking emoji, accents or Sinhala and Tamil letters, and see how code points differ from UTF-16 units.
