What does exclamation point stand for in HTML in constructs like DOCTYPE and comments?
Asked Answered
P

4

15

I am curious about the syntax of the doctype and comment tags...

Why the exclamation point? What is it called, what does it mean/do?

I have read through the HTML syntax spec and found no real explanation other than

Any case-insensitive match for the string <!DOCTYPE.

Cite: http://www.w3.org/TR/html-markup/syntax.html#doctype-syntax

Peevish answered 1/5, 2013 at 15:24 Comment(0)
H
26

In SGML, which is what HTML was nominally based on, up to and including HTML 4.01, the exclamation mark is part of the construct <!, which is the reference concrete syntax for mdo, markup declaration open. Markup declarations are not markup elements but, informally speaking, declarations relating to elements. This includes document type declaration, comment declarations, and entity declarations.

In XML, which is what XHTML is based on, there is no general concept like that. Instead, the character pair <! just appears in some constructs, with no uniform theory.

In HTML5, the HTML syntax has been defined very much in an ad hoc manner, and the doctype string is called just the doctype string – it has no role and no meaning beyond the expected effect of triggering “standards mode” (or “no-quirks mode”) in browsers. In the XHTML syntax, it has its XML meaning.

Hartford answered 1/5, 2013 at 18:44 Comment(1)
Perfect answer for the XML: grepping w3.org/TR/xml for <! shows how each <! grammar case is defined one by one. Of course, the underlying idea of all of them is: "this is a magic instruction for the parser, not part of your regular data."Bennie
R
6

The ! is used for comments (<!-- -->) and to define the DOCTYPE (<!DOCTYPE ...>) of the HTML document. The DOCTYPE describe some characteristics of the document such as the root of the XML/XHTML/HTML file (in HTML usually is <html>), a DTD, a Public Identifier and other subset declarations.

Rhonarhonchus answered 1/5, 2013 at 15:29 Comment(1)
Also used for <![CDATA sections.Turbidimeter
N
1

From the specification of HTML from the Cern docs:

MDO

Markup Declaration Open: "<!", when followed by a letter or "--" or "[", signals one of several SGML markup declarations. The only purpose it serves in HTML is to introduce comments.

Source: http://info.cern.ch/hypertext/WWW/MarkUp/Connolly/Text.html

Ng answered 2/2, 2017 at 7:0 Comment(0)
D
0

A <!DOCTYPE ...> is a SGML document type declaration. Its purpose is to tell an SGML parser what DTD it should use to parse the document.

Dynameter answered 13/8, 2016 at 10:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.