在计算机科学中，多语言标记指使用一系列有效的标记语言写成的文档或脚本。它独立于标记语言分析器、输出引擎或编译器，但能以相同的方式输出。总而言之，the polyglot markup is a common subset of two or more languages, that can be used as a robust or simplified profile.
Polyglot HTML is HTML that has been written to conform to both the HTML and XHTML specifications. A polyglot document can therefore be parsed as either HTML (which is SGML-compatible) or XML, and will produce the same DOM structure either way. For example, in order for an HTML5 document to meet these criteria, the two requirements are that it must have an HTML5 doctype, and be written in well-formed XHTML. The same document can then be served as either HTML or XHTML, depending on browser support and MIME type.
As expressed by the html-polyglot recommendation, to write a polyglot HTML5 document, the following key points should be observed:
- Processing instructions and the XML declaration
- Specifying a document’s character encoding
- Element syntax
- Element content
- Named entity references
- Scripting and styling polyglot markup
The most basic possible polyglot markup document would therefore look like this:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang=""> <head> <title>The title element must not be empty.</title> </head> <body> </body> </html>
In a polyglot markup document non-void elements (such as
div) cannot be self-closing even if they are empty, as this is not valid HTML. For example, to add an empty textarea to a page, one can not use
<textarea/>, but has to use
- Polyglot Markup: HTML-Compatible XHTML Documents, W3C Working Draft 5 April 2011
- The WhatWG Blog - XHTML5 in a nutshell, 25 July 2010
- Polyglot Markup: HTML-Compatible XHTML Documents: 6.4 Void Elements. W3C Editor's Draft 9 July 2012.