Skip to content

Free online tool

Sort lines

Paste a list, or any text with one item per line, to sort it A to Z or Z to A, from the shortest line to the longest, or by the number in each line. Lines that tie keep their original order, and empty lines go to the end. Nothing is uploaded.

Runs in your browser. Your text is never uploaded.

Runs in your browser. Your text isn’t uploaded or saved.

Sort order
Options

How to sort lines

  1. 1Paste your list into the box, one item per line: names, keywords, file names or prices.
  2. 2Pick an order: A to Z or Z to A, shortest or longest first, or smallest or largest number first.
  3. 3Choose whether capitals sort apart from lower-case letters, whether to trim spaces at the ends of lines, and whether to remove empty lines.
  4. 4Press Copy result and paste the sorted list where you need it.

Features

  • Six orders: A to Z, Z to A, shortest first, longest first, smallest number first and largest number first
  • Dictionary order that keeps “apple” and “Apple” together, or a case-sensitive order with capitals first, as in code
  • Number orders that read negative numbers, decimals and thousands separators, and compare long numbers exactly
  • Lines that tie keep their original order, so the result is the same every time
  • Empty lines moved to the end or removed, and spaces at the ends of lines trimmed if you want
  • Free, no sign-up, and your text never leaves your browser

How lines are sorted

Here is exactly how lines are compared. Everything happens in your browser.

Lines
Windows (CR LF), old Mac (CR) and Unix (LF) line breaks are all recognised, and so are the line and paragraph separators (U+2028, U+2029) that InDesign, Word and some PDFs use, vertical tabs, form feeds and NEL. A line break at the very end of the text doesn’t start an extra, empty line. A line break at the end is kept, and the result uses Unix (LF) line breaks. Every line is kept as you typed it, unless an option below changes it.
A to Z and Z to A
Lines are compared in dictionary order, which is the same for every visitor, whatever their language. Spaces and punctuation come first, then digits, then letters. Upper and lower case sort together, and when two lines differ only in case the lower-case one comes first (apple, Apple). An accented letter sorts with its base letter (é with e), and other scripts come after the Latin alphabet. Digits are compared one at a time, so 10 comes before 2. Z to A is the reverse.
Case-sensitive
With Case-sensitive on, A to Z and Z to A compare lines by Unicode character code, as sorting in code does: digits come before capitals, capitals before lower-case letters, and accented letters after z, so “Zebra” comes before “apple” and “éclair” after “zebra”. It doesn’t change the length and number orders.
Shortest and longest first
Length is counted in characters as you see them, so an emoji or an accented letter counts as one. Spaces and tabs count, unless Trim whitespace removes them.
Smallest and largest number first
The first number in each line is used, wherever it is in the line. A number is digits (0 to 9), with commas between groups of three as thousands separators (1,000) and a full stop as the decimal point (3.14 or .5). A minus sign (- or −) straight before the number makes it negative, unless a letter or digit comes before the sign, so “item-3” is 3 and “10-20” is 10. Decimal commas and exponents aren’t read: “3,14” is 3 and “1e5” is 1. Numbers are compared exactly, however long they are. Lines with no number come after the numbered ones, in their original order.
Ties
Lines that compare the same, such as two lines of the same length or with the same number, keep the order they had in your text, in every order.
Trim whitespace
Spaces and tabs at the start and end of each line are ignored when comparing, and removed from the result. With it off they count: in A to Z a line that starts with a space comes before every line that starts with a letter.
Empty lines
Lines that are empty or hold only spaces aren’t sorted. They go to the end of the result in every order, and Remove empty lines deletes them.

Private by design

Your text stays with you

Everything runs in your browser. Nothing you type or paste is uploaded, logged or used for analytics, so it’s safe for code, contracts and private notes.

Works with any language

Accented letters, other scripts and emoji come through intact, and Windows, Mac and Unix line breaks are all understood.

Fast with long texts

Results update as you type. Long pastes are handled once you pause, so typing never stutters.

Frequently asked questions

How are capital letters sorted?

By default, upper and lower case sort together, as in a dictionary: apple, Apple, banana, Banana. When two lines differ only in case, the lower-case one comes first. Turn on “Case-sensitive” to sort by character code instead, as programming languages do: the capitals A to Z then come before every lower-case letter, so “Zebra” comes before “apple”.

Why does 10 come before 2 in A to Z order?

A to Z compares lines one character at a time, and “1” comes before “2”, so “10” sorts before “2”, just as “ab” sorts before “b”. To sort by value, pick “Smallest number first” or “Largest number first”, which read the first number in each line: 2 then comes before 10, and “Chapter 2” before “Chapter 10”.

How does sorting by number work?

The first number in each line is used, wherever it is: “3 apples”, “$5.99” and “Chapter 12” sort as 3, 5.99 and 12. A minus sign straight before the number makes it negative, a comma between groups of three digits is a thousands separator (1,000), and a full stop is the decimal point. Lines with the same number keep their original order, and lines with no number follow the numbered ones, also in their original order.

What happens to blank lines and duplicate lines?

Blank lines, including lines of only spaces, aren’t sorted: they go to the end of the result, or “Remove empty lines” deletes them. Duplicate lines are kept, next to each other once sorted. To delete them, use Remove Duplicate Lines before or after sorting: it keeps the order of the lines it’s given.

Is my text uploaded or stored?

No. Everything happens in JavaScript in your browser, and your text is never sent to a server, logged or tracked. You can check by opening your browser’s network tab while you type. This tool doesn’t save your text either: it’s gone when you close or reload the page.

Is it free?

Yes. There’s no sign-up, paid plan or adverts, and no limit on how often you use it. Everything runs on your own device, so there are no servers to pay for.

More free text tools

Looking for something else? Browse all free tools.