🔧 TL3 Tools

Live demo (works without JavaScript):

Sample input — paste anything and watch the result update.
→ A–Z (case-insensitive)
Sample input — paste anything and watch the result update.

📋 Sort Lines

Written by Jane Smith · Reviewed by Alex Chen · July 26, 2026

Sort lines alphabetically ascending (A–Z) or descending (Z–A), with optional case-insensitivity.

Input

Output

What Ordering Text Lines Actually Means

A long list is far easier to scan when it runs in a predictable order, which is what this page provides: it takes the lines of a textarea, orders them with JavaScript's string comparison, and writes the sorted result back into the output panel. The same rules apply whether the list holds names, URLs, product codes, or keywords. Because the comparison happens locally, the sort works on private data without anything leaving the machine.

Following a Three-Line Sort

Take a three-line list of page numbers that mixes one-digit and two-digit values:

2
10
apple

Sorted as text, the number 10 lands before 2, because the first character 1 is smaller than the first character 2. The ascending output is:

10
2
apple

A numeric sort would instead produce 2, 10, apple, which is the order most people expect. Both results are sorted according to their own rules; this page orders them as text rather than as quantities. When the values matter as numbers, pad them to equal width, such as 02 and 10, or use a spreadsheet that understands numeric values.

A Second Example With Capitalization

Capitalization changes the order, and the case-insensitive option decides how much. Sort these three lines with the option on, which is the default:

Zebra
apple
Apple

The comparison runs on lowercased copies, so apple and Apple are treated as equal for ordering, and the stable sort keeps their original relative order. The output is apple, Apple, Zebra. Turn case-insensitive off and the raw code points take over: uppercase letters all sort before lowercase ones, so the result becomes Apple, Zebra, apple, because Z at code point 90 precedes a at code point 97. The same switch controls duplicate removal, so with the option off, apple and Apple survive as two distinct lines.

How the Comparison Works

The sort treats every line as plain text and compares it character by character, using the same less-than and greater-than logic JavaScript applies to strings. The first position where two lines differ decides which one comes first, and if one line is a prefix of the other, the shorter one comes first. The order is defined by Unicode code points rather than by the alphabet you learned in school, which is why uppercase letters precede lowercase ones and accented characters land at their raw positions. With the case-insensitive option on, the comparison is made on lowercased copies, so Apple and apple are treated as equal for ordering and for duplicate removal. The A to Z button sorts ascending, and the Z to A button runs the same comparison in reverse.

The Three Options and Their Defaults

The case-insensitive option is checked by default and orders without regard to capitalization, using lowercased copies for both the comparison and the duplicate check. The trim option is also on by default, so leading and trailing spaces on each line are removed before comparison, which keeps an indented line from sorting ahead of an identical clean one. The remove-duplicates option is off by default; when enabled, it keeps the first occurrence of each line and discards later copies. Although the label says the duplicate removal happens after sorting, the filter actually runs before the sort, and the final result is the same either way, because identical lines are adjacent regardless of when they are filtered.

Working With Duplicates and Trimmed Output

When the remove-duplicates option is on, the page keeps the first occurrence of each line and drops later copies. With case-insensitive on, which is the default, lines that differ only by capitalization are treated as the same line, so Apple, apple, and APPLE collapse to whichever came first in the input; the first occurrence wins regardless of its capitalization. With duplicate removal off, which is also the default, every line survives, and Apple and apple stay as two separate entries.

The trim option does more than influence the comparison: it rewrites each line in the output. Leading and trailing spaces are removed from the text that actually lands in the output panel, not just from the key used to order the lines. A list pasted with indentation therefore comes back clean, which is usually what you want. If the indentation carried meaning, such as in a hierarchical outline, the original file is the only place that structure still exists, so keep a copy before sorting.

Sorting Real-World Lists

Alphabetizing a tag list before publishing, ordering the options in a dropdown, or sorting two files so they can be diffed side by side are all good fits. An ecommerce manager sorting a list of product names for a catalog, a developer arranging configuration keys before comparing two environments, and a writer alphabetizing a bibliography all reach for the same operation. The trim option makes the tool forgiving of pasted lists that carry accidental indentation, and the duplicate option keeps a cleaned list from growing back when the source contained repeats. One caution: sorting a single column of a two-column table breaks the pairing between the halves, so paste both columns into one block separated by a common delimiter, sort, and split them apart again afterwards.

Lines That Sort in Surprising Spots

Lines that differ only in capitalization collapse to one when the case-insensitive option is on and stay separate when it is off. Empty lines sort to the front in ascending order, so delete them from the input if they are not wanted. Punctuation sorts before letters, which puts a line beginning with an exclamation mark ahead of one starting with a word. Accented characters are ordered by their raw code points, which rarely matches the alphabetical order of the language they come from. Version numbers like 1.9 and 1.10 also follow text rules, placing 1.10 first, and a leading zero such as 02 sorts before 2 the same way, because the digit 0 compares smaller than the digit 2. Numbers behave as text throughout, so 100 comes before 20, and 9 comes after 100.

When Text Sorting Is the Wrong Tool

The tool is not the right choice for numeric ranking, calendar ordering, or natural-language collation, because each of those needs a comparison rule the text sort does not implement. Sorting prices from highest to lowest, ordering dates by month, or sorting a German list so that ä sits with a all require logic beyond character comparison. A mixed list of words and numbers usually sorts more usefully after the numbers are padded or removed. For those cases a spreadsheet column with the proper type, or a language-aware sort in a real application, gives the expected result.

Questions People Ask About Sorting

Why does 10 come before 2?

The comparison walks the strings position by position, and the character 1 is smaller than the character 2, so any line starting with 1 precedes one starting with 2.

Does the tool sort numbers numerically?

No, every line is treated as text. Pad the values to equal width, such as 02 and 10, when numeric order matters.

What changes when I turn case-insensitive off?

Capitalization then decides the order, with uppercase letters sorting before lowercase, and Apple and apple become two separate lines.

Can I sort just one column of a CSV file?

Only whole lines are sorted. Split the columns in a spreadsheet first, or sort the data there and paste the result back.

Where do blank lines end up?

An empty line sorts to the top in ascending order, so remove blank lines from the input if they are not part of the list.

Does remove-duplicates keep the first or the last copy?

The first occurrence survives and later copies are dropped. The option is off by default and can be ticked together with case-insensitive to merge lines that differ only by capitalization.

Why did my indented lines come back without their indentation?

The trim option is on by default and removes leading and trailing spaces from every line in the output, so the result is clean even when the input was ragged. Turn the option off to keep the whitespace.

How many lines can I sort at once?

There is no practical limit. The whole textarea is compared in memory inside the browser, so even a list of several thousand lines returns the sorted result instantly.