← Chrome 160 reference · All APIs
v160 · dom · enabled by default
Case-sensitive anchor name matching in quirks mode
Fragment navigation in quirks-mode HTML documents (document.compatMode === "BackCompat") now matches <a name="…"> attributes using exact case-sensitive code-unit comparison, matching standards mode, Firefox, Safari, and the HTML Living Standard. Navigating to #Foo no longer scrolls to or sets :target on <a name="foo">.
at a glance
| Shipped in | Chrome 160 (desktop, Android, Android WebView), enabled by default — listed under “Enabled by default” in the milestone=160 listing and confirmed in the ChromeStatus API record |
|---|---|
| Kill switch / flag | No origin trial, no user-facing chrome://flags toggle. Blink runtime flag CaseSensitiveAnchorMatching is status: "stable" in runtime_enabled_features.json5 (kill switch planned for removal in M162; emergency rollback via --disable-blink-features=CaseSensitiveAnchorMatching) |
| Specification | HTML Living Standard — find a potential indicated element & the indicated part of the document |
| Tracking bug | issues.chromium.org/40829784 |
| Telemetry | UseCounter 5784 (AnchorCaseSensitiveMatch); UseCounter 5785 (AnchorCaseInsensitiveMatch) (~0.00015% of page loads) |
| Web platform tests | wpt.fyi — scroll-to-anchor-name-quirks-case.html (WPT source) |
| ChromeStatus | 5085237991309312 — Case-sensitive anchor name matching in quirks mode |
why it exists
In quirks mode (pages rendered without a standards <!doctype html> declaration, where document.compatMode === "BackCompat"), Chromium previously ran a legacy case-insensitive fallback (DeprecatedEqualIgnoringCase) when resolving URL fragments against <a name="…"> elements. Neither Firefox, Safari, nor the HTML Living Standard perform case-insensitive anchor name matching in quirks mode. Worse, Chromium’s single-pass tree traversal could let an earlier case-mismatched <a name="Destination"> shadow a later exact <a name="destination">. With telemetry showing the fallback fired on only ~0.00015% of page loads, Chrome 160 removes it to achieve cross-browser interoperability.
Syntax
No new HTML element, attribute, or JavaScript API syntax is introduced. This change updates fragment-identifier resolution against the existing (obsolete in HTML5) <a name="…"> attribute in quirks-mode documents (document.compatMode === "BackCompat") and aligns it with case-sensitive id matching:
<!-- Quirks-mode HTML document (no <!doctype html>): document.compatMode === "BackCompat" -->
<a name="section-Alpha"></a>
<!-- Fragment link & CSS :target matching -->
<a href="#section-Alpha">Matches (exact case)</a>
<a href="#section-alpha">Does NOT match in Chrome 160+</a>
<!-- Preferred modern replacement (case-sensitive in all modes) -->
<section id="section-Alpha">...</section>
“To find a potential indicated element given a
Documentdocument and a string fragment, run these steps: 1. If there is an element in the document tree whose root is document and that has an ID equal to fragment, then return the first such element in tree order. 2. If there is anaelement in the document tree whose root is document that has anameattribute whose value is equal to fragment, then return the first such element in tree order. 3. Return null.”
This reference covers both parts of the Chrome 160 change: the case-sensitive quirks-mode <a name> fragment lookup algorithm and migrating quirks-mode documents from case-mismatched name anchors to exact-case or id targets.
a name attribute.
Quirks-mode fragment lookup — inputs and outputs
Inputs. A quirks-mode HTML Document (document.compatMode === "BackCompat") and a URL fragment string (from initial navigation, clicking <a href="#…">, assigning location.hash, or history traversal).
Outputs. Returns the indicated DOM node (updating CSS :target and scrolling the element into view), the special value top of the document, or null (clearing :target with no scroll). Per the HTML specification and Blink’s TreeScope::FindAnchor() / FindAnchorWithName():
- If the raw fragment is the empty string
"", return the top of the document. - Look up the raw fragment via
FindAnchorWithName(fragment): first checkgetElementById(fragment)(always exact case-sensitive), then scan<a>elements in tree order for an exact code-unit matchanchor.getAttribute("name") === fragment. - If step 2 returns
null, percent-decode the fragment as UTF-8 without BOM to producedecodedFragmentand runFindAnchorWithName(decodedFragment)again using exact case-sensitive matching. - If still
nullanddecodedFragmentis an ASCII case-insensitive match for"top"(for example#TOPor#Top), return the top of the document. (This special#toprule is unchanged.) - Otherwise return
null.
| Anchor markup in quirks mode | Fragment | Chrome ≤ 159 | Chrome 160+ / Firefox / Safari |
|---|---|---|---|
<a name="sample_é"> | #sample_é | Matches | Matches |
<a name="sample_é"> | #SAMPLE_é (ASCII case mismatch) | Matched (fallback) | null (no match) |
<a name="sample_é"> | #sample_É (non-ASCII case mismatch) | Matched (fallback) | null (no match) |
<a name="sample_é"> | #ſample_é (U+017F Unicode fold) | Matched (fallback) | null (no match) |
<a name="Destination"> then <a name="destination"> | #destination | Matched earlier Destination | Matches exact destination |
| Any document (no matching id/name) | #TOP | Top of document | Top of document (unchanged) |
Errors, silent misses, and migration
Error behavior. A case-mismatched fragment does not throw a JavaScript exception or log a console error. Assigning location.hash = "#Foo" still updates the URL and fires hashchange, but document.querySelector(":target") becomes null and the browser does not scroll to <a name="foo">.
Migration steps for legacy quirks-mode pages (document.compatMode === "BackCompat"):
- Normalize case on links and anchors: Update in-page
<a href="#…">links and<a name="…">targets so their casing matches identically (code-unit for code-unit). - Migrate from obsolete
nametoid: The HTML Living Standard marks<a name>obsolete; replacing<a name="foo">with anid="foo"attribute on the target heading or section works identically in quirks mode and standards mode (andidlookup always runs before<a name>lookup). - Exit quirks mode when feasible: Adding
<!doctype html>switches the document to standards mode (document.compatMode === "CSS1Compat"), eliminating quirks-mode layout and matching divergences altogether. - Enterprise/testing rollback: During Chrome 160–161, Chromium retains the
CaseSensitiveAnchorMatchingruntime flag (--disable-blink-features=CaseSensitiveAnchorMatching) for emergency testing; the flag comment in runtime_enabled_features.json5 notes planned kill-switch removal in M162.
a name.
Context and exposure
This behavior applies to HTML documents rendered in quirks mode (document.compatMode === "BackCompat") in any top-level browsing context or <iframe> on desktop, Android, and Android WebView. Standards mode (CSS1Compat) and limited-quirks mode already performed case-sensitive id and <a name> lookup. Fragment lookup operates within the document’s own tree scope (TreeScope); elements inside shadow trees are not matched by document fragment navigation. No secure context, permission, or JavaScript is required.
Lifecycle and timing
Fragment anchor resolution runs whenever the browser navigates to a URL containing a fragment, clicks a same-document fragment link, updates location.hash, or traverses session history entries with fragments. On each resolution, the document updates its target element (observable immediately via document.querySelector(":target")) and scrolls the indicated element into view if found. Removing the case-insensitive fallback also guarantees that an earlier case-mismatched <a name> in tree order cannot preempt a later exact-case <a name>.
Examples
No live demo exists yet on the Chrome Platform Showcase for this feature.
Quirks-mode fragment matching in Chrome 160+
<!-- Intentionally missing <!doctype html> so document.compatMode === "BackCompat" -->
<html>
<head><meta charset="utf-8"></head>
<body>
<a name="sample_é" id="anchor">Exact target</a>
<a name="Destination" id="earlier-anchor">Different case</a>
<a name="destination" id="exact-anchor">Exact lowercase</a>
<script>
console.assert(document.compatMode === "BackCompat");
// 1. Exact case matches:
location.hash = "#sample_é";
document.querySelector(":target")?.id; // "anchor"
// 2. ASCII, non-ASCII, and Unicode case-fold mismatches all return null:
location.hash = "#SAMPLE_é";
document.querySelector(":target"); // null
location.hash = "#sample_É";
document.querySelector(":target"); // null
location.hash = "#\u017Fample_é"; // U+017F long s
document.querySelector(":target"); // null
// 3. Earlier case-mismatched <a name="Destination"> no longer hides exact match:
location.hash = "#destination";
document.querySelector(":target")?.id; // "exact-anchor"
</script>
</body>
</html>
Source: Adapted from WPT scroll-to-anchor-name-quirks-case.html.
Auditing quirks-mode pages for case-mismatched <a name> links
// Run in DevTools or automated checks on legacy quirks-mode pages:
function findCaseMismatchedFragmentLinks() {
if (document.compatMode !== "BackCompat") return [];
const exactIds = new Set([...document.querySelectorAll("[id]")].map((el) => el.id));
const anchorNames = [...document.querySelectorAll("a[name]")]
.map((a) => a.getAttribute("name"))
.filter(Boolean);
const exactNames = new Set(anchorNames);
const lowerNames = new Map(anchorNames.map((n) => [n.toLowerCase(), n]));
const broken = [];
for (const link of document.querySelectorAll('a[href^="#"]')) {
const raw = link.getAttribute("href").slice(1);
if (!raw || raw.toLowerCase() === "top") continue;
const decoded = decodeURIComponent(raw);
if (exactIds.has(raw) || exactIds.has(decoded)) continue;
if (exactNames.has(raw) || exactNames.has(decoded)) continue;
const matchedName = lowerNames.get(raw.toLowerCase()) ?? lowerNames.get(decoded.toLowerCase());
if (matchedName) {
broken.push({ href: link.getAttribute("href"), expectedName: matchedName, link });
}
}
return broken;
}
// Recommended fix: add <!doctype html> and replace <a name="faq"> with <h2 id="faq">
Source: Derived from HTML Living Standard fragment lookup steps and ChromeStatus 5085237991309312 migration notes.
Browser compatibility
| Browser | Case-sensitive in quirks mode | Evidence / notes | <a name> attribute (BCD) |
|---|---|---|---|
| Chrome (desktop, Android, WebView) | 160 | CaseSensitiveAnchorMatching set to status: "stable" for M160 per ChromeStatus 5085237991309312 and runtime_enabled_features.json5 | 1 (deprecated) |
| Edge | 160 (expected) | Chromium-based (feature authored by Microsoft engineers); wpt.fyi Edge 160.0.4408.0 recorded 2/6 prior to stable flag flip (checked 2026-11-24) | 12 (deprecated) |
| Firefox | Shipped | Already case-sensitive in quirks mode per ChromeStatus (exact historical version unrecorded in BCD) | 1 (deprecated) |
| Safari | Shipped | Already case-sensitive in quirks mode per ChromeStatus (exact historical version unrecorded in BCD) | 1 (deprecated) |
Security and privacy
ChromeStatus 5085237991309312 records security_risks: "None" and marks Security and Privacy reviews Not applicable. Removing Chromium’s legacy case-insensitive fallback in quirks mode introduces no new storage, permission, or cross-origin channel; it narrows fragment matching to exact code-unit equality and removes an ambiguity where an earlier case-mismatched <a name> element could intercept :target styling and scroll focus intended for an exact-case anchor.