Sort Lines Alphabetically

Text Tools

How to use the Sort Lines Alphabetically

Sort any list of lines in four steps:

1

Paste your list

Paste any multi-line list or text into the input area — one item per line.

2

Choose sort mode

Select A→Z, Z→A, 0→9, 9→0, Shortest first, or Longest first using the mode selector.

3

Set options

Toggle case-sensitive sorting, remove duplicates after sort, trim lines before sorting, and skip empty lines as needed.

4

Copy or download

Click 'Sort Lines' and copy or download the sorted output.


When to use this tool

Use to sort any list of text lines into a consistent order:

  • Alphabetising a list of names, cities, products, or keywords for a document or spreadsheet
  • Sorting CSS class names, import statements, or configuration keys alphabetically for consistent code style
  • Ordering a list of file names, URLs, or dependencies alphabetically for a README or manifest
  • Numerically sorting log entries, invoice numbers, or version strings to find the highest or lowest value
  • Sorting lines by length to identify the longest or shortest entries in a data set
  • Combining sort with duplicate removal to produce a clean, unique, alphabetically ordered list in one step

Frequently asked questions

Q:Is sorting case-sensitive by default?
No — case-insensitive sorting is the default, which means 'Apple', 'apple', and 'APPLE' are sorted together as if they were the same word, following natural alphabetical order. Enable 'Case sensitive' to sort by raw character codes, which places all uppercase letters before all lowercase letters (so 'Z' sorts before 'a').
Q:How does numeric sort differ from alphabetical sort?
Alphabetical sort compares lines as strings, which produces the order 1, 10, 100, 2, 20 — because '1' < '10' < '100' < '2' in string comparison. Numeric sort parses the leading number of each line and compares numerically, producing the correct order: 1, 2, 10, 20, 100. Lines that do not begin with a number are placed at the end of the sorted output.
Q:Can I sort and remove duplicates at the same time?
Yes — enable the 'Remove duplicates' toggle before clicking Sort. Deduplication uses the same case sensitivity setting as the sort: with case-insensitive mode, 'Apple' and 'apple' are treated as duplicates; with case-sensitive mode, they are kept as distinct entries. The deduplication happens after the sort so the result is a clean, unique, ordered list.
Q:How are lines sorted by length?
'Shortest first' sorts lines by their character count in ascending order — the shortest line appears at the top and the longest at the bottom. 'Longest first' reverses this. Lines of equal length are kept in their original relative order (stable sort). This mode is useful for identifying outliers in a data set — very long lines that may be anomalous or very short lines that may be incomplete.
Q:Can I sort CSS properties or import statements alphabetically?
Yes — paste your CSS property block or import list (one property or import per line), select A→Z with case-insensitive mode, and click Sort. The output is an alphabetically ordered list ready to paste back into your editor. Many CSS style guides (including Google's and Airbnb's) recommend alphabetical property ordering. CSS and JavaScript linters like Stylelint and ESLint can enforce this automatically, but this tool is useful for one-off sorting.
Q:Is there a limit on how many lines can be sorted?
There is no enforced limit. The sort uses JavaScript's built-in Array.sort(), which is implemented as a highly optimised Timsort algorithm (O(n log n) time complexity). Lists of tens of thousands of lines are sorted in milliseconds. Very large files with millions of lines may take a few seconds, but all processing happens in your browser with no server round-trip.