Sort Lines Alphabetically
What This Tool Does
This tool sorts lines of text using one of several methods: alphabetical (A–Z or Z–A), numeric (for lists of numbers), by line length, or reverse the original order. Options include case-sensitive sorting, removing duplicates, and locale-aware comparison for accented characters.
Inputs Explained
- Source Text: Paste any multi-line text — one item per line.
- Sort Method: Alphabetical A-Z, Z-A, numeric ascending/descending, by length, or reverse order.
- Case Sensitive: When checked, uppercase letters sort before lowercase.
- Remove Duplicates: Optional deduplication after sorting.
How It Works
The text is split by newlines into an array. The chosen sort method is applied using JavaScript's Array.sort with a custom comparator. Alphabetical uses localeCompare for proper handling of accents and Unicode. Numeric sort parses each line as a number. Length sort compares string lengths.
Formula / Logic Used
Sort any list of lines alphabetically, numerically, by length, or reverse order.
Step-by-Step Example
Input:
banana Apple cherry 10 2 apple
Method: Alphabetical A-Z (case insensitive)
Output:
10 2 Apple apple banana cherry
For numeric sort: 2, 10, Apple, apple, banana, cherry (numbers first in ascending order, text alphabetically after).
Use Cases
- Alphabetize lists: Sort names, products, or tags into alphabetical order for reports and directories.
- Prioritize by length: Find the longest or shortest entries in a list — useful for URL slugs, titles, or tweet drafts.
- Numeric sorting: Sort numeric IDs, quantities, or prices when they're mixed into a text list.
- Reverse order: Flip the order of items quickly — e.g., reverse a timeline or playlist.
- Random shuffle: Shuffle lines to randomize quiz questions, playlists, or team rosters.
Assumptions and Limitations
- Numeric sort treats non-numeric lines as 0 (they cluster at the top/bottom of numeric sort).
- localeCompare uses your browser's default locale — sorting may differ slightly across locales for accented characters.
- Shuffle uses Math.random, which is pseudo-random, not cryptographic. For fair raffles, use a verifiable RNG.
- Stable sort is guaranteed in modern browsers, so equal keys preserve their relative input order.
Frequently Asked Questions
How to sort lines alphabetically online
Paste your list with one item per line, click Sort A-Z, and the tool reorders everything alphabetically. Copy the result. Works on names, URLs, titles, anything where each line is a separate item. By default sorting is case-sensitive, so capital letters come before lowercase ones. Switch on the case-insensitive toggle if "Apple" and "apple" should sort together. For a Z-to-A sort, there's a separate descending option right next to the ascending button.
How to alphabetize a list online
Same idea as sorting lines alphabetically. Paste your list with each item on its own line, click Sort A-Z. The tool returns the list in alphabetical order. Numbers, when mixed with words, sort by their character value rather than their numeric value — so "10" comes before "2" in default mode. Switch to numeric sort if your list is numbers. Switch to case-insensitive if mixed capitalisation is causing weird sort order. Copy and paste the cleaned output.
How to sort numbers in a text list
Pick the Numeric Sort option instead of alphabetical. The tool then reads each line as a number and orders them by value — "2" before "10", "100" after "20". Without numeric mode, sorting goes character-by-character, which puts "10" before "2" because "1" comes before "2". Useful for sorting price lists, ID numbers, dates in YYYY-MM-DD format, or any column of numbers you've copied out of a spreadsheet that needs reordering.
How to sort lines by length online
Switch the sort mode to "by length". The tool then orders lines from shortest to longest, counting characters per line. So a list of "cat, elephant, dog, ant, hippopotamus" becomes "ant, cat, dog, elephant, hippopotamus" when sorted shortest-to-longest. Use Reverse Order to flip it longest-to-shortest. Useful for finding outlier-length entries in a dataset, organising poetry, or just quick visual sorting when alphabetical doesn't help much. A small but oddly useful feature.
How to randomize lines in a list
Switch to the Shuffle or Random Order mode. The tool returns your lines in a random sequence — every click gives a different order. Useful for randomising playlist order, shuffling quiz questions, picking a random winner from a list of names, or breaking up a sorted list when you don't want any pattern. The randomisation is fresh each time, so don't worry about hidden patterns; click again if you want a different result.
How to sort text in reverse alphabetical order
Click Sort Z-A (or "descending"). The tool orders your lines from Z down to A — exactly the opposite of normal alphabetical sort. So "apple, banana, mango" becomes "mango, banana, apple". Useful for finding entries that start with later letters, organising countdown lists, or reversing a sort you just did. Combine with case-insensitive mode if mixed capitalisation is throwing off the order. Numeric values can also be sorted high-to-low using descending numeric mode.
How to sort a list and remove duplicates online
Two-step on the same page. First, run Sort A-Z to alphabetise your list. Then, if there's a "remove duplicates" toggle, switch it on before sorting; if not, copy the sorted output, paste it into the dedupe tool, and run Remove Duplicates. The result is a clean, alphabetised, unique list. Useful for cleaning email lists, contact files, URL collections, or anything that combines messiness with repetition. Three clicks, no spreadsheet needed.
Sources and References
- MDN — Array.prototype.sort — JavaScript array sorting reference.
- MDN — String.prototype.localeCompare — Locale-aware string comparison.
- Wikipedia — Fisher-Yates Shuffle — The algorithm used for unbiased random shuffling.
- ECMAScript Specification — Sort — The official spec guaranteeing stable sort in modern engines.
Related Calculators
What this tool does
Sort Lines Alphabetically turns the visible inputs on the page into a specific result and keeps the calculation context close to the form. The added notes identify what the output means, which assumptions matter, and when the result should be checked against source data or official guidance.
How to use this tool
- Enter the values requested by the form, keeping units, formats, and date fields consistent.
- Run the calculation or conversion and review each output label before using the result elsewhere.
- Compare important results with the page notes, examples, or official references when accuracy affects money, safety, configuration, or reporting.