Skip to main content
ToolsHub

Sort Text Lines

Paste a list and instantly sort it A–Z, Z–A, or numerically. Toggle case sensitivity, remove duplicates, and trim whitespace — all in your browser.

Updated

Files never leave your browser

Sorted output will appear here

Paste lines on the left to see them sorted.

How to use Sort Text Lines

Sort lines of text alphabetically, numerically, or in reverse order entirely in your browser — no data leaves your device. Paste any list and choose from multiple sort modes including natural sort (so "item10" correctly follows "item9"), case-insensitive comparison, whitespace trimming, and duplicate removal. Ideal for sorting word lists, log entries, CSV rows, reference lists, or any numbered inventory.

  1. Paste your list or multi-line text into the input area (one item per line).
  2. Choose a sort order: A–Z, Z–A, numerical ascending, or numerical descending.
  3. Toggle "Natural sort" to sort numbered items in human-readable order (item2 before item10).
  4. Toggle "Case insensitive" to treat uppercase and lowercase letters as equal during comparison.
  5. Optionally enable "Remove duplicates" and "Trim whitespace" for a cleaner output.
  6. Click "Sort Lines" — the sorted output appears instantly.
  7. Copy or download the sorted list.

Your data never leaves your device — 100% private processing.

Lexicographic vs natural sort

Lexicographic (alphabetical) sort compares strings character by character using Unicode code point values. This produces correct results for plain words but counterintuitive results for strings containing numbers: "item10" sorts before "item2" because the character "1" (U+0031) has a lower code point than "2" (U+0032). Natural sort — also called human sort — recognises embedded numeric substrings and compares them as integers rather than character sequences, placing "item2" before "item10". Natural sort is essential for filenames, version numbers (v1.9 before v1.10), and any list where numbers appear within alphabetic strings.

Lexicographic vs natural sort comparison
Input itemsLexicographicNatural sort
item1, item10, item2item1, item10, item2item1, item2, item10
v1.9, v1.10, v1.2v1.10, v1.2, v1.9v1.2, v1.9, v1.10
file20, file3, file100file100, file20, file3file3, file20, file100

Stable sort and multi-key ordering

A stable sort preserves the original relative order of elements that compare as equal. If two lines — "Apple" and "apple" — are considered equal under case-insensitive comparison, a stable sort keeps them in their original input order, while an unstable sort may swap them arbitrarily. Modern JavaScript's Array.prototype.sort() has been guaranteed stable since ECMAScript 2019, meaning all major browsers now produce consistent results. Stable sorting is important when applying multiple passes — for example, first sorting by category and then by name — because each pass preserves the ordering achieved by the previous one.

Worked examples

Alphabetical A–Z

Inputs: banana / apple / cherry

Result: apple / banana / cherry

Natural sort

Inputs: item10 / item2 / item1

Result: item1 / item2 / item10

Numeric descending

Inputs: 3 / 20 / 100

Result: 100 / 20 / 3

Glossary

Lexicographic order
Alphabetical ordering that compares strings character by character using Unicode code point values; the default sort behaviour in most programming languages.
Natural sort
A sort algorithm that treats embedded numeric substrings as integers rather than character sequences, producing human-readable ordering for alphanumeric strings.
Stable sort
A sorting algorithm that preserves the original relative order of elements that compare as equal, enabling reliable multi-key sorting.
Collation
The rules for comparing and ordering strings in a specific language or locale, accounting for accents, case, and locale-specific character ordering.
ASCII order
The ordering of characters by their ASCII code point values; digits (48–57) sort before uppercase letters (65–90), which sort before lowercase letters (97–122).

Related reading

Free · No spam

Get weekly tool tips & updates

New tools, power-user tips, and productivity hacks — delivered free every Friday.

No spam, ever. Unsubscribe with one click.

Related Text Tools

Explore all Text Tools.