📝 Text & Content Free Forever

Text Sorter, Sort Lines Alphabetically or by Length Free

This text sorter arranges any list of lines alphabetically, numerically, by length, or in random order, ascending or descending. Remove duplicates while sorting and copy the clean result in one click, no sign up needed.

Your Text
Sort Method
About This Tool

How this text sorter handles five sort methods, including two that understand numbers

Sorting lines alphabetically is a one line call to Array.prototype.sort. The interesting engineering in a line sorter is everything wrapped around that call: a natural sort mode that stops item10 from landing before item2, a numeric mode that orders lines by the value of their first number, a Fisher-Yates shuffle for genuine randomization, and a set of pre and post processing options that decide what counts as a line worth sorting in the first place.

Every sort runs client side in your browser and updates as you type or change an option. Your list is never uploaded.

The sort methods

Alphabetical Uses Intl.Collator, which sorts by linguistic rules for the user's locale rather than raw character codes. That means accented letters and mixed case sort the way a human expects, not by their underlying Unicode code point value.
Length Compares the number of characters you see in each line, so an emoji or accented letter counts once, shortest lines first with no consideration of content.
Natural Uses Intl.Collator with its numeric option, so runs of digits compare as whole numbers wherever they appear in the line. This is what correctly orders item2 before item10, where plain alphabetical sorting would put item10 first because the character 1 sorts before 2. Leading zeros and numbers too large for JavaScript are handled correctly.
Random Implements a Fisher-Yates shuffle fed by crypto.getRandomValues: walk the array backward from the last index, and at each position swap the current element with a randomly chosen element at or before it. This produces a uniformly random permutation, unlike naive shuffles built on sort(() => Math.random() - 0.5), which are known to be biased.

Numeric (by value) reads the first number in each line, including minus signs, decimals and thousands separators like 1,200, and sorts by its value, so -5.5, 3, 10 and 1,200 come out in that order. A dash glued to a word, as in file-10, is not treated as a minus sign. Lines without any number are listed last.

// alphabetical and natural comparators var col = new Intl.Collator(undefined, { numeric: isNatural, sensitivity: caseInsensitive ? 'accent' : 'variant', caseFirst: caseInsensitive ? undefined : 'upper' }); lines.sort(function(a, b){ return dir * col.compare(a.s, b.s) || a.i - b.i; });

A worked sort

Input lines: item10, item2, item1

MethodResult order
Alphabeticalitem1, item10, item2
Naturalitem1, item2, item10
Lengthitem1, item2, item10 (ties broken by original array order, since the comparator returns 0 for equal length)
Length sort is not stable across engines by contract, but it is in practice. When two lines tie in length, the comparator returns 0, and modern JavaScript engines including V8 guarantee a stable sort as of the ECMAScript 2019 specification, meaning tied elements keep their original relative order. Older engines were not required to guarantee this, so if you are running this logic somewhere with an ancient JavaScript engine, tie order was technically undefined.

Pre-processing options that run before any sort

Trim and keep empty lines

Trim strips leading and trailing whitespace from every line before sorting. Keep empty lines, if turned off, filters out any line that is empty after trimming, which changes both the sort input and the final line count.

Deduplicate and case insensitive

Dedupe runs a first-seen-wins pass using a Map before sorting starts, so even lines like constructor are handled. The case insensitive toggle affects two things: whether dedupe treats Apple and apple as the same key, and whether the sort treats them as equal. With it off, uppercase sorts before lowercase when the letters are the same.

Ascending or descending direction is applied inside the comparison, so lines that tie keep their original order in both directions. It is ignored for random order, and in numeric mode lines without a number stay at the end either way.

Alphabetical via Intl.Collator Natural and numeric sorts Length sort Fisher-Yates random shuffle

Sorting jobs in practice

Alphabetizing a guest list or works cited page, ordering file names like chapter2.txt and chapter10.txt the way a human would expect with natural sort, sorting survey responses by length to skim the shortest first, deduplicating and alphabetizing a mailing list before an export, and randomizing a list of raffle entries or quiz questions with the shuffle mode so nobody can claim the order was rigged.

Common Questions

FAQ: Text Sorter

Standard alphabetical sort compares text character by character, so "item10" comes before "item2" because it compares "1" against "2" at that position and stops there. Natural sort recognizes consecutive digits as a full number and compares those numbers as values, so "item2" correctly comes before "item10." Use natural sort for lists with version numbers, file names with numbers, or any sequence where numeric order matters.

Lines with the same length, counted in visible characters, keep their relative original order among themselves, in ascending and descending order alike, since this tool uses a stable sort, it only reorders lines when their lengths genuinely differ. This means length sorting won't shuffle items that happen to tie in length unpredictably.

It uses the Fisher-Yates shuffle algorithm, the standard, statistically unbiased method for randomizing a list, powered by your browser's cryptographic random number generator. It's suitable for raffles, random ordering, or breaking ties fairly.

No, case insensitivity only affects the comparison used to determine sort order, "Apple" and "apple" are treated as equivalent for ranking purposes, but each line's original capitalization is preserved exactly as you typed it in the final result.

You can paste CSV rows in and sort them as whole lines, which works well if you're sorting by the value that happens to be first on each line, but this tool sorts entire lines as single units, it doesn't understand or sort by a specific column within comma separated data. For column specific spreadsheet sorting, a dedicated spreadsheet tool is a better fit.

Yes, alphabetical and natural sorting use your browser's built in locale aware string comparison, which correctly places accented characters like é, ñ, or ü near their unaccented equivalents rather than lumping them all at the end of the alphabet, matching how dictionaries and most software sort them.

Yes, enable the "Remove duplicate lines while sorting" checkbox to deduplicate and sort in a single click, rather than running two separate tools. Duplicates are detected before sorting, so only unique lines make it into the final ordered result.

No, all sorting happens locally in your browser using JavaScript, nothing you paste is sent to a server, logged, or stored.