Text Tools
Sort Lines - Sort Text Lines Online
Sort lines of text alphabetically, numerically, by length, or randomly. Ascending or descending, case-insensitive or case-sensitive. Free and runs entirely in your browser.
When to sort lines of text
Sorting lines is a surprisingly common task: alphabetising a list of names, putting import statements in order, ranking items by length, or simply randomising a list to remove bias. A dedicated tool saves the effort of copy-pasting into a spreadsheet or writing a one-off script.
Sort methods explained
- Alphabetical: the default. Lines are sorted lexicographically using the browser's built-in locale-aware comparison. Works well for any language.
- Numeric: lines are compared by their leading numeric value. "2" sorts before "10" (unlike alphabetical, where "10" would come first). Non-numeric lines are sorted after all numeric lines.
- By length: shorter lines first (ascending) or longer lines first (descending). Lines of equal length are sub-sorted alphabetically.
- Random (shuffle): randomises the order of lines using the browser's
Math.random(). Useful for creating randomised quizzes, picking a random winner from a list, or removing presenter bias from a slide order.
Case sensitivity
In case-insensitive mode (the default), "Apple", "apple", and "APPLE" sort to the same position. In case-sensitive mode, uppercase ASCII letters (A–Z) sort before their lowercase equivalents (a–z), so "Apple" sorts before "banana".
Trim whitespace option
When enabled, leading and trailing spaces are stripped from each line before comparing, but the original line (including its spaces) is preserved in the output. This is useful when pasting from sources that add inconsistent indentation.
Natural sort (file ordering)
Standard alphabetical sorting treats strings character by character, which produces counter-intuitive results for filenames and numbered sequences: "file10" sorts before "file2" because "1" < "2" in ASCII. Natural sort fixes this by comparing embedded numeric substrings as integers, so "file2" sorts before "file10". This tool's Numeric sort mode applies this logic to leading numbers; many text editors and file explorers use natural sort for their listings.
Locale-aware sorting
Different languages have different collation rules. Swedish treats Å, Ä, Ö as distinct letters
that sort after Z. German sorts ä as equivalent to ae in traditional collation. The browser's Intl.Collator API handles these rules when locale-aware sorting is enabled. Without
locale awareness, characters are compared by Unicode code point - which often mispredicts the intended
order for non-English text.
Deduplication
To remove duplicate lines after sorting, use the Remove Duplicate Lines tool. Sorting first (which places duplicates adjacent to each other) makes deduplication more predictable.