How to alphabetize a list: case, accents, spaces and punctuation
To alphabetize a list, put one item on each line and sort the lines. The result depends on the rule the sort uses, though. Capitals, accents, spaces and punctuation can each move an item to a surprising place, so decide which rule you want before you sort.
Sort linesList is out of orderOpenTwo rules that give different orders
A computer can compare text in one of two common ways. The first compares the numeric code of each character. Every capital letter has a lower code than every lowercase letter, so a plain code sort puts Zoe and Ezra before the lowercase word apple. Python, for example, sorts plain strings this way by default.
The second follows the rules of a language, which is what a dictionary does. Letters are compared without regard to capitals first, and accents count as small differences within a letter. This is how people expect a list of names to look.
The sort lines tool uses the second rule. It relies on the browser's built-in language-aware comparison, in the language your browser is set to. You do not pick a language, but the browser's setting still decides the place of letters that are unusual in English.
Capitals: Apple, apple and APPLE
By default, letters are compared without case, so Apple and apple are equal at the first level of comparison. Equal items keep the order they had in your list. Take this list:
banana Apple cherry apple
Sorted A to Z with the default setting, you get Apple, apple, banana, cherry. The two apples keep the order they were pasted in.
Turn on Case-sensitive to keep capitals and lower case apart. Lower-case letters then come before capitals of the same letter, so the same list becomes apple, Apple, banana, cherry. Remove duplicates follows the same setting, so with Case-sensitive off, Apple and apple count as one item.
Use Case-sensitive for identifiers, keys and file names, where a lower-case letter and a capital are different things. Leave it off for names, titles and most lists of words.
Accents and other alphabets
Accents are where a plain code sort looks wrong most often. Take four names in code order: Eve, Ezra, Zoe, Émile. The É has a high code, so it lands after Z. A dictionary places Émile with the E names, which gives Émile, Eve, Ezra, Zoe.
Other alphabets have their own order too. In Swedish, Å comes after Z, and a browser set to Swedish sorts it that way. A browser set to English places å among the A words. If your list mixes languages, check the order by eye on a few items before you rely on it.
Spaces, hyphens and punctuation
Spaces and punctuation are not ignored. They sort before letters and digits, and they have a fixed order among themselves. For these six items:
ab a1 a b a-b a.b a_b
the result is a b, a_b, a-b, a.b, a1, ab. A space comes before the underscore, the underscore before the hyphen, and all of them before the letter b. That is why "Sea Lion" comes before "Seal", while "Sealion" comes after "Seal".
Leading spaces are the other common surprise. A line that starts with a space sorts before every line that does not, so " apple" comes first even though it is an apple. Turn on Trim spaces at the ends of each line to remove them before the sort.
Numbers
A plain sort puts item 10 before item 2, because the character 1 comes before 2. Choose Numbers to read the digits as whole numbers, so item 2 comes first. The remove duplicate lines guide covers the difference with examples for file names and codes.
Shuffle is a different job
Shuffle is not a sort. Each press of Shuffle again gives a new order, drawn with the browser's cryptographic random numbers, so every order is equally likely. A shuffle is useful for putting a playlist or a set of practice questions in random order. For a fair draw of winners from a list, use the random picker instead.
Quick answers
Why does Émile come after Zoe in my spreadsheet or code?
A code sort compares character numbers, and É has a higher number than Z. A sort that follows language rules puts Émile with the E names.
Should I turn on Case-sensitive?
Only when capitals carry meaning, as in identifiers, keys or file names. For a list of names or words, leave it off.
Why did a line with a leading space move to the top?
A space sorts before letters. Turn on Trim spaces at the ends of each line, then sort again.


