Sort Lines

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

Input
Sort Options

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 (V8, SpiderMonkey, JavaScriptCore). 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. Use the Random String Generator for cryptographic randomness.

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 and sorts by that value, 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, so "Banana" would sort before "apple". In case-insensitive mode (the default), case is ignored during comparison so "apple", "Apple", and "APPLE" are treated as equivalent and sorted by their lowercase form. 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. Natural sort is important for file names, version strings (v1.2 vs v1.10), and chapter numbering. The numerical sort option in this tool 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". JavaScript's localeCompare() method can sort text according to a specific locale's rules. 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. For example, if "apple" appears on lines 3 and 7 and both sort as equal, a stable sort ensures line 3's "apple" comes before line 7's "apple" in the output. 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, formatting data with predictable widths, identifying outlier-length records, or ranking text by density. Lines of equal length retain their relative order (stable sort).

Select Alphabetical (Z → A) or Numerical (9 → 0) from the Sort by dropdown to sort in descending order. For length, choose Length (longest first). Reverse alphabetical sort is useful when you want the most recent timestamp (Z-sorted) at the top, or the highest version number first. You can also sort ascending and 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

How It Works

Paste Your List

Paste any newline-separated list into the input area. Each line is treated as a sortable item.

Choose Sort Method

Select from alphabetical, reverse alphabetical, numerical, by line length, or shuffle. Set case sensitivity and trimming options.

Copy the Result

Click Sort to apply the chosen method. The sorted output appears instantly and can be copied to the clipboard.

Common Use Cases

Alphabetize Lists

Sort bibliographies, reference lists, glossary entries, or ingredient lists alphabetically for consistent, professional formatting.

Sort Numeric Data

Sort version numbers, IDs, prices, or quantities from exported reports numerically — without needing a spreadsheet.

CSS Property Ordering

Alphabetically sort CSS properties within a selector to enforce consistent style ordering as required by some team style guides.

Randomize Survey Options

Shuffle answer choices for surveys or quizzes to reduce order bias before pasting into your form builder.

De-duplicate & Sort Together

Enable "Remove blank lines" to clean a list while sorting, combining two operations in a single run.

Sort by Line Length

Sort lines by character length to find the shortest or longest entries in a dataset — useful for truncating labels or finding outliers.

Related Articles

View all articles
Alphabetical Sort Order Isn't Universal: Locale Collation, Swedish Å, and Why Your Database Might Be Sorting Wrong

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.

Jun 17, 2026
Natural Sort vs Lexicographic: Why "file10 Before file2" Happens Differently in Every Language, Database, and File Manager

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.

Jun 14, 2026
Sort Orders Explained: Why "file10" Sorts Before "file2" and When It Matters

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.

Jun 10, 2026
Sorting Algorithms Explained: Why the Choice Matters at Scale

Sorting Algorithms Explained: Why the Choice Matters at Scale

Bubble sort handles 1,000 items fine but takes hours on 1 million. Quicksort handles both in milliseconds. Here's how common sorting algorithms actually work, why O(n log n) is the comparison sort lower bound, and what TimSort is doing inside Python and Java.

Jun 10, 2026
Sort Lines — Sort Any List Alphabetically, Numerically, or by Length

Sort Lines — Sort Any List Alphabetically, Numerically, or by Length

Learn how to sort any text list alphabetically, numerically, by length, or randomly, why numerical sort differs from alphabetical for numbers, and how to use a free sort lines tool for any list.

Jun 6, 2026