Sort Lines

Sort text lines alphabetically, numerically, by length, or in random order. Supports case-insensitive and reverse sorting.

Input
Sort Options
Sort by

Frequently Asked Questions

Numerical sort uses parseFloat() on each line to extract the number and sorts by that value. Lines that don't contain a leading number are treated as 0. This correctly sorts 2, 10, 20 (unlike alphabetical, which would give 10, 2, 20).
Yes. Modern JavaScript's Array.prototype.sort() is guaranteed to be stable in all current browsers. Lines with equal sort keys retain their original relative order.
The shuffle uses a Fisher-Yates algorithm with Math.random() for each swap. While sufficient for most use cases, it is not cryptographically secure — don't use it for security-critical applications.
Alphabetical sort compares characters left-to-right by their Unicode code points, so "10" sorts before "2" (because "1" comes before "2"). Numerical sort extracts the numeric value of each line, so 2 correctly sorts before 10. Always use numerical sort when dealing with numbers, version numbers, prices, or ranked data.
In case-sensitive mode, uppercase letters (A–Z) sort before lowercase letters (a–z) by Unicode value. In case-insensitive mode (the default), case is ignored during comparison so "apple", "Apple", and "APPLE" are treated as equivalent. Case-insensitive is usually the more intuitive result for word lists.
Natural sort order sorts strings containing numbers the way a human would: "file2.txt" before "file10.txt". Standard alphabetical sort gives "file10.txt" before "file2.txt" because "1" < "2" in character comparison. The numerical sort option handles many natural sort cases for lines that start with numbers.
Different languages have different alphabetical ordering rules. For example, in Swedish, "Å" comes after "Z"; in Spanish, "ñ" comes between "n" and "o". This tool uses a simple Unicode comparison, which works well for English but may not match expectations for sorting accented or non-Latin characters.
A stable sort preserves the original relative order of elements that compare as equal. All modern JavaScript engines use a stable sort, so this tool is stable. Stability matters when sorting by one key while preserving a previous sort order.
Select Length (shortest first) or Length (longest first) from the Sort by dropdown. Lines are sorted by their character count (after optional trimming). This is useful for finding the shortest or longest entries in a list, or ranking text by density.
Select Alphabetical (Z → A) or Numerical (9 → 0) from the Sort by dropdown to sort in descending order. For length, choose Length (longest first). You can also sort ascending then use the Text Reverser's "Reverse Lines" to flip the order.

About This Line Sorter

This free line sorter sorts the lines of any text alphabetically (A–Z or Z–A), numerically, or by line length. Options include case-insensitive sorting and removing blank lines before sorting — all processing happens in your browser.

When to use this tool

  • Alphabetising a list of names, keywords, or file paths
  • Sorting import statements, CSS properties, or config keys
  • Deduplicating and sorting a word list in one step
  • Organising log lines or data exports by a leading value

Standards & References

Related Articles

In-depth guides and technical articles.

View all →
Why Quicksort Fails When Data Doesn't Fit in RAM — External Merge Sort, Timsort, and Database Sort Optimisation
When data exceeds RAM, the bottleneck shifts from CPU comparisons to disk I/O — and quicksort's cache-friendly random access pattern becomes a liability while merge sort's sequential access pattern becomes an asset. Here's external merge sort's two-phase approach, why Timsort sorts nearly-sorted real-world data in close to O(n), how database query planners use B-tree index order to avoid explicit sort steps, and why `LC_ALL=C sort` produces different output than locale-aware sort on the same data.
Why Stable Sorting Matters — Multi-Key Composition, Algorithm Stability, and the JavaScript Array.sort Change
A stable sort preserves the relative order of equal elements — which enables multi-key sorting by composing stable sorts. Sort by amount first, then by date (stable): the final result is ordered by date, with amount order preserved within each date. Here's which algorithms are stable (merge sort, Timsort, insertion sort) vs unstable (quicksort, heapsort), why JavaScript's Array.sort stability changed in 2018, and why numbers stored as text sort "10" before "2".
Alphabetical Sort Order Isn't Universal: Locale Collation, Swedish Å, and Why Your Database Might Be Sorting Wrong
Alphabetical sort order isn't the same in every language — Swedish Å, Ä, Ö go at the end of the alphabet; German has two competing sort conventions for umlauts; Spanish ñ sits between n and o. Most sort tools and database defaults use Unicode code-point order, which is correct for English and wrong for nearly every other language. Here's what locale-sensitive collation actually is, how to configure it in SQL, JavaScript, and Python, and the case/accent-sensitivity dimensions on top of letter ordering.
Natural Sort vs Lexicographic: Why "file10 Before file2" Happens Differently in Every Language, Database, and File Manager
"file10" sorting before "file2" isn't a bug specific to one tool — it's the default lexicographic behavior across most programming languages, while file managers typically default to natural sort, creating a common mismatch. Here's how Python, JavaScript, SQL ORDER BY, and spreadsheets each handle this differently, and why version-number sorting (SemVer) is a related but distinct problem with its own rules.
Sort Orders Explained: Why "file10" Sorts Before "file2" and When It Matters
"file10" sorts before "file2" alphabetically — which is correct for strings but wrong for filenames. Here's natural sort vs lexicographic sort, locale-aware collation for multilingual names, multi-column SQL ORDER BY, and why stable vs unstable sort algorithms matter in practice.