Sort Lines

Paste any list and sort lines alphabetically A-Z or Z-A, order by character length from shortest to longest, or shuffle them into a random order. Preview the result before applying.

Input Text

Sort Mode

Choose how lines should be ordered, then click Apply.

Why Use This Tool?

Sorting lines of text is one of the most common data-cleaning tasks — whether you are alphabetising a word list, ranking URLs by length, organising config keys, or randomising quiz question order. This sort lines tool applies the operation instantly inside your browser using Unicode-aware lexicographic comparison for alphabetical sorts and the Fisher-Yates algorithm for shuffling. Your data never leaves your device.

  • Alphabetical Sorting: Sort any list A-Z or Z-A using JavaScript's localeCompare for correct Unicode handling — works with accented characters, mixed-case entries, and multilingual text.

  • Sort by Character Length: Order lines by their character count to quickly surface the shortest or longest entries — useful for cleaning API response fields, formatting code, or finding outlier strings.

  • Shuffle Lines: Randomise line order with the Fisher-Yates algorithm, which guarantees a statistically uniform distribution — every permutation has an equal probability of appearing.

How to Use It

  1. 1

    Paste your list into the text area above — one item per line. You can paste from a spreadsheet column, a log file, or any other source.

  2. 2

    Choose a sort mode: A → Z, Z → A, Shortest First, Longest First, or Shuffle. Toggle Case Sensitive if capitalisation matters for alphabetical sorts.

  3. 3

    Review the Preview panel to see the reordered lines before committing. The After column shows exactly how your text will look once you apply.

  4. 4

    Click Apply to update the text area with the sorted result, then Copy Result to send it to your clipboard.

Frequently Asked Questions

What algorithm does this tool use to sort lines?

Alphabetical sorting uses JavaScript's Array.prototype.sort with localeCompare for Unicode-aware lexicographic ordering — the same algorithm used by most operating-system file explorers. Length-based sorting applies a simple numeric comparator on each line's character count. Shuffling uses the Fisher-Yates (Knuth) shuffle, which iterates the array from the last element backwards and swaps each element with a random earlier position, producing a uniformly random permutation in O(n) time.

Is my data safe when I use this tool?

Yes, completely. The sort lines tool runs 100% client-side in your browser using JavaScript. No text is ever sent to a server, stored in a database, or logged anywhere. It is safe to paste confidential data, internal documents, API keys, or personal lists — none of it leaves your device at any point during sorting.

What is the difference between case-sensitive and case-insensitive alphabetical sort?

In case-insensitive mode (the default), all letters are normalised to lowercase before comparing, so "banana", "Banana", and "BANANA" sort together as equal entries. In case-sensitive mode, uppercase letters sort before their lowercase equivalents in Unicode order, meaning "Banana" would appear before "apple". Use case-insensitive mode for human-readable word lists and case-sensitive mode for programming identifiers or file names where capitalisation is meaningful.

Does sorting by length count characters or bytes?

Sorting by length uses JavaScript's string .length property, which counts UTF-16 code units. For standard Latin text this is identical to counting visible characters. Emoji and rare Unicode code points outside the Basic Multilingual Plane may count as 2 units — so a line containing one emoji may measure as length 2 rather than 1. This is standard JavaScript string measurement behaviour and affects only those edge-case characters.

Is the Shuffle truly random?

The Shuffle mode uses the Fisher-Yates algorithm with Math.random() as its randomness source. Math.random() produces a pseudorandom sequence sufficient for everyday list shuffling — quiz randomisation, playlist generation, random sampling. Each permutation of n lines has an equal probability of 1/n! of appearing. Note that Math.random() is not a cryptographically secure PRNG, so it should not be used for security-sensitive applications such as cryptographic key generation.

Can I undo a sort after I click Apply?

Yes. Every apply action is saved to the undo history before the text is modified. Click the undo button (the curved arrow in the toolbar) to instantly restore the text to its previous state. The history stack holds up to 50 entries, so you can undo multiple consecutive sort operations in sequence. Redo is also available if you change your mind and want to re-apply a sort.

What happens to blank lines when sorting?

Blank lines participate in sorting like any other line — they are treated as zero-length strings. In alphabetical sort, blank lines appear at the top because they precede all non-empty strings lexicographically. In length sort, blank lines also rise to the top under Shortest First mode. In Shuffle mode, blank lines are distributed randomly throughout the output. If you want to remove blank lines before sorting, use the Remove Spaces tool first, then paste the cleaned text here to sort it.

Sort any list in seconds — right in your browser, no account needed.