Skip to content

MDN "lang" page says incorrectly says "the default value of lang is the empty string", which is wrong -- explicit-empty-string vs. missing-attribute have different semantics #43259

@dholbert

Description

@dholbert

MDN URL

https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/lang

What specific section or headline is this issue about?

"Note: The default value of lang is the empty string, which means that the language is unknown."

What information was incorrect, unhelpful, or incomplete?

"Note: The default value of lang is the empty string,"

What did you expect to see?

Either this statement being removed, or it expanded to be more accurate.

Do you have any supporting links, references, or citations?

https://html.spec.whatwg.org/multipage/dom.html#language

Do you have anything more you want to share?

Notes on why the statement is incorrect:

https://html.spec.whatwg.org/multipage/dom.html#language has the details, and it is conditioned on whether the attribute is set. (which means the attribute being set to the empty string vs. being unset are semantically different)

If the lang attribute is explicitly set to the empty string, then the spec says that the language is explicitly unknown per [1].

But when when the lang attribute is not set on an element, then the spec defines a variety of other sources that browsers should use to establish the language (including the element's parent node, or shadow root, or "a pragma-set default language", or language information from another involved protocol like from an HTTP header.

[1] Here's the spec text that says an explicit empty-string value results in the language being explicitly-unknown:

To determine the language of a node, user agents must use the first appropriate step in the following list:
[...]

  • If the node is an HTML element or an element in the SVG namespace, and it has a lang in no namespace attribute set
    Use the value of that attribute.
    [...]
    If the resulting value is the empty string, then it must be interpreted as meaning that the language of the node is explicitly unknown.

It looks like this note was last modified in #32604 / 1a84803 which replaced another bit of incorrect information ("The default value of lang is unknown"), but the replacement about the empty string is also incorrect.

MDN metadata

Page report details

Metadata

Metadata

Assignees

No one assigned

    Labels

    Content:HTMLHypertext Markup Language docsneeds triageTriage needed by staff and/or partners. Automatically applied when an issue is opened.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions