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.
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
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
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
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
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
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`.
Alphabetical: release-1 release-10 release-2
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.
Case-sensitive: Apple Banana apple banana
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.
Untrimmed ("apple " vs "apple"):
apple
banana
apple ← trailing space, sorts oddly 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.
Reverse on unsorted input: cat apple banana → banana / apple / cat (just backwards)
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?
What's the difference between alphabetical and natural sort?
How do I alphabetize a list?
Is my text uploaded anywhere?
How do I sort a list of numbers correctly?
Does sorting respect uppercase and lowercase?
Can I sort and remove duplicates at the same time?
What happens to blank lines when I sort?
How are accented and non-English characters sorted?
Is there a limit on how many lines I can sort?
How is this different from sorting in Excel or a code editor?
What does the Shuffle option do?
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.