html.elements
import html
htmlexposes this ashtml.elements, soimport htmlis enough and the names are called ashtml.elements.*.import html.elementsreaches the same definitions directly.
The element tables the tree construction algorithm consults on almost every token: which elements are “special”, which are formatting elements, which close which, and how SVG and MathML tag and attribute names have to be repaired after the tokenizer has lowercased them.
These are data, lifted from the WHATWG HTML Living Standard. They live
apart from html.parser so the algorithm there reads as the algorithm
and not as a wall of lists.
Constants
SPECIAL_HTML
html.elements.SPECIAL_HTML = [...]
The HTML elements the standard calls “special”: the ones a list item or definition term stops searching past, and the ones the adoption agency algorithm treats as a block boundary when it looks for the furthest block.
Nothing to do with CSS. This is purely the tree construction algorithm’s own category.
SPECIAL_MATHML
html.elements.SPECIAL_MATHML = [...]
The MathML elements that count as special.
SPECIAL_SVG
html.elements.SPECIAL_SVG = [...]
The SVG elements that count as special.
FORMATTING_ELEMENTS
html.elements.FORMATTING_ELEMENTS = [...]
The formatting elements: the ones the adoption agency algorithm reopens
across a badly nested boundary, so that <b>a<p>b</b>c puts a fresh
<b> inside the paragraph.
SCOPE_HTML
html.elements.SCOPE_HTML = [...]
The HTML elements that make up the “in scope” barrier every scope check shares. The narrower checks (list item scope, button scope) add to this list rather than replacing it.
IMPLIED_END_TAGS
html.elements.IMPLIED_END_TAGS = [...]
Elements whose end tag is implied by the start of a sibling, so that
<li>a<li>b produces two list items rather than nesting.
THOROUGH_IMPLIED_END_TAGS
html.elements.THOROUGH_IMPLIED_END_TAGS = [...]
Everything in IMPLIED_END_TAGS plus the elements
only closed when the standard says to generate implied end tags
thoroughly, which is what </template> and the table sections do.
MATHML_TEXT_INTEGRATION_POINTS
html.elements.MATHML_TEXT_INTEGRATION_POINTS = [...]
The MathML elements whose children are parsed as HTML rather than as MathML.
SVG_HTML_INTEGRATION_POINTS
html.elements.SVG_HTML_INTEGRATION_POINTS = [...]
The SVG elements whose children are parsed as HTML rather than as SVG.
FOREIGN_BREAKOUT_TAGS
html.elements.FOREIGN_BREAKOUT_TAGS = [...]
Start tags that are always a mistake inside foreign content and that break out of it, closing SVG or MathML elements until an HTML insertion point is reached.
SVG_TAG_NAMES
html.elements.SVG_TAG_NAMES = {...}
SVG tag names the tokenizer lowercased and that have to be put back,
keyed by the lowercase form. SVG is case-sensitive and <foreignobject>
is not the same element as <foreignObject>.
SVG_ATTRIBUTES
html.elements.SVG_ATTRIBUTES = {...}
SVG attribute names the tokenizer lowercased and that have to be put back, keyed by the lowercase form.
MATHML_ATTRIBUTES
html.elements.MATHML_ATTRIBUTES = {...}
The one MathML attribute whose case the tokenizer destroys.
FOREIGN_ATTRIBUTES
html.elements.FOREIGN_ATTRIBUTES = {...}
Attributes in foreign content that belong to a namespace, mapping the lowercase name the tokenizer produced to the qualified name and the namespace URI it should carry.
QUIRKS_PUBLIC_PREFIXES
html.elements.QUIRKS_PUBLIC_PREFIXES = [...]
Public identifier prefixes that put a document in quirks mode, in lowercase for case-insensitive comparison.
QUIRKS_PUBLIC_EXACT
html.elements.QUIRKS_PUBLIC_EXACT = [...]
The two public identifiers that put a document in quirks mode on an exact match rather than a prefix match, in lowercase.
LIMITED_QUIRKS_PUBLIC_PREFIXES
html.elements.LIMITED_QUIRKS_PUBLIC_PREFIXES = [...]
Public identifier prefixes that always mean limited-quirks mode.
HTML4_TRANSITIONAL_PREFIXES
html.elements.HTML4_TRANSITIONAL_PREFIXES = [...]
Public identifier prefixes whose mode depends on whether the doctype also carries a system identifier: quirks without one, limited-quirks with one.
QUIRKS_SYSTEM_ID
html.elements.QUIRKS_SYSTEM_ID
The system identifier that alone puts a document in quirks mode, in lowercase.
Functions
is_special()
html.elements.is_special(namespace: string, name: string) -> bool
True when the element name in namespace namespace is one of the standard’s special elements.
Parameters
namespace(string)name(string)
Returns bool
is_mathml_text_integration_point()
html.elements.is_mathml_text_integration_point(element) -> bool
True when element is a MathML text integration point, meaning its children are parsed as HTML.
Parameters
element(any)
Returns bool
is_html_integration_point()
html.elements.is_html_integration_point(element) -> bool
True when element is an HTML integration point.
An <annotation-xml> qualifies only when its encoding attribute names
an HTML flavour, which is how MathML embeds real markup.
Parameters
element(any)
Returns bool
adjust_svg_tag_name()
html.elements.adjust_svg_tag_name(name: string) -> string
The correctly cased SVG tag name for the lowercase name the tokenizer produced, or name itself when it needs no repair.
Parameters
name(string)
Returns string
adjust_svg_attributes()
html.elements.adjust_svg_attributes(attributes: dict) -> dict
Repairs the case of SVG attribute names in attributes and returns a new dictionary. Attributes that need no repair are copied across untouched, in their original order.
Parameters
attributes(dict)
Returns dict
adjust_mathml_attributes()
html.elements.adjust_mathml_attributes(attributes: dict) -> dict
Repairs the case of MathML attribute names in attributes and returns a new dictionary.
Parameters
attributes(dict)
Returns dict
doctype_mode()
html.elements.doctype_mode(name: ?string, public_id: ?string, system_id: ?string, force_quirks: bool) -> string
Which quirks mode a doctype puts a document in.
name may be nil for a doctype with no name at all, and the two
identifiers may be nil when the doctype omits them; all three cases
mean something different to the algorithm, which is why they are not
folded into empty strings.
Returns 'no-quirks', 'limited-quirks' or 'quirks'. Nothing in this
module behaves differently between them, but knowing which one a browser
would have picked is exactly the question you are asking when you audit
a legacy document.
Parameters
name(?string)public_id(?string)system_id(?string)force_quirks(bool)
Returns string
2026, Richard Ore and The Zuri Contributors