Skip to content
Locale Lab

Chapter 06·The Intl Toolbox·~6 min·

Sorting and Alphabetical Collation

Alphabetical sort order varies by language and context. Intl.Collator implements the Unicode Collation Algorithm and CLDR tailorings for dictionary sorting, phonebook ordering, and accent-insensitive search.

Intl.CollatorCLDR collationUCA

Overview

Default JavaScript `.sort()` compares UTF-16 code units, which sorts `Z` before `a` and places accented letters after `z`. Alphabetical order is a cultural convention that varies by language and usage context. `Intl.Collator` implements the Unicode Collation Algorithm with CLDR language tailorings.

Core rule

Sort user-facing lists with Intl.Collator using the active locale, and use usage: 'search' with sensitivity: 'base' for locale-aware string matching.

Specification note: German sorts ä beside a, whereas Swedish sorts ä after z. A single static sort table cannot satisfy both locales.

Failure mode

Calling Array.prototype.sort() without a comparator orders strings by UTF-16 code unit value. That order places all uppercase ASCII letters before lowercase letters and places accented Latin characters after z. In a German directory sorted by code units, Öztürk appears after Zander. In Polish, ł sorts after z instead of between l and m. In a Hebrew interface, Latin strings sort before Hebrew strings unless the Hebrew locale collation is active.

Stakeholder Teaching Aid & Novice Guide
Cross-functional alignment tool

Standard software sorting orders characters by binary Unicode code points, not human alphabetical order. International users cannot find sorted records.

Business stakes & user risk

In Swedish, 'Ö' sorted at the top with 'O' instead of after 'Z' makes customer lists, contact directories, and product catalogs look broken and unusable.

Rule of thumb

Sort user-facing strings using Intl.Collator with the user active locale. Never use default Array.prototype.sort().

The Novice Trap vs. Production Standard

Contrast the intuitive assumption with the architecture required for global releases.

Naive mental model

“The default array.sort() method sorts alphabetically in all languages.”

Naive approach: Built-in JavaScript sort

names.sort(); // Compares binary code points

Defect:Produces: ['Apple', 'Zebra', 'apple', 'Åberg']. Lowercase 'apple' and Swedish 'Åberg' appear after 'Zebra'.

Production standard

Default sort compares ASCII/UTF-16 numeric values. Lowercase 'a' sorts after uppercase 'Z', and accented letters sort at the very end of the alphabet.

Production standard: Intl.Collator

names.sort(new Intl.Collator(locale, { sensitivity: "base" }).compare);

Benefit:Places accented letters in true national alphabetical sequence and handles case-insensitive comparisons properly.

Cross-Functional Review Questions

Questions for product managers, designers, engineers, and testers to ask during sprint reviews.

For EngineeringQuestion #1

“Is every user-visible list sorted using Intl.Collator or database collation?”

What to look for: Database queries with COLLATE clauses and frontend sort functions passing locale collators.
For ProductQuestion #2

“Are search filters and autocomplete features configured for accent-insensitive matching?”

What to look for: Search queries matching 'cafe' to 'café' using Intl.Collator with sensitivity: 'base'.
For DesignQuestion #3

“Does alphabet index navigation (A through Z) support regional letters?”

What to look for: Directory jump bars including Nordic 'Å, Ä, Ö' or Spanish 'Ñ' when rendered for those locales.
For QAQuestion #4

“Are sorted tables tested with German phonebook (DIN 5007-2) and Nordic names?”

What to look for: Test cases ensuring German 'Müller' and 'Mueller' sort correctly under specified collation rules.

Mechanism

Multi-level collation and CLDR tailorings

JavaScript's default Array.prototype.sort() compares 16-bit UTF-16 code units in numeric order, which places every uppercase ASCII letter before every lowercase letter and places accented characters such as É (U+00C9) after z (U+007A). In contrast, the Unicode Collation Algorithm (UTS #10) evaluates strings across multiple comparison levels: primary (base letters), secondary (diacritics), and tertiary (case and width). Secondary differences break ties only when the primary base letters are identical, so Élan sorts beside elan rather than after zebra.

CLDR layers language-specific tailorings on top of the default Unicode collation table. Swedish treats å, ä, and ö as distinct letters at the end of the alphabet after z. Polish places ł between l and m. German defines two standard collation orders: dictionary order (DIN 5007-1) and phonebook order (DIN 5007-2, selected via de-DE-u-co-phonebk), which expands ä, ö, and ü to ae, oe, and ue. Passing { numeric: true } to Intl.Collator also compares multi-digit substrings by numeric value so file2 sorts before file10.

Interactive demo

Guided exercises

  1. 1
    On the default Polish list, scan the highlighted cells across the en and pl columns. `Łaba` and `Łapińska` sort with `L` under `en` but move after `Lis` under `pl`, because Polish sorts `ł` as a distinct letter between `l` and `m`.
  2. 2
    Switch to “German names · dictionary vs phonebook ordering”. Under `de-DE-u-co-phonebk`, `Mössbauer` sorts before `Mosel` and `Mütze` sorts before `Mutter` because phonebook collation expands `ö` to `oe` and `ü` to `ue`.
  3. 3
    Switch to the Swedish list. Under `sv`, `Ångström`, `Älg`, and `Östergren` move to the bottom of the list because `å`, `ä`, and `ö` are letters 27 to 29 after `z`. Under `da`, `Ångström` sorts last because the Danish alphabet ends `æ, ø, å`.
  4. 4
    Load “Case sensitivity” and compare the three English columns. Default collation places lowercase first, `-u-kf-upper` places uppercase first, and `sensitivity: 'base'` treats uppercase and lowercase as equal.
  5. 5
    Type a few entries into “Your list · comma-separated”, and include at least one accented word, e.g. Zorro, Öberg, chávez, Lukas, łódź. Each locale column re-sorts the custom entries according to its CLDR tailoring and highlights rows that diverge from the English sort order.
  6. 6
    In “Sort is not search”, keep the defaults (Search locale English, Sensitivity base, Search query muller), then switch Search locale to German (de). Under `en`, `muller` matches `Müller`. Under `de`, `muller` does not match `Müller`, whereas `mueller` matches both `Müller` and `Mueller`.

Each column sorts the list with Intl.Collator for its locale tag; highlighted cells differ from the first column, the English default. Type two or more entries to sort a custom list.

Sorted output, locale by locale
#
en
English (UCA default)
pl
Polish
01ŁabaLewandowski
02ŁapińskaLewiński
03LewandowskiLipiński
04LewińskiLis
05LipińskiŁaba
06LisŁapińska
07ŁukasiewiczŁukasiewicz
08MaciejewskiMaciejewski
09MałachowskiMałachowski
10ModlińskiModliński

Default order and tailorings

The Unicode Collation Algorithm (UCA) defines a default order, and CLDR adds per-locale tailorings for letter order, accents, and case. Intl.Collator applies the tailoring for its locale and returns a comparator for .sort().

  • Polish ł is a separate letter that sorts between l and m. Code-unit order puts it after z.
  • German phonebook (DIN 5007-2) reads ä, ö, ü as ae, oe, ue, so Müller files with Mueller and Mössbauer sorts before Mosel.
  • Swedish sorts å, ä, ö after z, as the last three letters of the alphabet.
  • Icelandic treats á and ó as separate letters and ends the alphabet with þ, æ, ö. Directories list people by given name, because a patronymic changes with each generation.
  • Case order is tailored too: English sorts lowercase first, Danish capitals first. For most apps the right default is sensitivity: "base" with a secondary tiebreaker.

The fix

Pass new Intl.Collator(locale).compare to every .sort() on a user-visible list.

Sort is not search

usage: "search" loads CLDR's matching rules, which are separate from its sort rules, and sensitivity sets which differences count. A name matches when compare(query, name) === 0.

new Intl.Collator("en", { usage: "search", sensitivity: "base" })

  • Müllermatch
  • Muellerno match
  • Möllerno match
  • Núñezno match
  • Åströmno match
  • Célineno match
The fix: For find-as-you-type, filters, and duplicate checks, build a separate collator with usage: "search" and an explicit sensitivity (base for a search box). Do not reuse the sort collator or strip accents with a regex.

Implementation rules

  • Sort user-facing strings with Intl.Collator. Instantiate a collator with the active locale and pass collator.compare to Array.prototype.sort().
  • Separate sort collation from search collation. Use usage: "sort" for ordered lists. Use usage: "search" with sensitivity: "base" for user filtering so queries match base characters and locale equivalences.
  • Enable numeric collation for alphanumeric labels. Pass { numeric: true } so digit sequences compare by numeric value and file2 sorts before file10.
  • Match database column collations to the application locale. Configure ICU collations in SQL databases (such as PostgreSQL COLLATE "de-DE-x-icu") so server-side ORDER BY queries match client-side sort order.

Operational context

Roles

EngineeringProduct

Workflow stages

  • ·Implementing sortable tables and directories
  • ·Designing database schemas and indexes
  • ·Supporting locales with tailored alphabets

See it in a market: Sweden · ä sorts after z →

Production incident

Germany standardizes two alphabetical orders under DIN 5007: DIN 5007-1 for general dictionaries (where ä sorts with a) and DIN 5007-2 for name directories (where ä sorts as ae so Müller files alongside Mueller). Default code-point sorting satisfies neither standard because it places ä after z.

Wikipedia: German orthography (alphabetization) ↗

Terms in this chapter

Further reading

Related chapters