In computing, a polyglot markup is a document or script written in a valid form of multiple
markup languages, which performs the same output, independent of the markup's
parser,
layout engine, or
interpreter. In general, 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
The HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser. It can be assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaScri ...
that has been written to conform to both the HTML and
XHTML
Extensible HyperText Markup Language (XHTML) is part of the family of XML markup languages. It mirrors or extends versions of the widely used HyperText Markup Language (HTML), the language in which Web pages are formulated.
While HTML, prior ...
specifications.
[Polyglot Markup: A robust profile of the HTML5 vocabulary](_blank)
W3C Working Group Note 29 September 2015 A polyglot document can therefore be parsed as either HTML (which is
SGML
The Standard Generalized Markup Language (SGML; ISO 8879:1986) is a standard for defining generalized markup languages for documents. ISO 8879 Annex A.1 states that generalized markup is "based on two postulates":
* Declarative: Markup should des ...
-compatible) or
XML
Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. T ...
, and will produce the same
DOM Dom or DOM may refer to:
People and fictional characters
* Dom (given name), including fictional characters
* Dom (surname)
* Dom La Nena (born 1989), stage name of Brazilian-born cellist, singer and songwriter Dominique Pinto
* Dom people, an et ...
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 #REDIRECT Document type declaration #REDIRECT Document type declaration
{{redirect category shell, {{R move{{R from other capitalisation{{R up ...
{{redirect category shell, {{R move{{R from other capitalisation{{R up ...
, 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.
to write a polyglot HTML5 document, the following key points should be observed:
# Processing instructions and the XML declaration are both forbidden in polyglot markup
# Specifying a document’s character encoding
# The DOCTYPE
# Namespaces
# Element syntax (i.e. End tags are not optional. Use self-closing tags for void elements.)
# Element content
# Text (i.e. pre and textarea should not start with newline character)
# Attributes (i.e. Values must be quoted)
# Named entity references (i.e. Only amp, lt, gt, apos, quot)
# Comments (i.e. Use <!-- syntax -->)
# Scripting and styling polyglot markup
The most basic possible polyglot markup document would therefore look like this:
) cannot be self-closing even if they are empty, as this is not valid HTML.