Skip to content

Sort Text Lines Alphabetically & Naturally

Sort text lines alphabetically, numerically (natural order), or by length — ascending or descending. Free online line sorter, 100% in your browser. Also dedupe, reverse, and clean up lists. No signup, nothing uploaded.

No Tracking Runs in Browser Free
All processing happens locally in your browser. No data is sent to any server.
Sort
Deduplicate
Clean up
Reviewed for natural-sort correctness, locale-aware collation, case-sensitivity behavior, deterministic pipeline order, and accurate line-count statistics — Go Tools Engineering Team · Jul 13, 2026

What Does Sorting Text Lines Mean?

Sorting text lines means taking a block of text split on newlines and reordering those lines according to a rule — most commonly alphabetical (dictionary) order, but also numeric order, length, or reverse. It is one of the most frequent small tasks in a developer's or writer's day: alphabetizing a list of names, ordering import statements, tidying a column of tags copied from a spreadsheet, or arranging config keys so a diff stays clean.

The subtlety that trips people up is that computers sort strings by character code by default, not by human intuition. A plain sort places `item10` before `item2` because the character `1` has a lower code point than `2`. It also pushes every capitalized word ahead of lowercase ones, so `Zebra` lands before `apple`. Real-world lists rarely want either behavior. This tool defaults to case-insensitive, locale-aware sorting and offers a Natural method that compares embedded numbers as numbers — the two settings that make sorting match what a human expects.

Sorting is closely related to cleaning a list. You often want to sort and deduplicate together, or drop blank lines and stray whitespace in the same pass. This tool folds those operations into one panel: sort, remove duplicates, trim, remove empty lines, reverse, and even shuffle. For deduplication as the primary task — with control over keeping the first or last occurrence — reach for the companion Remove Duplicate Lines tool, which shares the same engine. To count words and lines, use the Word Counter; to compare two versions of a list, use Text Diff; and to change the casing of your lines, use the Case Converter.

Everything happens entirely in your browser with no uploads, so sorting a confidential list is exactly as private as opening a text editor. Paste, choose an order, and copy the result — the whole round trip takes a couple of seconds.

Input (unsorted):
  file10.txt
  file2.txt
  file1.txt

Alphabetical sort (naive):
  file1.txt
  file10.txt   ← wrong: 10 before 2
  file2.txt

Natural sort (numeric-aware):
  file1.txt
  file2.txt
  file10.txt   ← correct

Key Features

Alphabetical, Natural & Length Sorting

Three sort methods cover every list: Alphabetical dictionary order, Natural sort that keeps `item2` before `item10` by comparing numbers as numbers, and By length for shortest-to-longest. Each works ascending or descending.

Locale-Aware Collation

Sorting uses the browser's `Intl.Collator`, which follows the Unicode Collation Algorithm. Accented and non-English characters sort the way a reader of your language expects — `é` next to `e`, not dumped at the end of the alphabet.

Case-Insensitive by Default

`Apple` and `apple` sort as neighbors instead of all-caps words jumping to the top — the natural choice for human lists. Flip on Case-sensitive when uppercase and lowercase must be treated as distinct.

Sort + Deduplicate in One Pass

Turn on Remove duplicate lines to get a clean, unique, sorted list in a single step. The live stats badge reports exactly how many duplicates were collapsed so you can trust the result.

Live Line Counts

A stats badge updates as you type: `12 lines → 9 lines · 3 duplicates removed · 0 empty removed`. No guessing whether the tool actually changed anything — you see the before and after instantly.

Reverse & Shuffle

Reverse flips the current order without re-sorting; Shuffle randomizes lines with a cryptographic Fisher–Yates shuffle. Randomize quiz questions, pick a draw order, or invert a changelog in one click.

Clean-Up Toggles

Trim each line, remove empty lines, and add line numbers round out the panel. Compose them with sorting to turn a messy pasted column into tidy, publish-ready output without a script.

100% Browser-Based Privacy

Your text never leaves the page — no uploads, no logging, no analytics on what you type. Safe for confidential lists, internal wordlists, and sensitive exports. Verify it yourself in the Network tab: zero requests.

Sort Lines Examples

Alphabetical A→Z

banana
apple
cherry
apple
banana
cherry

The default sort: ascending, alphabetical, case-insensitive. Dictionary order for a simple list of words — the most common use for sorting a column of names, tags, or keywords.

Descending Z→A

apple
banana
cherry
cherry
banana
apple

Set order to Descending to reverse the alphabetical direction. Useful for leaderboards, most-recent-first lists, or any ranking where the last item alphabetically should come first.

Natural sort (numeric-aware)

item10
item2
item1
item1
item2
item10

Natural sort compares the embedded numbers as numbers, so `item2` stays before `item10`. A plain alphabetical sort would wrongly put `item10` first because the character `1` sorts before `2`. Essential for filenames, versions, and numbered rows.

Sort by length

ccc
a
bb
a
bb
ccc

The By length method orders lines from shortest to longest, breaking ties alphabetically. Handy for spotting outliers, aligning fixed-width data, or arranging tag lists from short to long.

Case-insensitive sort

banana
Apple
apple
Apple
apple
banana

With Case-sensitive off (the default), `Apple` and `apple` sort as neighbors instead of all-uppercase words jumping to the top. This is almost always what you want for human-readable lists.

Sort and remove duplicates together

dog
cat
dog
bird
cat
bird
cat
dog

Turn on Remove duplicate lines while sorting to get a clean, unique, ordered list in one step. The stats badge reports `5 lines → 3 lines · 2 duplicates removed` so you can verify what was collapsed.

Reverse the current order

line one
line two
line three
line three
line two
line one

Reverse order flips the final list without sorting alphabetically — it simply inverts the existing sequence. Combine it with a sort for descending results, or use it alone to reverse a log or changelog.

Shuffle (randomize) a list

north
south
east
west
east
north
west
south

Shuffle randomizes line order using the browser's cryptographic RNG (Fisher–Yates). Great for randomizing quiz questions, picking a random draw order, or sampling. The output differs every time you toggle it.

How to Sort Text Lines

  1. 1

    Paste or type your lines

    Drop your text into the input box. Each newline is treated as a separate line. Sorting runs instantly as you type — there is no submit button. A trailing newline is ignored so it won't add a blank row.

  2. 2

    Choose an order and method

    Set Order to Ascending (A→Z) or Descending (Z→A), then pick a Method: Alphabetical for words, Natural for anything with numbers, or By length. The output updates the moment you change a setting.

  3. 3

    Add clean-up options if needed

    Toggle Remove duplicate lines, Trim each line, or Remove empty lines to tidy the list while sorting. Turn on Case-sensitive only when uppercase and lowercase must be treated as different.

  4. 4

    Check the stats badge

    The badge shows lines in, lines out, and how many duplicates or empty lines were removed. Use it to confirm the tool did what you expected before you copy the result.

  5. 5

    Copy the sorted result

    Click Copy to put the sorted output on your clipboard. Use Reset to clear both boxes, or Sample to load an example list to experiment with. Nothing is uploaded at any point.

Common Sorting Mistakes

Naive Alphabetical Sort on Numbered Items

The classic mistake: sorting filenames or versions alphabetically so `10` lands before `2`. The fix is to switch the method to Natural, which compares embedded numbers as numbers. Always check numbered lists after sorting — the wrong method looks plausible until you notice `item10` above `item2`.

✗ Wrong
Alphabetical:
  release-1
  release-10
  release-2
✓ Correct
Natural:
  release-1
  release-2
  release-10

Case-Sensitive Sort Scattering a Human List

Leaving Case-sensitive on for a list of names pushes every capitalized entry ahead of lowercase ones, splitting what should be one alphabetical run into two. Unless case is semantically meaningful, keep it off so `Apple` and `apricot` sit next to each other.

✗ Wrong
Case-sensitive:
  Apple
  Banana
  apple
  banana
✓ Correct
Case-insensitive:
  Apple
  apple
  Banana
  banana

Whitespace Defeating the Sort

Lines with trailing spaces or tabs sort differently from their trimmed twins because the whitespace is part of the string. If two visually identical lines end up apart, enable Trim each line to strip surrounding whitespace before sorting.

✗ Wrong
Untrimmed ("apple " vs "apple"):
  apple
  banana
  apple    ← trailing space, sorts oddly
✓ Correct
Trimmed:
  apple
  apple
  banana

Expecting Reverse to Sort Descending

Reverse order simply inverts the current sequence — it does not sort. If the list wasn't sorted, reversing gives you the input backwards, not Z→A order. To sort descending, set Order to Descending; use Reverse only to flip an already-ordered list.

✗ Wrong
Reverse on unsorted input:
  cat
  apple
  banana
→ banana / apple / cat (just backwards)
✓ Correct
Descending sort:
  cat
  banana
  apple

Sort Text Lines: Common Use Cases

Alphabetize Names, Tags & Keywords
Paste a column of names, tags, or SEO keywords copied from a spreadsheet and get them in clean dictionary order. Add Remove duplicate lines to collapse repeats from a messy export in the same step.
Order Import Statements & Config Keys
Sort a block of import lines or configuration keys so they stay in a canonical order and future diffs stay small. Natural sort keeps numbered items (`v1`, `v2`, `v10`) in the right sequence.
Sort Filenames & Version Strings
Filenames and semantic versions are where naive sorting fails hardest — `v1.10` before `v1.2`. Natural sort fixes it, giving you a correctly ordered list for release notes, manifests, or build scripts.
Tidy Security Wordlists
Sort and deduplicate password wordlists, subdomain lists, or fuzzing dictionaries entirely offline. Because nothing is uploaded, sensitive security data never touches a third-party server.
Organize CSV Columns
Copy a single column out of a CSV, sort it, remove duplicates, and paste it back. Faster than a spreadsheet formula for a one-off cleanup, and the live count confirms how many rows collapsed.
Randomize a Draw or Quiz Order
Use Shuffle to randomize the order of names for a fair draw, questions for a quiz, or items for blind review. The cryptographic RNG makes the randomness defensible, not a predictable pseudo-shuffle.
Prepare Data for a Clean Diff
Sorting two lists the same way before comparing them makes a diff reflect real content changes instead of order noise. Pair this tool with Text Diff to spot exactly what was added or removed.
Reverse Logs & Changelogs
Use Reverse order to flip a log or changelog so the newest entries appear first (or last), without re-sorting alphabetically. A one-click alternative to piping through `tac` on the command line.

How the Sorting Works

Line Splitting (CRLF / LF / CR)
Input is split on `\r\n`, `\r`, or `\n`, so text pasted from Windows, Unix, or classic Mac sources all work. A single trailing line terminator is stripped first so a final newline doesn't create a spurious empty last line.
Intl.Collator Ordering
Alphabetical and natural sorts use `Intl.Collator(locale, { numeric, sensitivity })`. `numeric: true` enables natural (numeric-aware) comparison; sensitivity is `variant` when Case-sensitive is on and `accent` (case-insensitive) otherwise. Collation follows the Unicode Collation Algorithm.
Natural Sort Semantics
Natural sort compares maximal runs of digits as integers rather than character by character, so `a2` < `a10`. It handles digits embedded anywhere in the line, which is why filenames and version strings sort intuitively rather than lexically.
By-Length Sort with Tie-Break
The By length method orders lines by character count ascending, then breaks ties with the collator so equal-length lines still fall into a stable alphabetical order. Descending flips the final direction.
Deterministic Pipeline Order
Operations always apply in a fixed order: trim each line → remove empty → deduplicate → sort or shuffle → reverse → add line numbers. This makes the output predictable regardless of which toggles you combine.
Cryptographic Shuffle
Shuffle uses a Fisher–Yates algorithm seeded by `crypto.getRandomValues`, giving a uniform, unpredictable permutation. It is mutually exclusive with sorting — enabling Shuffle bypasses the collator entirely.
Stable, In-Browser Sort
JavaScript's `Array.prototype.sort` is guaranteed stable in modern engines, so lines the collator considers equal keep their original relative order. All computation happens on the main thread in your browser with no workers or network calls needed for typical list sizes.

Sorting Best Practices

Use Natural Sort for Anything with Numbers
If your lines contain numbers — filenames, versions, invoice IDs, numbered steps — choose the Natural method. Alphabetical sort will place `10` before `2` and quietly scramble the sequence. Natural sort is the single most important setting to get right, and it costs nothing to enable.
Keep Case-Insensitive for Human Lists
Leave Case-sensitive off for names, tags, and prose lists so capitalized words don't jump ahead of lowercase ones. Only turn it on for case-significant data like identifiers where `ID` and `id` are genuinely different values.
Sort Both Lists the Same Way Before Diffing
When comparing two lists, sort each with identical settings first. A diff of two unsorted lists is dominated by order changes; a diff of two sorted lists shows only real additions and removals. Pair this tool with Text Diff for the cleanest comparison.
Deduplicate While You Sort
If a list might contain repeats, enable Remove duplicate lines in the same pass rather than sorting first and hunting for duplicates by eye. The stats badge tells you how many were collapsed, so you never have to wonder whether the list is truly unique.
Trim Before You Sort Pasted Data
Text copied from spreadsheets, PDFs, or terminals often carries trailing spaces that make otherwise-identical lines sort apart or survive deduplication. Turn on Trim each line to normalize whitespace before sorting so the order reflects content, not invisible characters.
Use Shuffle's Crypto RNG When Fairness Matters
For draws, sampling, or anything where a predictable order could be gamed, Shuffle's cryptographic randomness is preferable to eyeballing or to a `Math.random`-based tool. Re-toggle it to reshuffle if you want a fresh order.

Frequently Asked Questions

What does this tool do?
It sorts lines of text right in your browser — alphabetically, in natural (numeric-aware) order, or by length, ascending or descending. As you paste or type, the sorted result appears instantly with a live count of lines in and out. You can also deduplicate, reverse, trim, remove empty lines, add line numbers, or shuffle in the same pass. Nothing is uploaded: all sorting runs 100% client-side in JavaScript, so it is safe for confidential lists, internal wordlists, and any data you would not want to send to a server. You can confirm this in your browser's Network tab — sorting triggers zero network requests.
What's the difference between alphabetical and natural sort?
Alphabetical (lexical) sort compares strings one character at a time, so `file10` comes before `file2` because the character `1` (U+0031) sorts before `2` (U+0032). Natural sort recognizes runs of digits and compares them as numbers, so `file2` correctly precedes `file10`. Use alphabetical for plain words and codes; use natural for anything with embedded numbers — filenames, version tags (`v1.2` vs `v1.10`), invoice numbers, and numbered list items. This tool implements natural sort with `Intl.Collator({ numeric: true })`, the standards-based Unicode collation built into every modern browser.
How do I alphabetize a list?
Paste your list, keep the default Ascending order with the Alphabetical method, and the lines are put in alphabetical order (A→Z) instantly — that's all it takes to alphabetize a list online. For names, tags, or keywords, leave Case-sensitive off so capitalized and lowercase entries sort together instead of splitting into two runs. Switch to Descending for Z→A, or enable Remove duplicate lines to alphabetize and dedupe in one step. Everything runs in your browser, so you can put even a confidential list in alphabetical order without uploading it.
Is my text uploaded anywhere?
No. Every operation — sorting, deduplication, trimming, reversing — runs entirely in your browser using JavaScript. Your text is never transmitted, never stored on any server, never logged, and never analyzed. This makes the tool safe for confidential lists, internal data, security wordlists, and any content you would not paste into a networked service. There are no cookies used for your input and no third-party analytics that capture what you type. Open your browser's developer tools and watch the Network tab: sorting a million-line list produces zero requests.
How do I sort a list of numbers correctly?
Choose the Natural method. Plain alphabetical sort treats numbers as text, so `100` would sort before `2` (because `1` < `2` as characters). Natural sort compares the numeric value, giving `2`, `100` in the right order. For lines that mix text and numbers like `chapter 2` and `chapter 12`, natural sort also gets it right by comparing the `2` and `12` numerically. If your lines are purely numeric and you want strict numeric ordering, natural sort handles integers and the numeric portions of mixed strings; for decimal-heavy financial data, double-check edge cases like leading zeros.
Does sorting respect uppercase and lowercase?
By default, no — Case-sensitive is off, so `Apple` and `apple` are treated as equivalent for ordering and sort as neighbors. This is the natural choice for human-readable lists, where you rarely want all capitalized words to jump ahead of lowercase ones. Turn Case-sensitive on to get a strict ordering where uppercase letters sort before lowercase (following Unicode code-point order within the collator's variant sensitivity). Case sensitivity also affects deduplication when that option is enabled: with it off, `Foo` and `foo` count as the same line.
Can I sort and remove duplicates at the same time?
Yes. Enable Remove duplicate lines alongside any sort order. The tool deduplicates first, then sorts, so you get a clean, unique, ordered list in a single step — and the stats badge reports how many duplicates were removed. This is the fastest way to turn a messy pasted column (say, a list of emails or tags with repeats) into a tidy sorted set. If you need the dedicated deduplication workflow with keep-first/keep-last control, use the companion Remove Duplicate Lines tool, which shares the same engine.
What happens to blank lines when I sort?
By default, blank lines are kept and sort to the top (an empty string sorts before any non-empty line). If you don't want them, enable Remove empty lines to drop blank and whitespace-only lines before sorting — the stats badge counts how many were removed. A single trailing newline at the end of your input (common when pasting from files or editors) is treated as a line terminator, not an extra empty line, so it won't inflate your counts or add a spurious blank row to the output.
How are accented and non-English characters sorted?
Sorting is locale-aware through the browser's `Intl.Collator`, which follows the Unicode Collation Algorithm. Accented letters are ordered the way a reader of your language expects — for example, in most Latin locales `é` sorts next to `e` rather than at the end of the alphabet. The tool uses the page's language for collation, so the German, French, Spanish, and other localized versions apply the appropriate rules. This is far more correct than a naive code-point sort, which would scatter accented and non-ASCII characters in surprising places.
Is there a limit on how many lines I can sort?
There is no hard limit imposed by the tool — it is bounded only by your browser's memory and how much text you can comfortably paste into a textarea. Modern browsers sort tens of thousands of lines instantly and hundreds of thousands with a brief pause. Because everything runs locally with no network round-trips, large lists are often faster here than on server-based tools that upload your data. For truly massive files (millions of lines), a command-line `sort` utility will be more comfortable, but for everyday lists, wordlists, and exports this tool handles them with ease.
How is this different from sorting in Excel or a code editor?
Spreadsheets sort cells within a grid and often reorder entire rows; this tool sorts a flat list of lines, which is exactly what you need for wordlists, config values, import statements, or any newline-separated data. Compared with a code editor's sort-lines command, this tool adds natural (numeric-aware) sorting, locale-aware collation, one-click deduplication, length sorting, and a live count — without installing an extension. And unlike online spreadsheet tools, nothing leaves your browser. It is the quickest way to sort a chunk of text when you just have it on the clipboard.
What does the Shuffle option do?
Shuffle randomizes the order of your lines using a Fisher–Yates shuffle driven by the browser's cryptographic random number generator (`crypto.getRandomValues`), so the result is genuinely unpredictable and different each time. It is mutually exclusive with sorting — you either order the lines or randomize them. Common uses include randomizing quiz or flashcard order, choosing a fair draw sequence, sampling a subset, or de-biasing a list before manual review. Because it uses a cryptographic RNG rather than `Math.random`, it is suitable when you need defensible randomness.

Related Tools

View all tools →

Case Converter — UPPERCASE, lowercase, camelCase & More

Text Processing

Convert text between UPPERCASE, lowercase, Title Case, Sentence case, camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE and 6 more formats instantly. Free, browser-only, no signup.

Lorem Ipsum Generator — Free Placeholder Text Tool

Text Processing

Generate Lorem Ipsum placeholder text instantly — by paragraph, sentence, word, byte, or list. Copy or download as plain text, HTML, Markdown, or JSON. 100% free, private, in-browser. No sign-up.

Free Regex Tester — Debug & Match Patterns Online

Text Processing

Test regex patterns instantly against any text. Live match highlighting, capture groups, replace preview, split, and pattern explainer. JavaScript-flavor regex, 100% private, no signup.

Remove Duplicate Lines from Text

Text Processing

Remove duplicate lines from text online — free, instant, 100% in your browser. Ignore case or whitespace, keep first or last occurrence, and see how many duplicates were removed. Also sort and clean up. No signup.

URL Slug Generator — Slugify Any Text

Text Processing

Slugify any title into a clean, SEO-friendly URL slug instantly. Transliterate accents and Cyrillic, or keep Unicode letters. 100% private, in your browser.

Text Diff & Compare

Text Processing

Compare two texts instantly in your browser. Side-by-side view with inline word-level highlights, unified-diff export, ignore case / whitespace / blank lines. 100% private — your text never leaves your device.