Sort Lines

Sort lines alphabetically — A→Z by default, Z→A on second click. Case-insensitive comparison. Works on any line-separated text.

Example: banana apple cherryapple banana cherry

Sorts lines alphabetically using locale-aware comparison — accented letters cluster correctly with their unaccented forms, and embedded numbers sort numerically ("file2" before "file10"), not as raw strings. Default order is A→Z.

Useful for organising any line-separated list — names, email addresses, URLs, words, file names, log entries.

When you reach for this

Alphabetising name lists

Member rosters, contact lists, attendee names — sort once, paste back into your document.

Sorting URLs or domains

Group related domains together by paste-and-sort. The locale-aware comparison handles country TLDs sensibly.

Sorting code-style identifiers

Variable names, function names, file paths — natural sort handles "item1, item2, item10" correctly.

Reverse-alphabet exercises

Run forwards then reverse the lines (using Reverse Line Order) for Z→A.

Vocabulary or glossary work

Build an index of terms by pasting your draft and sorting; spot duplicates and gaps immediately.

What gets processed (and how)

The tool splits input text into an array using split(/\r?\n/) to handle both CRLF (Windows) and LF (Unix) line endings. Each line is then compared using JavaScript's Intl.Collator with sensitivity 'base' — this makes comparisons locale-aware so accented characters (e.g., é vs e) cluster correctly. Embedded numbers are parsed via a custom natural-sort algorithm that extracts numeric substrings and compares them numerically, so file2 comes before file10. The sorted array is joined back with \n (LF). For descending order, the comparator is reversed.

How to use it

  1. Paste or type your line-separated text into the input box.
  2. Choose sort order: A→Z or Z→A (toggle button).
  3. Click the Sort button to reorder the lines.
  4. Copy the sorted output from the result box.

Behavior on tricky inputs

Trailing newline
A trailing newline is ignored: the last empty line is not included in the sort.
Empty lines
Empty lines are treated as valid lines and sorted (they appear first in ascending order).
Whitespace-only lines
Lines containing only spaces or tabs are considered empty after trimming and sorted as such.

Workflow tips

  • Combine with Remove Duplicates to get a unique sorted list.
  • For log analysis, sort timestamps by prefixing with sort -k style but this tool sorts whole lines; pre-process to align fields.
  • Use ascending sort to alphabetize a list of URLs until they need to be grouped by domain.
  • Paste from a spreadsheet (tab-separated) but only the first column will sort — extract that column first.

vs other ways to do this

Compare this tool with two common alternatives for sorting lines: the Unix sort command and Excel's sort feature.

This toolsort(1) (Unix)Excel Sort
PlatformWeb browser (any OS)Unix/Linux/macOS terminalWindows/macOS (requires Excel)
Locale-awareYes (Intl.Collator)Needs locale flag (-l) or LC_ALLYes, but manual configuration
Natural sort of numbersBuilt-inVia -V (version sort)Not built-in; requires workarounds

Where this came from

The concept of sorting lines alphabetically originates from the Unix sort utility (1971, Bell Labs) which used a merge sort on line-based text. The natural-sort extension was popularized by Mac OS X Finder's file sorting and later by libraries like natsort. This web tool brings that functionality to the browser without a terminal or external software.

Common questions

Is the sort case-sensitive?

No — case-insensitive by default. "Apple" and "apple" are sorted as equal. For case-sensitive sorting, paste through a locale-aware sort in your terminal.

How are numbers sorted?

Naturally — "item2" comes before "item10". Pure-string sort would put "item10" first because '1' < '2'; we use locale-aware natural sort to match human expectations.

How do I sort Z→A instead?

Run sort, then run the result through Reverse Line Order. Two clicks total.

Does it sort accented characters correctly?

Yes — the JavaScript locale-aware comparator uses your browser's collation rules. "café" sorts near "cafe", "über" near "uber".

Embed our tools on your website

Free for any site. No signup. Iframe loads from our servers and stays up-to-date automatically.

📋 Embed the Word Counter

Copy this snippet:

Live preview:

📋 Embed this Sort Lines

Copy this snippet:

Live preview:

Want more options? All embeddable tools →