My Tool Studio
Text

Sort Lines Alphabetically

Paste a list and sort lines online in the order you need: alphabetical A to Z or Z to A, natural order where item2 comes before item10, numeric, by length, reversed, or shuffled at random. It works for names, keywords, file names, URLs and prices copied from a spreadsheet. Items can be split by lines, commas, semicolons or your own separator, and joined back with a different one, so a comma list can come out as a column. Sort by column sorts CSV or tab-separated lines by any field. Before sorting you can remove duplicates, empty lines, stray spaces, HTML tags and punctuation. A Case-sensitive switch decides whether capitals come first. The count before and after is shown, and nothing leaves your browser.

Always freeNo sign upRuns in your browser

How to use

01

Paste one item per line

Type or paste your list into the Your list box. Press Try sample to load a short list with mixed capitals, a blank line and numbered items like item2 and item10.

02

Pick a sort order

Choose from the Sort order menu, for example Natural A to Z or Numeric, smallest first. For Random shuffle, press Shuffle again to get a new order.

03

Set options and copy

Set the separators, tick Sort by column for CSV lines, and tick any clean-up options. Check the in and out counter, then press Copy or Download .txt.

Why Sort Lines Alphabetically

Examples of each sort order

The table uses the sample list: item10, Banana, item2, apple, a blank line, cherry, item1, banana, Apple. Case-sensitive is off and no other option is ticked.

Sort orderResult (blank line shown as ___)
Alphabetical A to Z___, apple, Apple, Banana, banana, cherry, item1, item10, item2
Alphabetical Z to Aitem2, item10, item1, cherry, Banana, banana, apple, Apple, ___
Natural A to Z___, apple, Apple, Banana, banana, cherry, item1, item2, item10
Length, shortest first___, item2, apple, item1, Apple, item10, Banana, cherry, banana
Reverse current orderApple, banana, item1, cherry, ___, apple, item2, Banana, item10
A to Z with Case-sensitive onApple, Banana, apple, banana, cherry, item1, item10, item2 (with Remove duplicates and Remove empty lines also on)

Common sorting mistakes

Most surprising results come from one of a few causes. Check these before assuming the sort is wrong. The line counter helps here too: if fewer lines come out than went in, an option such as Remove duplicates or Remove empty lines is switched on.

  • Numbers inside text sorted alphabetically: use Natural A to Z so file2 comes before file10.
  • Leading spaces: a line that starts with a space sorts before letters. Tick Trim spaces on each line.
  • Blank lines at the top: empty lines sort first in A to Z. Tick Remove empty lines.
  • Numeric sort with units first: a line like USD 25 has no leading number, so it goes to the end. Remove the prefix before sorting.
  • Decimal commas: 2,5 is read as 25 because commas are treated as thousands separators. Replace decimal commas with dots first.

Common questions

Why does item10 come before item2 when I sort lines alphabetically?
Alphabetical sorting compares text one character at a time, and the character 1 comes before 2, so item10 lands before item2. Choose Natural A to Z instead. It reads runs of digits as whole numbers, so item1, item2 and item10 come out in counting order.
What is the difference between natural sort and numeric sort?
Natural sort handles text that has numbers inside it, like file names or chapter titles. Numeric sort only looks at the number at the start of each line and orders by its value. Use numeric for plain lists of numbers or prices, and natural for mixed text such as photo12.jpg.
How are lines without a number handled in numeric sort?
Lines that do not start with a number are moved to the end and keep their original order. Commas are read as thousands separators, so 1,000 sorts as one thousand. A leading minus sign and decimals work, so -3.5 comes before 2.
Does the Case-sensitive option change how lines are sorted?
With Case-sensitive off, apple and Apple sort next to each other and letters with accents sit beside their plain versions. With it on, lines are ordered by character code, so every line that starts with a capital comes before every lowercase line. Case-sensitive also decides whether Remove duplicates treats Apple and apple as different.
Can I sort lines and remove duplicates at the same time?
Yes. Tick Remove duplicates and repeated lines are dropped before sorting, keeping one copy of each. Combine it with Trim spaces on each line so that lines that differ only by padding are caught too.
Is the random shuffle in the line sorter fair?
Yes. It uses the Fisher-Yates method, which gives every possible order the same chance. Press Shuffle again for a fresh order. It uses the browser's normal random numbers, so it suits picking a speaking order or randomizing quiz questions, not lotteries or security uses.
How do I sort a comma-separated list alphabetically?
Set Items in the input are separated by to Comma and paste the list, such as pear, apple, fig. Pick the separator for the result in Separate sorted items with: Comma keeps it on one line, New line turns it into a column. Tick Trim spaces on each line so the space after each comma does not affect the order.
How do I sort lines by length?
Choose Length, shortest first or Length, longest first from the Sort order menu. Length is counted in characters, and lines of equal length keep their original order. It is handy for finding the longest title in a list or checking slugs against a limit.
Can I reverse the order of lines without sorting them?
Yes. Reverse current order flips the list so the last line becomes the first, with no alphabetical sorting at all. That is useful for turning an oldest-first log into newest-first.
Can I sort a CSV file by a specific column with this tool?
Yes. Tick Sort by column, type the Column number, for example 2 for the second field, and choose how Columns are split by: comma, semicolon, tab, space, pipe or custom. Each whole line moves, ordered by that field. Quoted fields that contain the separator are not parsed as one value, so use a spreadsheet for complex CSV files.

More Text tools

View all