Sort Lines Alphabetically
Paste a list and its lines are sorted at once: A to Z, Z to A, naturally (file2 before file10), by number or by length, reversed or shuffled. The example list has 8 lines; sorted A to Z with English rules (the default) they come out as: apple, Apple, banana, cherry, Cherry, date, elderberry, fig. Lowercase comes just before its capital; turn on “Ignore case” and “Apple” ties with “apple” and “Cherry” with “cherry”, so each pair stays in the order you typed it (apple, Apple, banana, Cherry, cherry, date, elderberry, fig). Text is compared with the browser’s Intl.Collator for the language you choose, so accented letters land where that language expects them. You can also trim lines, drop blank lines and keep only unique lines. Your list never leaves the browser.
Updated Runs in your browser: nothing you enter is uploadedHow this tool works
Replace the example: paste or type one item per line. The sorted list updates as you type.
Your list is processed on this device and never uploaded. It is not saved either: reload the page and it is gone.
Sorted list
8 lines in, 8 lines out, sorted A to Z.
Compared with Intl.Collator, locale “en” (English).
Counts
- Lines in
- 8
- Lines out
- 8
- Blank lines removed
- 0
- Duplicates removed
- 0
The sort orders
| Sort | Result | How it works |
|---|---|---|
| A to Z | -3 degrees, 10 apples, 9 pears, file1.txt, file10.txt, File2.txt, note, Zebra | Dictionary order for the chosen language: digits and symbols first, accents sort with their letter, and a lowercase letter comes just before its capital. |
| Z to A | Zebra, note, File2.txt, file10.txt, file1.txt, 9 pears, 10 apples, -3 degrees | The same order, backwards. |
| Natural, A to Z | -3 degrees, 9 pears, 10 apples, file1.txt, File2.txt, file10.txt, note, Zebra | Runs of digits are compared as numbers, so file2 comes before file10. Leading zeros do not change the value; ties fall back to plain text order. |
| Natural, Z to A | Zebra, note, file10.txt, File2.txt, file1.txt, 10 apples, 9 pears, -3 degrees | Natural order, backwards. |
| Numeric, smallest first | -3 degrees, 9 pears, 10 apples, file1.txt, file10.txt, File2.txt, note, Zebra | By the number a line starts with (negative and decimal numbers work). Lines with no leading number go last, A to Z. |
| Numeric, largest first | 10 apples, 9 pears, -3 degrees, file1.txt, file10.txt, File2.txt, note, Zebra | Largest number first; lines with no leading number still go last. |
| Length, shortest first | note, Zebra, 9 pears, File2.txt, file1.txt, 10 apples, file10.txt, -3 degrees | By number of characters (an emoji counts as one); lines of equal length keep their order. |
| Length, longest first | file10.txt, -3 degrees, File2.txt, file1.txt, 10 apples, 9 pears, Zebra, note | Longest line first; equal lengths keep their order. |
| Reverse | Zebra, note, -3 degrees, 10 apples, 9 pears, file1.txt, File2.txt, file10.txt | Flips the list upside down without comparing anything. |
| Random shuffle | 10 apples, note, File2.txt, file1.txt, 9 pears, -3 degrees, Zebra, file10.txt (seed 7) | A different order for every seed. The page picks a new random seed each time you press Shuffle; the same text and seed always give the same order. |
What each option does
| Option | Result | Effect |
|---|---|---|
| Default (trim on, case-sensitive) | (blank), (blank), apple, apple, fig, pear, pear, Pear | Spaces around a line are ignored; “pear” sorts just before “Pear”, and blank lines sort first. |
| Ignore case | (blank), (blank), apple, apple, fig, pear, Pear, pear | “Pear” and “pear” compare as equal, so they stay in the order you typed them. |
| Remove empty lines | apple, apple, fig, pear, pear, Pear | Blank and whitespace-only lines are dropped before sorting. |
| Unique lines only | (blank), apple, fig, pear, Pear | Only the first copy of each identical line is kept, then the list is sorted. |
| Unique and ignore case | (blank), apple, fig, pear | “Pear” counts as a copy of “pear”; the first one typed stays. |
| Do not trim | (blank), (blank), Pear, apple, apple, fig, pear, pear | A leading space is part of the line, so “ Pear” sorts before every letter. |
Sorting rules by language
| Language | Result | Why |
|---|---|---|
| English (en) | apple, äpple, ol, öl, zebra | Accented letters sort right after the plain letter, so äpple follows apple. |
| German (de) | apple, äpple, ol, öl, zebra | The standard (dictionary) order treats ä like a, so it matches English here. |
| Swedish (sv) | apple, ol, zebra, äpple, öl | ä and ö are separate letters after z, so äpple and öl come last. |
How to sort lines alphabetically
- Paste your list. Replace the example with your own text, one item per line. The sorted result appears as you type.
- Choose the order. Pick A to Z, Z to A, natural order for names with numbers, numeric order for lines that start with a number, length, reverse or a random shuffle.
- Set the language and options. Choose the language whose alphabet you want to follow. Turn on “Ignore case”, “Trim spaces”, “Remove empty lines” or “Unique lines only” as needed.
- Shuffle again if you like. In shuffle mode, “Shuffle again” picks a fresh random order. Other options keep the current shuffle.
- Copy or download. Copy the sorted list to the clipboard or download it as a .txt file. The counts are shown beside it.
Frequently asked questions
- How do I sort lines alphabetically online?
- Paste your text into the box above, one item per line, and leave the sort on “A to Z”. The sorted list appears below as you type; copy it or download it as a .txt file. Nothing is uploaded, so it is safe for private lists. In a terminal, “sort file.txt” does the same job, but its order depends on your locale settings.
- Why does file10 come before file2?
- Plain alphabetical order compares one character at a time, and “1” sorts before “2”, so file10 lands before file2. Choose “Natural” to compare runs of digits as whole numbers; then file2 comes before file10. Leading zeros count by value, so file02 and file2 are tied and then ordered by their text.
- How does numeric sort work?
- Each line is sorted by the number it starts with, so “9 pears” comes before “10 apples”. Negative numbers and decimals work. Lines that do not start with a number go after all the numbered lines, in A to Z order, whichever direction you choose. Lines with the same number are ordered A to Z by the whole line.
- Is the sort case-sensitive?
- By default letters keep their case, and a lowercase letter sorts just before its capital (apple, Apple, banana). Turn on “Ignore case” to treat them as equal; lines that then tie stay in the order you typed them. Accents still count: “é” and “e” remain different.
- How are accented and non-English letters sorted?
- With the browser’s Intl.Collator and the language set in the “Language” list (English by default, and the page says which locale it used). In German “ä” sorts with “a”; in Swedish it is a separate letter after “z”. Pick “Your browser’s language” to follow the device setting instead. Hebrew, Arabic, Greek, Russian, Japanese and Chinese lists sort by their own rules too.
- Is the random shuffle really random?
- It is a Fisher–Yates shuffle, which is unbiased given a good random source. Each click draws a fresh 32-bit seed from your browser’s cryptographic generator and feeds a seeded generator, so the same list and seed always give the same order and the next click gives another. Because the seed has 32 bits, only about four billion different orders can occur, which is plenty for picking a speaking order but not meant for security or lotteries.
- How do I sort by line length?
- Choose “Length, shortest first” or “Length, longest first”. Length counts characters (an emoji counts once, not twice), and lines of equal length stay in the order you typed them.
- Can I sort and remove duplicates at the same time?
- Yes: turn on “Unique lines only” and the first copy of each line is kept before sorting. With “Ignore case” on as well, “Apple” counts as a copy of “apple”. The example list has 8 lines and 6 are left when both options are on. For more control, such as keeping the last copy or listing only repeated lines, use the Remove Duplicate Lines tool.
- Will it handle a very long list?
- Yes. Lists of 100,000 lines sort in well under a second on an ordinary computer; for very large pastes the result updates a moment after you stop typing so the page stays responsive. Sorting happens on your device, so the limit is your browser’s memory.
- Are Windows and Mac line endings kept?
- Sorted output keeps your line-ending style: if the first break in your text is a Windows CRLF, every line ends in CRLF; otherwise each ends in a plain LF. A trailing line break appears only when your input ended with one.
- Is my list saved or sent anywhere?
- No. The lines are sorted inside your browser tab and never sent anywhere or saved, so they vanish on reload. With analytics allowed, the site notes only that a button was pressed, never what you pasted.
How it works
Text is split into lines on LF, CRLF or CR. Blank lines (empty or only whitespace) are dropped if that option is on; lines are trimmed if “Trim spaces” is on; with “Unique lines only”, the first line of each kind is kept, where two lines match if they are equal after Unicode NFC normalization (and case folding, if “Ignore case” is on). The remaining lines are sorted. Text orders use Intl.Collator for the chosen locale (“en” by default): without “Ignore case” at variant sensitivity, with it at accent sensitivity, so case is ignored but accents are not; natural order turns on the collator’s numeric option. Numeric order parses the number each line starts with (optional sign, digits and decimal part) and compares them as floating-point numbers; lines without one go last. Length counts Unicode code points. The sort is stable, so lines that compare equal keep their input order. Shuffle runs a Fisher–Yates shuffle with a mulberry32 generator seeded with a 32-bit number drawn from crypto.getRandomValues for each click; a 32-bit seed reaches only about four billion of the possible orders of a list longer than 12 lines, so it is not suited to cryptographic use.Sorting time grows with n log n, and the numbers and lengths are computed once per line rather than on every comparison.
Sources
More free tools
- Remove Duplicate LinesRemove duplicate lines from a list, keep the first or last copy, and sort A to Z, naturally or at random. Works in any language and stays in your browser.
- Case ConverterConvert text to UPPERCASE, lowercase, Title Case, Sentence case, camelCase, PascalCase, snake_case, kebab-case or CONSTANT_CASE. Stays in your browser.
- Word Frequency CounterPaste text to see which words and phrases repeat most, with counts, percentages and keyword density. Filters stop words and works in any language.
- Text CompareCompare two texts and see what changed, line by line with changed words highlighted. Ignore case or spacing, copy a unified diff. Stays in your browser.
- Random Name PickerPaste a list and pick a random winner, shuffle it or split it into teams. Every entry has the same chance, and your list never leaves your device.
- Find and ReplaceFind and replace text online: match case or whole words, use regular expressions with $1, run several pairs in order, and replace all or one by one.