Skip to main content
ToolsBay

Sort Lines Alphabetically

Sort a list of lines A–Z, Z–A, or by length.

Runs entirely in your browser — nothing is uploaded

Your list

1 line

Sorted result

1 line

Frequently asked questions

Why does "Apple" sort before "banana" here but after it elsewhere?

Because this sorts the way a person would, not the way a computer stores letters. JavaScript's default sort compares character codes, and every capital letter has a lower code than every lowercase letter — so it puts Zebra before apple. This tool uses locale-aware comparison instead.

How are numbers inside text handled?

Naturally. item2 sorts before item10, rather than after it as a plain text sort would produce. This is what you want for filenames, version strings and numbered lists.

Does sorting also remove duplicates?

No, sorting keeps every line. To remove repeats, run the list through the remove duplicate lines tool either before or after sorting.

Sorting a list the way people expect

Alphabetical sorting looks trivial and is not. The default sort in most programming languages compares UTF-16 code units, which means every capitalised entry lands before every lowercase one: ["banana", "Apple"] sorts to ["Apple", "banana"] for the wrong reason, and ["apple", "Banana"] sorts to ["Banana", "apple"] which is plainly wrong.

This tool compares using locale rules, so case is ignored for ordering purposes and accented letters sort next to their base letter rather than after Z. Digits inside text are compared numerically, so item2 precedes item10.

The other sort modes

Sorting by length is useful for finding outliers — the one malformed row in a column of IDs is usually the longest or shortest. Reverse order does not sort at all; it simply flips the list you already have, which is what you want when the input was already in a meaningful order.

Pair this with remove duplicate lines to get a clean, ordered, unique list.

All text utilities