HTML 5 Custom element names?

后端 未结 1 441
無奈伤痛
無奈伤痛 2020-12-21 07:20

In HTML 5 specification the parser and the specification state that the element name can be everything starting with a letter and followed by alpha-numeric characters.

相关标签:
1条回答
  • 2020-12-21 08:01

    In HTML 5 specification the parser and the specification state that the element name can be everything starting with a letter and followed by alpha-numeric characters.

    Incorrect. The specification states that the element name must be one of the names explicitly listed in that document, or in another applicable specification. These include but are not limited to SVG and MathML.

    The specification also includes a processing specification for consumers of HTML, such as browsers. This doesn't describe what's "allowed", it describes what those consumers should do with each character of the document regardless of whether it contains things that are allowed or not allowed.

    Now the question is what happens if I introduce additional elements not part of the specification but valid in terms of compliance to the specified syntax.

    The above rules are followed. The "specified syntax" is irrelevant. The specification describes what the consumer should do for any input stream of characters.

    What do all those browsers do when they encounter elements with custom yet unknown name? Does those elements got treated like any element or are they left out, stripped out or replaced?

    They are treated as elements in the http://www.w3.org/1999/xhtml namespace which implement the HTMLUnknownElement interface.

    How for instance do HTML5 editor behave?

    If they are HTML5 compliant they will behave the same way when reading in the HTML.

    Is there anything in the specifications I have overlooked regarding valid element tag names?

    See the first paragraph above. Also the Custom Elements spec which makes any element name starting with an ASCII letter and containing a hyphen to be considered valid. It is unclear whether that specification is currently an "HTML5 applicable specification" but if not, it will very probably be one soon.

    0 讨论(0)
提交回复
热议问题