Text Sorter, Sort Lines Alphabetically Free

📝 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 four sort methods, including one that understands 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 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 the moment you click generate. Your list is never uploaded.

The four sort methods

Alphabetical Uses String.prototype.localeCompare, 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 A direct numeric comparator, a.length - b.length, sorting shortest lines first with no consideration of content.
Natural Splits each line into alternating chunks of digits and non-digits using /(\d+)|(\D+)/g, then compares chunk by chunk: numeric chunks compare as numbers, text chunks compare with localeCompare. This is what correctly orders item2 before item10, where plain alphabetical sorting would put item10 first because the character 1 sorts before 2.
Random Implements a Fisher-Yates shuffle: 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.
// natural sort comparator, unchanged from the tool source function naturalCompare(a, b){ var ax = [], bx = []; a.replace(/(\d+)|(\D+)/g, function(_, num, str){ ax.push([num||Infinity, str||]); }); b.replace(/(\d+)|(\D+)/g, function(_, num, str){ bx.push([num||Infinity, str||]); }); while (ax.length && bx.length){ var an = ax.shift(), bn = bx.shift(); var nn = (an[0]-bn[0]) || an[1].localeCompare(bn[1]); if (nn) return nn; } return ax.length – bx.length; }

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 lookup object before sorting even starts. The case insensitive toggle affects two independent things: whether dedupe treats Apple and apple as the same key, and whether the sort comparator itself lowercases both sides before comparing.

Ascending or descending direction is applied last, as a plain .reverse() call on the already sorted array, for every method except random, where reversing a random order is meaningless and is skipped.

Alphabetical via localeCompare Natural number-aware sort 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 character length keep their relative original order among themselves, 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 built in random number generator. It’s suitable for randomizing lists for raffles, random ordering, or breaking ties fairly, though it’s not intended for cryptographic security purposes.

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.

Privacy Overview

Cookies let this site remember your preferences and show us which tools people actually use. Full detail sits in our Privacy Policy.