Annotation of html5/spec/syntax.html, revision 1.1233
1.1139 mike 1: <!DOCTYPE html>
1.1210 sruby 2: <html lang="en-US-x-Hixie"><head><title>8 The HTML syntax — HTML5</title><style type="text/css">
1.1 mike 3: pre { margin-left: 2em; white-space: pre-wrap; }
4: h2 { margin: 3em 0 1em 0; }
5: h3 { margin: 2.5em 0 1em 0; }
6: h4 { margin: 2.5em 0 0.75em 0; }
7: h5, h6 { margin: 2.5em 0 1em; }
8: h1 + h2, h1 + h2 + h2 { margin: 0.75em 0 0.75em; }
9: h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 0.5em; }
10: p { margin: 1em 0; }
11: hr:not(.top) { display: block; background: none; border: none; padding: 0; margin: 2em 0; height: auto; }
12: dl, dd { margin-top: 0; margin-bottom: 0; }
13: dt { margin-top: 0.75em; margin-bottom: 0.25em; clear: left; }
14: dt + dt { margin-top: 0; }
15: dd dt { margin-top: 0.25em; margin-bottom: 0; }
16: dd p { margin-top: 0; }
17: dd dl + p { margin-top: 1em; }
18: dd table + p { margin-top: 1em; }
19: p + * > li, dd li { margin: 1em 0; }
20: dt, dfn { font-weight: bold; font-style: normal; }
1.1045 mike 21: i, em { font-style: italic; }
1.1 mike 22: dt dfn { font-style: italic; }
23: pre, code { font-size: inherit; font-family: monospace; font-variant: normal; }
24: pre strong { color: black; font: inherit; font-weight: bold; background: yellow; }
25: pre em { font-weight: bolder; font-style: normal; }
26: @media screen { code { color: orangered; } code :link, code :visited { color: inherit; } }
27: var sub { vertical-align: bottom; font-size: smaller; position: relative; top: 0.1em; }
28: table { border-collapse: collapse; border-style: hidden hidden none hidden; }
1.983 mike 29: table thead, table tbody { border-bottom: solid; }
1.1 mike 30: table tbody th:first-child { border-left: solid; }
1.475 mike 31: table tbody th { text-align: left; }
1.1 mike 32: table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
33: blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }
34:
35: .bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
36: .matrix, .matrix td { border: none; text-align: right; }
37: .matrix { margin-left: 2em; }
38: .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
39: .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
40: .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
41:
42: .toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
1.1048 mike 43: img.extra, p.overview { float: right; }
1.1047 mike 44: pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; position: relative; }
1.1 mike 45: pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
1.1047 mike 46: pre.idl::before { content: "IDL"; font: bold small sans-serif; padding: 0.5em; background: white; position: absolute; top: 0; margin: -1px 0 0 -4em; width: 1.5em; border: thin solid; border-radius: 0 0 0 0.5em }
1.1 mike 47: pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
48: pre.css:first-line { color: #AAAA50; }
1.840 mike 49: dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #DDFFDD; }
1.1 mike 50: hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
51: dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
52: dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
53: dl.domintro dd p { margin: 0.5em 0; }
1.1050 mike 54: dl.domintro:before { display: table; margin: -1em -0.5em -0.5em auto; width: auto; content: 'This box is non-normative. Implementation requirements are given below this box.'; color: black; font-style: italic; border: solid 2px; background: white; padding: 0 0.25em; }
1.1 mike 55: dl.switch { padding-left: 2em; }
56: dl.switch > dt { text-indent: -1.5em; }
57: dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
58: dl.triple { padding: 0 0 0 1em; }
59: dl.triple dt, dl.triple dd { margin: 0; display: inline }
60: dl.triple dt:after { content: ':'; }
61: dl.triple dd:after { content: '\A'; white-space: pre; }
62: .diff-old { text-decoration: line-through; color: silver; background: transparent; }
63: .diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
64: a .diff-new { border-bottom: 1px blue solid; }
65:
1.1232 sruby 66: figure.diagrams { border: double black; background: white; padding: 1em; }
67: figure.diagrams img { display: block; margin: 1em auto; }
68:
1.1 mike 69: h2 { page-break-before: always; }
70: h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
71: h1 + h2, hr + h2.no-toc { page-break-before: auto; }
72:
1.1016 mike 73: p > span:not([title=""]):not([class="XXX"]):not([class="impl"]):not([class="note"]),
74: li > span:not([title=""]):not([class="XXX"]):not([class="impl"]):not([class="note"]), { border-bottom: solid #9999CC; }
1.1 mike 75:
76: div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
77: div.head p { margin: 0; }
78: div.head h1 { margin: 0; }
79: div.head .logo { float: right; margin: 0 1em; }
80: div.head .logo img { border: none } /* remove border from top image */
81: div.head dl { margin: 1em 0; }
1.671 mike 82: div.head p.copyright, div.head p.alt { font-size: x-small; font-style: oblique; margin: 0; }
1.1 mike 83:
84: body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
85: body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
86: body > .toc > li > * { margin-bottom: 0.5em; }
87: body > .toc > li > * > li > * { margin-bottom: 0.25em; }
88: .toc, .toc li { list-style: none; }
89:
90: .brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
91: .brief li { margin: 0; padding: 0; }
92: .brief li p { margin: 0; padding: 0; }
93:
94: .category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
95: .category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
96: .category-list li { display: inline; }
97: .category-list li:not(:last-child)::after { content: ', '; }
98: .category-list li > span, .category-list li > a { text-transform: lowercase; }
99: .category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
100:
101: .XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
102: .XXX > :first-child { margin-top: 0; }
103: p .XXX { line-height: 3em; }
1.159 mike 104: .annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
105: .annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
106: .annotation :link, .annotation :visited { color: inherit; }
107: .annotation :link:hover, .annotation :visited:hover { background: transparent; }
108: .annotation span { border: none ! important; }
1.1 mike 109: .note { color: green; background: transparent; font-family: sans-serif; }
110: .warning { color: red; background: transparent; }
111: .note, .warning { font-weight: bolder; font-style: italic; }
1.1045 mike 112: .note em, .warning em, .note i, .warning i { font-style: normal; }
1.1 mike 113: p.note, div.note { padding: 0.5em 2em; }
114: span.note { padding: 0 2em; }
115: .note p:first-child, .warning p:first-child { margin-top: 0; }
116: .note p:last-child, .warning p:last-child { margin-bottom: 0; }
117: .warning:before { font-style: normal; }
118: p.note:before { content: 'Note: '; }
119: p.warning:before { content: '\26A0 Warning! '; }
120:
121: .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
122: .bookkeeping { font-size: 0.8em; margin: 2em 0; }
123: .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
1.1006 mike 124: .bookkeeping dt { margin: 0.5em 2em 0; }
125: .bookkeeping dd { margin: 0 3em 0.5em; }
1.1 mike 126:
127: h4 { position: relative; z-index: 3; }
128: h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
129: .element {
130: background: #EEEEFF;
131: color: black;
132: margin: 0 0 1em 0.15em;
133: padding: 0 1em 0.25em 0.75em;
134: border-left: solid #9999FF 0.25em;
135: position: relative;
136: z-index: 1;
137: }
138: .element:before {
139: position: absolute;
140: z-index: 2;
141: top: 0;
142: left: -1.15em;
143: height: 2em;
144: width: 0.9em;
145: background: #EEEEFF;
146: content: ' ';
147: border-style: none none solid solid;
148: border-color: #9999FF;
149: border-width: 0.25em;
150: }
151:
1.149 mike 152: .example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
153: td > .example:only-child { margin: 0 0 0 0.1em; }
1.1 mike 154:
155: ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
156: ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
157: ul.domTree li li { list-style: none; }
158: ul.domTree li:first-child::before { position: absolute; top: 0; height: 0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
159: ul.domTree li:not(:last-child)::after { position: absolute; top: 0; bottom: -0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
160: ul.domTree span { font-style: italic; font-family: serif; }
161: ul.domTree .t1 code { color: purple; font-weight: bold; }
162: ul.domTree .t2 { font-style: normal; font-family: monospace; }
163: ul.domTree .t2 .name { color: black; font-weight: bold; }
164: ul.domTree .t2 .value { color: blue; font-weight: normal; }
165: ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
166: ul.domTree .t7 code, .domTree .t8 code { color: green; }
167: ul.domTree .t10 code { color: teal; }
168:
1.736 mike 169: body.dfnEnabled dfn { cursor: pointer; }
170: .dfnPanel {
171: display: inline;
172: position: absolute;
173: z-index: 10;
174: height: auto;
175: width: auto;
176: padding: 0.5em 0.75em;
177: font: small sans-serif, Droid Sans Fallback;
178: background: #DDDDDD;
179: color: black;
180: border: outset 0.2em;
181: }
182: .dfnPanel * { margin: 0; padding: 0; font: inherit; text-indent: 0; }
183: .dfnPanel :link, .dfnPanel :visited { color: black; }
184: .dfnPanel p { font-weight: bolder; }
185: .dfnPanel * + p { margin-top: 0.25em; }
186: .dfnPanel li { list-style-position: inside; }
187:
1.671 mike 188: #configUI { position: absolute; z-index: 20; top: 10em; right: 1em; width: 11em; font-size: small; }
189: #configUI p { margin: 0.5em 0; padding: 0.3em; background: #EEEEEE; color: black; border: inset thin; }
190: #configUI p label { display: block; }
191: #configUI #updateUI, #configUI .loginUI { text-align: center; }
192: #configUI input[type=button] { display: block; margin: auto; }
1.1002 mike 193:
1.1021 mike 194: fieldset { margin: 1em; padding: 0.5em 1em; }
195: fieldset > legend + * { margin-top: 0; }
1.1013 mike 196: fieldset > :last-child { margin-bottom: 0; }
1.1021 mike 197: fieldset p { margin: 0.5em 0; }
198:
1.1210 sruby 199: </style><link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel="stylesheet" type="text/css"><style type="text/css">
1.267 mike 200:
1.292 mike 201: .applies thead th > * { display: block; }
202: .applies thead code { display: block; }
203: .applies tbody th { whitespace: nowrap; }
204: .applies td { text-align: center; }
205: .applies .yes { background: yellow; }
206:
1.1007 mike 207: .matrix, .matrix td { border: hidden; text-align: right; }
1.267 mike 208: .matrix { margin-left: 2em; }
209:
210: .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
211: .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
212: .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
213:
1.1009 mike 214: td.eg { border-width: thin; text-align: center; }
215:
1.267 mike 216: #table-example-1 { border: solid thin; border-collapse: collapse; margin-left: 3em; }
217: #table-example-1 * { font-family: "Essays1743", serif; line-height: 1.01em; }
218: #table-example-1 caption { padding-bottom: 0.5em; }
219: #table-example-1 thead, #table-example-1 tbody { border: none; }
220: #table-example-1 th, #table-example-1 td { border: solid thin; }
221: #table-example-1 th { font-weight: normal; }
222: #table-example-1 td { border-style: none solid; vertical-align: top; }
223: #table-example-1 th { padding: 0.5em; vertical-align: middle; text-align: center; }
224: #table-example-1 tbody tr:first-child td { padding-top: 0.5em; }
225: #table-example-1 tbody tr:last-child td { padding-bottom: 1.5em; }
226: #table-example-1 tbody td:first-child { padding-left: 2.5em; padding-right: 0; width: 9em; }
227: #table-example-1 tbody td:first-child::after { content: leader(". "); }
228: #table-example-1 tbody td { padding-left: 2em; padding-right: 2em; }
229: #table-example-1 tbody td:first-child + td { width: 10em; }
230: #table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
231: #table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
232:
233: .apple-table-examples { border: none; border-collapse: separate; border-spacing: 1.5em 0em; width: 40em; margin-left: 3em; }
234: .apple-table-examples * { font-family: "Times", serif; }
235: .apple-table-examples td, .apple-table-examples th { border: none; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
236: .apple-table-examples tbody th:first-child { border-left: none; width: 100%; }
237: .apple-table-examples thead th:first-child ~ th { font-size: smaller; font-weight: bolder; border-bottom: solid 2px; text-align: center; }
238: .apple-table-examples tbody th::after, .apple-table-examples tfoot th::after { content: leader(". ") }
239: .apple-table-examples tbody th, .apple-table-examples tfoot th { font: inherit; text-align: left; }
240: .apple-table-examples td { text-align: right; vertical-align: top; }
241: .apple-table-examples.e1 tbody tr:last-child td { border-bottom: solid 1px; }
242: .apple-table-examples.e1 tbody + tbody tr:last-child td { border-bottom: double 3px; }
243: .apple-table-examples.e2 th[scope=row] { padding-left: 1em; }
244: .apple-table-examples sup { line-height: 0; }
245:
1.724 mike 246: .details-example img { vertical-align: top; }
247:
1.1028 mike 248: #base64-table {
249: white-space: nowrap;
250: font-size: 0.6em;
251: column-width: 6em;
252: column-count: 5;
253: column-gap: 1em;
254: -moz-column-width: 6em;
255: -moz-column-count: 5;
256: -moz-column-gap: 1em;
257: -webkit-column-width: 6em;
258: -webkit-column-count: 5;
259: -webkit-column-gap: 1em;
260: }
261: #base64-table thead { display: none; }
262: #base64-table * { border: none; }
263: #base64-table tbody td:first-child:after { content: ':'; }
264: #base64-table tbody td:last-child { text-align: right; }
265:
1.882 mike 266: #named-character-references-table {
1.1010 mike 267: white-space: nowrap;
1.882 mike 268: font-size: 0.6em;
1.1010 mike 269: column-width: 30em;
1.882 mike 270: column-gap: 1em;
1.1010 mike 271: -moz-column-width: 30em;
1.882 mike 272: -moz-column-gap: 1em;
1.1010 mike 273: -webkit-column-width: 30em;
1.882 mike 274: -webkit-column-gap: 1em;
275: }
1.1010 mike 276: #named-character-references-table > table > tbody > tr > td:first-child + td,
1.882 mike 277: #named-character-references-table > table > tbody > tr > td:last-child { text-align: center; }
278: #named-character-references-table > table > tbody > tr > td:last-child:hover > span { position: absolute; top: auto; left: auto; margin-left: 0.5em; line-height: 1.2; font-size: 5em; border: outset; padding: 0.25em 0.5em; background: white; width: 1.25em; height: auto; text-align: center; }
1.1010 mike 279: #named-character-references-table > table > tbody > tr#entity-CounterClockwiseContourIntegral > td:first-child { font-size: 0.5em; }
1.882 mike 280:
1.997 mike 281: .glyph.control { color: red; }
282:
1.999 mike 283: @font-face {
284: font-family: 'Essays1743';
1.1230 sruby 285: src: url('../fonts/Essays1743.ttf');
1.999 mike 286: }
287: @font-face {
288: font-family: 'Essays1743';
289: font-weight: bold;
1.1230 sruby 290: src: url('../fonts/Essays1743-Bold.ttf');
1.999 mike 291: }
292: @font-face {
293: font-family: 'Essays1743';
294: font-style: italic;
1.1230 sruby 295: src: url('../fonts/Essays1743-Italic.ttf');
1.999 mike 296: }
297: @font-face {
298: font-family: 'Essays1743';
299: font-style: italic;
300: font-weight: bold;
1.1230 sruby 301: src: url('../fonts/Essays1743-BoldItalic.ttf');
1.999 mike 302: }
303:
1.1210 sruby 304: </style><link href="data:text/css," id="complete" rel="stylesheet" title="Complete specification"><link href="data:text/css,.impl%20%7B%20display:%20none;%20%7D%0Ahtml%20%7B%20border:%20solid%20yellow;%20%7D%20.domintro:before%20%7B%20display:%20none;%20%7D" id="author" rel="alternate stylesheet" title="Author documentation only"><link href="data:text/css,.impl%20%7B%20background:%20%23FFEEEE;%20%7D%20.domintro:before%20%7B%20background:%20%23FFEEEE;%20%7D" id="highlight" rel="alternate stylesheet" title="Highlight implementation requirements"><script>
1.1033 mike 305: function getCookie(name) {
306: var params = location.search.substr(1).split("&");
307: for (var index = 0; index < params.length; index++) {
308: if (params[index] == name)
309: return "1";
310: var data = params[index].split("=");
311: if (data[0] == name)
312: return unescape(data[1]);
313: }
314: var cookies = document.cookie.split("; ");
315: for (var index = 0; index < cookies.length; index++) {
316: var data = cookies[index].split("=");
317: if (data[0] == name)
318: return unescape(data[1]);
319: }
320: return null;
321: }
1.1210 sruby 322: </script><link href="dnd.html" title="7.7 Drag and drop" rel="prev">
1.1213 sruby 323: <link href="spec.html#contents" title="Table of contents" rel="contents">
1.996 mike 324: <link href="parsing.html" title="8.2 Parsing HTML documents" rel="next">
1.1073 mike 325: </head><body onload="fixBrokenLink();" class="split chapter"><div class="head" id="head">
1.1 mike 326: <p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="http://www.w3.org/Icons/w3c_home" width="72"></a></p>
1.998 mike 327:
1.183 mike 328: <h1>HTML5</h1>
1.1210 sruby 329: <h2 class="no-num no-toc" id="a-vocabulary-and-associated-apis-for-html-and-xhtml">A vocabulary and associated APIs for HTML and XHTML</h2>
1.1233 ! sruby 330: <h2 class="no-num no-toc" id="editor's-draft-date-1-january-1970">Editor's Draft 20 September 2012</h2>
1.1136 mike 331: </div>
1.1226 sruby 332: <div class="prev_next">
1.1157 mike 333: <a href="dnd.html">← 7.7 Drag and drop</a> –
1.1213 sruby 334: <a href="spec.html#contents">Table of contents</a> –
1.1052 mike 335: <a href="parsing.html">8.2 Parsing HTML documents →</a>
1.996 mike 336: <ol class="toc"><li><a href="syntax.html#syntax"><span class="secno">8 </span>The HTML syntax</a>
337: <ol><li><a href="syntax.html#writing"><span class="secno">8.1 </span>Writing HTML documents</a>
338: <ol><li><a href="syntax.html#the-doctype"><span class="secno">8.1.1 </span>The DOCTYPE</a></li><li><a href="syntax.html#elements-0"><span class="secno">8.1.2 </span>Elements</a>
1.1210 sruby 339: <ol><li><a href="syntax.html#start-tags"><span class="secno">8.1.2.1 </span>Start tags</a></li><li><a href="syntax.html#end-tags"><span class="secno">8.1.2.2 </span>End tags</a></li><li><a href="syntax.html#attributes-0"><span class="secno">8.1.2.3 </span>Attributes</a></li><li><a href="syntax.html#optional-tags"><span class="secno">8.1.2.4 </span>Optional tags</a></li><li><a href="syntax.html#element-restrictions"><span class="secno">8.1.2.5 </span>Restrictions on content models</a></li><li><a href="syntax.html#cdata-rcdata-restrictions"><span class="secno">8.1.2.6 </span>Restrictions on the contents of raw text and RCDATA elements</a></li></ol></li><li><a href="syntax.html#text"><span class="secno">8.1.3 </span>Text</a>
340: <ol><li><a href="syntax.html#newlines"><span class="secno">8.1.3.1 </span>Newlines</a></li></ol></li><li><a href="syntax.html#character-references"><span class="secno">8.1.4 </span>Character references</a></li><li><a href="syntax.html#cdata-sections"><span class="secno">8.1.5 </span>CDATA sections</a></li><li><a href="syntax.html#comments"><span class="secno">8.1.6 </span>Comments</a></li></ol></li></ol></li></ol></div>
1.1 mike 341:
1.1136 mike 342: <h2 id="syntax"><span class="secno">8 </span><dfn>The HTML syntax</dfn></h2>
343:
344: <p class="note">This section only describes the rules for resources
1.725 mike 345: labeled with an <a href="infrastructure.html#html-mime-type">HTML MIME type</a>. Rules for XML resources
346: are discussed in the section below entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
1.1136 mike 347: syntax</a>".</p>
348:
349:
350: <h3 id="writing"><span class="secno">8.1 </span>Writing HTML documents</h3>
351:
352: <div class="impl">
1.1 mike 353:
354: <p><i>This section only applies to documents, authoring tools, and
355: markup generators. In particular, it does not apply to conformance
356: checkers; conformance checkers must use the requirements given in
357: the next section ("parsing HTML documents").</i></p>
358:
1.1136 mike 359: </div>
360:
361: <p>Documents must consist of the following parts, in the given
362: order:</p>
363:
364: <ol><li>Optionally, a single "BOM" (U+FEFF) character.</li>
1.1 mike 365:
366: <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
1.996 mike 367: <a href="common-microsyntaxes.html#space-character" title="space character">space characters</a>.</li>
1.1 mike 368:
369: <li>A <a href="#syntax-doctype" title="syntax-doctype">DOCTYPE</a>.
370:
371: </li><li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
1.996 mike 372: <a href="common-microsyntaxes.html#space-character" title="space character">space characters</a>.</li>
1.1 mike 373:
1.1052 mike 374: <li>The root element, in the form of an <code><a href="the-html-element.html#the-html-element">html</a></code> <a href="#syntax-elements" title="syntax-elements">element</a>.</li>
1.1 mike 375:
376: <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
1.996 mike 377: <a href="common-microsyntaxes.html#space-character" title="space character">space characters</a>.</li>
1.1 mike 378:
379: </ol><p>The various types of content mentioned above are described in the
1.1136 mike 380: next few sections.</p>
381:
382: <p>In addition, there are some restrictions on how <a href="the-meta-element.html#character-encoding-declaration" title="character encoding declaration">character encoding
1.1 mike 383: declarations</a> are to be serialized, as discussed in the
1.1136 mike 384: section on that topic.</p>
385:
386: <div class="note">
1.1 mike 387:
1.1052 mike 388: <p>Space characters before the root <code><a href="the-html-element.html#the-html-element">html</a></code> element, and
389: space characters at the start of the <code><a href="the-html-element.html#the-html-element">html</a></code> element and
390: before the <code><a href="the-head-element.html#the-head-element">head</a></code> element, will be dropped when the
1.1 mike 391: document is parsed; space characters <em>after</em> the root
1.1052 mike 392: <code><a href="the-html-element.html#the-html-element">html</a></code> element will be parsed as if they were at the end
393: of the <code><a href="the-body-element.html#the-body-element">body</a></code> element. Thus, space characters around the
1.1 mike 394: root element do not round-trip.</p>
395:
396: <p>It is suggested that newlines be inserted after the DOCTYPE,
397: after any comments that are before the root element, after the
1.1052 mike 398: <code><a href="the-html-element.html#the-html-element">html</a></code> element's start tag (if it is not <a href="#syntax-tag-omission" title="syntax-tag-omission">omitted</a>), and after any comments
399: that are inside the <code><a href="the-html-element.html#the-html-element">html</a></code> element but before the
400: <code><a href="the-head-element.html#the-head-element">head</a></code> element.</p>
1.1 mike 401:
1.1136 mike 402: </div>
403:
404: <p>Many strings in the HTML syntax (e.g. the names of elements and
1.1 mike 405: their attributes) are case-insensitive, but only for characters in
1.547 mike 406: the ranges U+0041 to U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL
407: LETTER Z) and U+0061 to U+007A (LATIN SMALL LETTER A to LATIN SMALL
1.1 mike 408: LETTER Z). For convenience, in this section this is just referred to
1.1136 mike 409: as "case-insensitive".</p>
410:
411:
412: <h4 id="the-doctype"><span class="secno">8.1.1 </span>The DOCTYPE</h4>
413:
1.1210 sruby 414: <p>A <dfn id="syntax-doctype" title="syntax-doctype">DOCTYPE</dfn> is a <!-- mostly
415: useless but nonetheless --> required preamble.</p>
1.1136 mike 416:
417: <p class="note">DOCTYPEs are required for legacy reasons. When
1.1 mike 418: omitted, browsers tend to use a different rendering mode that is
419: incompatible with some specifications. Including the DOCTYPE in a
420: document ensures that the browser makes a best-effort attempt at
1.1136 mike 421: following the relevant specifications.</p>
422:
423: <p>A DOCTYPE must consist of the following components, in this
424: order:</p>
425:
426: <ol class="brief"><li>A string that is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title=""><!DOCTYPE</code>".</li>
1.996 mike 427: <li>One or more <a href="common-microsyntaxes.html#space-character" title="space character">space characters</a>.</li>
1.1011 mike 428: <li>A string that is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">html</code>".</li>
1.861 mike 429: <li>Optionally, a <a href="#doctype-legacy-string">DOCTYPE legacy string</a> or an <a href="#obsolete-permitted-doctype-string">obsolete permitted DOCTYPE string</a> (defined below).</li>
1.996 mike 430: <li>Zero or more <a href="common-microsyntaxes.html#space-character" title="space character">space characters</a>.</li>
1.588 mike 431: <li>A U+003E GREATER-THAN SIGN character (>).</li>
1.1011 mike 432: </ol><p class="note">In other words, <code><!DOCTYPE html></code>,
1.1136 mike 433: case-insensitively.</p>
434:
435: <hr><p>For the purposes of HTML generators that cannot output HTML
1.1 mike 436: markup with the short DOCTYPE "<code title=""><!DOCTYPE
1.1011 mike 437: html></code>", a <dfn id="doctype-legacy-string">DOCTYPE legacy string</dfn> may be inserted
1.1 mike 438: into the DOCTYPE (in the position defined above). This string must
1.1136 mike 439: consist of:</p>
440:
441: <ol class="brief"><li>One or more <a href="common-microsyntaxes.html#space-character" title="space character">space characters</a>.</li>
1.1 mike 442: <li>A string that is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">SYSTEM</code>".</li>
1.996 mike 443: <li>One or more <a href="common-microsyntaxes.html#space-character" title="space character">space characters</a>.</li>
1.1 mike 444: <li>A U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the <i>quote mark</i>).</li>
1.1047 mike 445: <li>The literal string "<code><a href="urls.html#about:legacy-compat">about:legacy-compat</a></code>".</li>
1.856 mike 446: <li>A matching U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (i.e. the same character as in the earlier step labeled <i>quote mark</i>).</li>
1.1011 mike 447: </ol><p class="note">In other words, <code><!DOCTYPE html SYSTEM
448: "about:legacy-compat"></code> or <code><!DOCTYPE html SYSTEM
1.1004 mike 449: 'about:legacy-compat'></code>, case-insensitively except for the
1.1136 mike 450: part in single or double quotes.</p>
451:
452: <p>The <a href="#doctype-legacy-string">DOCTYPE legacy string</a> should not be used unless
1.1 mike 453: the document is generated from a system that cannot output the
1.1136 mike 454: shorter string.</p>
455:
1.1210 sruby 456: <hr><!-- see the parser section before changing this bit --><p>To help authors transition from HTML4 and XHTML1, an
1.861 mike 457: <dfn id="obsolete-permitted-doctype-string">obsolete permitted DOCTYPE string</dfn> can be inserted into
458: the DOCTYPE (in the position defined above). This string must
1.1136 mike 459: consist of:</p>
460:
461: <ol class="brief"><li>One or more <a href="common-microsyntaxes.html#space-character" title="space character">space characters</a>.</li>
1.861 mike 462: <li>A string that is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">PUBLIC</code>".</li>
1.996 mike 463: <li>One or more <a href="common-microsyntaxes.html#space-character" title="space character">space characters</a>.</li>
1.861 mike 464: <li>A U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the <i>first quote mark</i>).</li>
465: <li>The string from one of the cells in the first column of the table below. The row to which this cell belongs is the <i>selected row</i>.</li>
466: <li>A matching U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (i.e. the same character as in the earlier step labeled <i>first quote mark</i>).</li>
1.996 mike 467: <li>If the cell in the second column of the <i>selected row</i> is not blank, one or more <a href="common-microsyntaxes.html#space-character" title="space character">space characters</a>.</li>
1.861 mike 468: <li>If the cell in the second column of the <i>selected row</i> is not blank, a U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the <i>third quote mark</i>).</li>
469: <li>If the cell in the second column of the <i>selected row</i> is not blank, the string from the cell in the second column of the <i>selected row</i>.</li>
470: <li>If the cell in the second column of the <i>selected row</i> is not blank, a matching U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (i.e. the same character as in the earlier step labeled <i>third quote mark</i>).</li>
471: </ol><table><caption>
472: Allowed values for public and system identifiers in an <a href="#obsolete-permitted-doctype-string">obsolete permitted DOCTYPE string</a>.
473: </caption>
474: <thead><tr><th> Public identifier
475: </th><th> System identifier
476: </th></tr></thead><tbody><tr><td> <code title="">-//W3C//DTD HTML 4.0//EN</code>
477: </td><td>
478: </td></tr><tr><td> <code title="">-//W3C//DTD HTML 4.0//EN</code>
479: </td><td> <code title="">http://www.w3.org/TR/REC-html40/strict.dtd</code>
480: </td></tr><tr><td> <code title="">-//W3C//DTD HTML 4.01//EN</code>
481: </td><td>
482: </td></tr><tr><td> <code title="">-//W3C//DTD HTML 4.01//EN</code>
483: </td><td> <code title="">http://www.w3.org/TR/html4/strict.dtd</code>
484: </td></tr><tr><td> <code title="">-//W3C//DTD XHTML 1.0 Strict//EN</code>
485: </td><td> <code title="">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</code>
486: </td></tr><tr><td> <code title="">-//W3C//DTD XHTML 1.1//EN</code>
487: </td><td> <code title="">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</code>
488: </td></tr></tbody></table><p>A <a href="#syntax-doctype" title="syntax-doctype">DOCTYPE</a> containing an
489: <a href="#obsolete-permitted-doctype-string">obsolete permitted DOCTYPE string</a> is an <dfn id="obsolete-permitted-doctype">obsolete
490: permitted DOCTYPE</dfn>. Authors should not use <a href="#obsolete-permitted-doctype" title="obsolete permitted DOCTYPE">obsolete permitted
1.1136 mike 491: DOCTYPEs</a>, as they are unnecessarily long.</p>
492:
493:
494:
495:
496: <h4 id="elements-0"><span class="secno">8.1.2 </span>Elements</h4>
497:
498: <p>There are five different kinds of <dfn id="syntax-elements" title="syntax-elements">elements</dfn>: <a href="#void-elements">void elements</a>,
1.373 mike 499: <a href="#raw-text-elements">raw text elements</a>, <a href="#rcdata-elements">RCDATA elements</a>,
1.1136 mike 500: <a href="#foreign-elements">foreign elements</a>, and <a href="#normal-elements">normal elements</a>.</p>
501:
502: <dl><dt><dfn id="void-elements">Void elements</dfn></dt>
1.1 mike 503:
1.1052 mike 504: <dd><code><a href="the-area-element.html#the-area-element">area</a></code>, <code><a href="the-base-element.html#the-base-element">base</a></code>, <code><a href="the-br-element.html#the-br-element">br</a></code>,
505: <code><a href="the-col-element.html#the-col-element">col</a></code>, <code><a href="the-command-element.html#the-command-element">command</a></code>, <code><a href="the-embed-element.html#the-embed-element">embed</a></code>,
506: <code><a href="the-hr-element.html#the-hr-element">hr</a></code>, <code><a href="the-img-element.html#the-img-element">img</a></code>, <code><a href="the-input-element.html#the-input-element">input</a></code>,
507: <code><a href="the-keygen-element.html#the-keygen-element">keygen</a></code>, <code><a href="the-link-element.html#the-link-element">link</a></code>, <code><a href="the-meta-element.html#the-meta-element">meta</a></code>,
508: <code><a href="the-param-element.html#the-param-element">param</a></code>, <code><a href="the-source-element.html#the-source-element">source</a></code>, <code><a href="the-track-element.html#the-track-element">track</a></code>,
509: <code><a href="the-wbr-element.html#the-wbr-element">wbr</a></code></dd>
1.1210 sruby 510: <!-- see also other places that say VOIDLIST -->
1.1 mike 511:
1.373 mike 512: <dt><dfn id="raw-text-elements">Raw text elements</dfn></dt>
1.1 mike 513:
1.1210 sruby 514: <dd><code><a href="the-script-element.html#the-script-element">script</a></code>, <code><a href="the-style-element.html#the-style-element">style</a></code></dd> <!-- iframe and
515: noscript don't count as raw text for syntax purposes -->
1.1055 mike 516:
1.373 mike 517: <dt><dfn id="rcdata-elements">RCDATA elements</dfn></dt>
1.1 mike 518:
1.1052 mike 519: <dd><code><a href="the-textarea-element.html#the-textarea-element">textarea</a></code>, <code><a href="the-title-element.html#the-title-element">title</a></code></dd>
1.1 mike 520:
1.373 mike 521: <dt><dfn id="foreign-elements">Foreign elements</dfn></dt>
1.1 mike 522:
1.1047 mike 523: <dd>Elements from the <a href="namespaces.html#mathml-namespace">MathML namespace</a>
524: and the <a href="namespaces.html#svg-namespace">SVG namespace</a>.</dd>
1.1 mike 525:
1.373 mike 526: <dt><dfn id="normal-elements">Normal elements</dfn></dt>
1.1 mike 527:
528: <dd>All other allowed <a href="infrastructure.html#html-elements">HTML elements</a> are normal
529: elements.</dd>
530:
531: </dl><p><dfn id="syntax-tags" title="syntax-tags">Tags</dfn> are used to delimit the start
1.373 mike 532: and end of elements in the markup. <a href="#raw-text-elements" title="raw text
533: elements">Raw text</a>, <a href="#rcdata-elements" title="RCDATA
534: elements">RCDATA</a>, and <a href="#normal-elements" title="normal
535: elements">normal</a> elements have a <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> to indicate where they
536: begin, and an <a href="#syntax-end-tag" title="syntax-end-tag">end tag</a> to
537: indicate where they end. The start and end tags of certain
538: <a href="#normal-elements">normal elements</a> can be <a href="#syntax-tag-omission" title="syntax-tag-omission">omitted</a>, as described
1.1 mike 539: later. Those that cannot be omitted must not be omitted. <a href="#void-elements">Void
540: elements</a> only have a start tag; end tags must not be
1.373 mike 541: specified for <a href="#void-elements">void elements</a>. <a href="#foreign-elements">Foreign
542: elements</a> must either have a start tag and an end tag, or a
543: start tag that is marked as self-closing, in which case they must
1.1136 mike 544: not have an end tag.</p>
545:
546: <p>The contents of the element must be placed between just after the
1.1 mike 547: start tag (which <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied,
548: in certain cases</a>) and just before the end tag (which again,
549: <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied in certain
550: cases</a>). The exact allowed contents of each individual element
1.1004 mike 551: depend on the content model of that element, as described earlier in
552: this specification. Elements must not contain content that their
1.1 mike 553: content model disallows. In addition to the restrictions placed on
554: the contents by those content models, however, the five types of
1.1136 mike 555: elements have additional <em>syntactic</em> requirements.</p>
556:
557: <p><a href="#void-elements">Void elements</a> can't have any contents (since there's
1.1 mike 558: no end tag, no content can be put between the start tag and the end
1.1136 mike 559: tag).</p>
560:
561: <p><a href="#raw-text-elements">Raw text elements</a> can have <a href="#syntax-text" title="syntax-text">text</a>, though it has <a href="#cdata-rcdata-restrictions">restrictions</a> described
562: below.</p>
563:
564: <p><a href="#rcdata-elements">RCDATA elements</a> can have <a href="#syntax-text" title="syntax-text">text</a> and <a href="#syntax-charref" title="syntax-charref">character references</a>, but the text
1.373 mike 565: must not contain an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.
1.1 mike 566: There are also <a href="#cdata-rcdata-restrictions">further
1.1136 mike 567: restrictions</a> described below.</p>
568:
569: <p><a href="#foreign-elements">Foreign elements</a> whose start tag is marked as
1.373 mike 570: self-closing can't have any contents (since, again, as there's no
571: end tag, no content can be put between the start tag and the end
572: tag). <a href="#foreign-elements">Foreign elements</a> whose start tag is <em>not</em>
573: marked as self-closing can have <a href="#syntax-text" title="syntax-text">text</a>, <a href="#syntax-charref" title="syntax-charref">character references</a>, <a href="#syntax-cdata" title="syntax-cdata">CDATA sections</a>, other <a href="#syntax-elements" title="syntax-elements">elements</a>, and <a href="#syntax-comments" title="syntax-comments">comments</a>, but the text must not
1.1136 mike 574: contain the character U+003C LESS-THAN SIGN (<) or an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.</p>
575:
576: <div class="note">
1.374 mike 577:
578: <p>The HTML syntax does not support namespace
579: declarations, even in <a href="#foreign-elements">foreign elements</a>.</p>
580:
581: <p>For instance, consider the following HTML fragment:</p>
582:
583: <pre><p>
584: <svg>
585: <metadata>
586: <!-- this is invalid -->
587: <cdr:license xmlns:cdr="http://www.example.com/cdr/metadata" name="MIT"/>
588: </metadata>
589: </svg>
590: </p></pre>
591:
592: <p>The innermost element, <code title="">cdr:license</code>, is
593: actually in the SVG namespace, as the "<code title="">xmlns:cdr</code>" attribute has no effect (unlike in
594: XML). In fact, as the comment in the fragment above says, the
595: fragment is actually non-conforming. This is because the SVG
596: specification does not define any elements called "<code title="">cdr:license</code>" in the SVG namespace.</p>
597:
1.1136 mike 598: </div>
599:
600: <p><a href="#normal-elements">Normal elements</a> can have <a href="#syntax-text" title="syntax-text">text</a>, <a href="#syntax-charref" title="syntax-charref">character references</a>, other <a href="#syntax-elements" title="syntax-elements">elements</a>, and <a href="#syntax-comments" title="syntax-comments">comments</a>, but the text must not
1.588 mike 601: contain the character U+003C LESS-THAN SIGN (<) or an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>. Some
602: <a href="#normal-elements">normal elements</a> also have <a href="#element-restrictions">yet more restrictions</a> on what
1.1 mike 603: content they are allowed to hold, beyond the restrictions imposed by
604: the content model and those described in this paragraph. Those
1.1136 mike 605: restrictions are described below.</p>
606:
607: <p>Tags contain a <dfn id="syntax-tag-name" title="syntax-tag-name">tag name</dfn>,
1.1 mike 608: giving the element's name. HTML elements all have names that only
1.1212 sruby 609: use characters in the range <a href="common-microsyntaxes.html#ascii-digits">ASCII digits</a>, <a href="common-microsyntaxes.html#lowercase-ascii-letters">lowercase ASCII letters</a>, and <a href="common-microsyntaxes.html#uppercase-ascii-letters">uppercase ASCII letters</a>. In the HTML syntax, tag names, even those for <a href="#foreign-elements">foreign
1.462 mike 610: elements</a>, may be written with any mix of lower- and uppercase
611: letters that, when converted to all-lowercase, matches the element's
1.1136 mike 612: tag name; tag names are case-insensitive.</p>
613:
614:
615: <h5 id="start-tags"><span class="secno">8.1.2.1 </span>Start tags</h5>
616:
617: <p><dfn id="syntax-start-tag" title="syntax-start-tag">Start tags</dfn> must have the
618: following format:</p>
619:
620: <ol><li>The first character of a start tag must be a U+003C LESS-THAN
1.588 mike 621: SIGN character (<).</li>
1.1 mike 622:
623: <li>The next few characters of a start tag must be the element's
624: <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
625:
626: <li>If there are to be any attributes in the next step, there must
1.996 mike 627: first be one or more <a href="common-microsyntaxes.html#space-character" title="space character">space
1.1 mike 628: characters</a>.</li>
629:
630: <li>Then, the start tag may have a number of attributes, the <a href="#syntax-attributes" title="syntax-attributes">syntax for which</a> is described
1.1004 mike 631: below. Attributes must be separated from each other by one or more
1.996 mike 632: <a href="common-microsyntaxes.html#space-character" title="space character">space characters</a>.</li>
1.1 mike 633:
1.766 mike 634: <li>After the attributes, or after the <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a> if there are no attributes,
1.996 mike 635: there may be one or more <a href="common-microsyntaxes.html#space-character" title="space character">space
1.766 mike 636: characters</a>. (Some attributes are required to be followed by
637: a space. See the <a href="#syntax-attributes" title="syntax-attributes">attributes
638: section</a> below.)</li>
1.1 mike 639:
640: <li>Then, if the element is one of the <a href="#void-elements">void elements</a>,
1.373 mike 641: or if the element is a <a href="#foreign-elements" title="foreign elements">foreign
1.588 mike 642: element</a>, then there may be a single U+002F SOLIDUS character
643: (/). This character has no effect on <a href="#void-elements">void elements</a>,
644: but on <a href="#foreign-elements">foreign elements</a> it marks the start tag as
645: self-closing.</li>
1.1 mike 646:
647: <li>Finally, start tags must be closed by a U+003E GREATER-THAN
1.588 mike 648: SIGN character (>).</li>
1.1 mike 649:
1.1136 mike 650: </ol><h5 id="end-tags"><span class="secno">8.1.2.2 </span>End tags</h5>
651:
652: <p><dfn id="syntax-end-tag" title="syntax-end-tag">End tags</dfn> must have the
653: following format:</p>
654:
655: <ol><li>The first character of an end tag must be a U+003C LESS-THAN
1.588 mike 656: SIGN character (<).</li>
1.1 mike 657:
1.1136 mike 658: <li>The second character of an end tag must be a "/" (U+002F) character.</li>
1.1 mike 659:
660: <li>The next few characters of an end tag must be the element's
661: <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
662:
1.996 mike 663: <li>After the tag name, there may be one or more <a href="common-microsyntaxes.html#space-character" title="space
1.1 mike 664: character">space characters</a>.</li>
665:
1.588 mike 666: <li>Finally, end tags must be closed by a U+003E GREATER-THAN SIGN
667: character (>).</li>
1.1 mike 668:
1.1136 mike 669: </ol><h5 id="attributes-0"><span class="secno">8.1.2.3 </span>Attributes</h5>
670:
671: <p><dfn id="syntax-attributes" title="syntax-attributes">Attributes</dfn> for an element
672: are expressed inside the element's start tag.</p>
673:
674: <p>Attributes have a name and a value. <dfn id="syntax-attribute-name" title="syntax-attribute-name">Attribute names</dfn> must consist of
1.996 mike 675: one or more characters other than the <a href="common-microsyntaxes.html#space-character" title="space
1.1210 sruby 676: character">space characters</a>, U+0000 NULL, U+0022 QUOTATION
677: MARK ("), U+0027 APOSTROPHE ('), U+003E GREATER-THAN SIGN
1.1136 mike 678: (>), "/" (U+002F), and "=" (U+003D) characters,
1.1 mike 679: the control characters, and any characters that are not defined by
1.462 mike 680: Unicode. In the HTML syntax, attribute names, even those for
681: <a href="#foreign-elements">foreign elements</a>, may be written with any mix of lower-
682: and uppercase letters that are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.1136 mike 683: case-insensitive</a> match for the attribute's name.</p>
684:
685: <p><dfn id="syntax-attribute-value" title="syntax-attribute-value">Attribute values</dfn> are a
1.1 mike 686: mixture of <a href="#syntax-text" title="syntax-text">text</a> and <a href="#syntax-charref" title="syntax-charref">character references</a>, except with the
1.1136 mike 687: additional restriction that the text cannot contain an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.</p>
688:
689: <p>Attributes can be specified in four different ways:</p>
690:
691: <dl><dt>Empty attribute syntax</dt>
1.1 mike 692:
693: <dd>
694:
695: <p>Just the <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute
1.837 mike 696: name</a>. The value is implicitly the empty string.</p>
1.1 mike 697:
698: <div class="example">
699:
1.1052 mike 700: <p>In the following example, the <code title="attr-fe-disabled"><a href="attributes-common-to-form-controls.html#attr-fe-disabled">disabled</a></code> attribute is given with
1.1 mike 701: the empty attribute syntax:</p>
702:
703: <pre><input <em>disabled</em>></pre>
704:
705: </div>
706:
707: <p>If an attribute using the empty attribute syntax is to be
1.996 mike 708: followed by another attribute, then there must be a <a href="common-microsyntaxes.html#space-character">space
1.1 mike 709: character</a> separating the two.</p>
710:
711: </dd>
712:
1.2 mike 713: <dt id="unquoted">Unquoted attribute value syntax</dt>
1.1 mike 714:
715: <dd>
716:
717: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
1.996 mike 718: followed by zero or more <a href="common-microsyntaxes.html#space-character" title="space character">space
1.1 mike 719: characters</a>, followed by a single U+003D EQUALS SIGN
1.996 mike 720: character, followed by zero or more <a href="common-microsyntaxes.html#space-character" title="space
1.1 mike 721: character">space characters</a>, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
722: addition to the requirements given above for attribute values,
1.996 mike 723: must not contain any literal <a href="common-microsyntaxes.html#space-character" title="space character">space
1.1210 sruby 724: characters</a>, any U+0022 QUOTATION MARK characters ("),
725: U+0027 APOSTROPHE characters ('), "=" (U+003D) characters, U+003C LESS-THAN SIGN characters (<), U+003E
1.1136 mike 726: GREATER-THAN SIGN characters (>), or "`" (U+0060) characters, and must not be the empty string.</p>
1.463 mike 727:
1.1210 sruby 728: <!-- The ` character is in this list on a temporary basis, waiting
729: for IE to fix its parsing bug whereby it treats ` as an
730: attribute value delimiter. Otherwise, escaping software that
731: tries to be clever and not use quotes when it doesn't need to
732: could be tricked by an attacker.
733:
734: Posit a site that allows the user to input text that is used
735: verbatim in two attributes, such that the user can set the
736: first attribute's value to:
737:
738: `
739:
740: ...and the second to:
741:
742: ` onload='...payload...' end=x
743:
744: ...with the assumption that the site is going to not quote
745: the first one, and quote the second one with double quotes:
746:
747: <body title=` class="` onload='...payload...' end=x">
748:
749: In IE, this is treated as:
750:
751: <body title=' class="'
752: onload='...payload...'
753: end='x"'>
754:
755: -->
1.1 mike 756:
1.1055 mike 757:
1.1 mike 758: <div class="example">
759:
1.1047 mike 760: <p>In the following example, the <code title="attr-input-value"><a href="the-input-element.html#attr-input-value">value</a></code> attribute is given
1.1 mike 761: with the unquoted attribute value syntax:</p>
762:
763: <pre><input <em>value=yes</em>></pre>
764:
765: </div>
766:
767: <p>If an attribute using the unquoted attribute syntax is to be
1.1136 mike 768: followed by another attribute or by the optional "/" (U+002F) character allowed in step 6 of the <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> syntax above, then there
1.996 mike 769: must be a <a href="common-microsyntaxes.html#space-character">space character</a> separating the two.</p>
1.1 mike 770:
771: </dd>
772:
773: <dt>Single-quoted attribute value syntax</dt>
774:
775: <dd>
776:
777: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
1.996 mike 778: followed by zero or more <a href="common-microsyntaxes.html#space-character" title="space character">space
1.1 mike 779: characters</a>, followed by a single U+003D EQUALS SIGN
1.996 mike 780: character, followed by zero or more <a href="common-microsyntaxes.html#space-character" title="space
1.1136 mike 781: character">space characters</a>, followed by a single "'" (U+0027) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
1.1 mike 782: addition to the requirements given above for attribute values,
1.1136 mike 783: must not contain any literal "'" (U+0027) characters, and
1.588 mike 784: finally followed by a second single U+0027 APOSTROPHE character
785: (').</p>
1.1 mike 786:
787: <div class="example">
788:
1.1047 mike 789: <p>In the following example, the <code title="attr-input-type"><a href="the-input-element.html#attr-input-type">type</a></code> attribute is given with the
1.1 mike 790: single-quoted attribute value syntax:</p>
791:
792: <pre><input <em>type='checkbox'</em>></pre>
793:
794: </div>
795:
796: <p>If an attribute using the single-quoted attribute syntax is to
1.996 mike 797: be followed by another attribute, then there must be a <a href="common-microsyntaxes.html#space-character">space
1.1 mike 798: character</a> separating the two.</p>
799:
800: </dd>
801:
802: <dt>Double-quoted attribute value syntax</dt>
803:
804: <dd>
805:
806: <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
1.996 mike 807: followed by zero or more <a href="common-microsyntaxes.html#space-character" title="space character">space
1.1 mike 808: characters</a>, followed by a single U+003D EQUALS SIGN
1.996 mike 809: character, followed by zero or more <a href="common-microsyntaxes.html#space-character" title="space
1.1136 mike 810: character">space characters</a>, followed by a single """ (U+0022) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
1.1 mike 811: addition to the requirements given above for attribute values,
1.1136 mike 812: must not contain any literal """ (U+0022) characters,
813: and finally followed by a second single """ (U+0022) character.</p>
1.1 mike 814:
815: <div class="example">
816:
1.1052 mike 817: <p>In the following example, the <code title="attr-fe-name"><a href="attributes-common-to-form-controls.html#attr-fe-name">name</a></code> attribute is given with the
1.1 mike 818: double-quoted attribute value syntax:</p>
819:
820: <pre><input <em>name="be evil"</em>></pre>
821:
822: </div>
823:
824: <p>If an attribute using the double-quoted attribute syntax is to
1.996 mike 825: be followed by another attribute, then there must be a <a href="common-microsyntaxes.html#space-character">space
1.1 mike 826: character</a> separating the two.</p>
827:
828: </dd>
829:
830: </dl><p>There must never be two or more attributes on the same start tag
831: whose names are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for
1.1136 mike 832: each other.</p>
833:
834: <hr><p>When a <a href="#foreign-elements" title="foreign elements">foreign element</a> has
1.462 mike 835: one of the namespaced attributes given by the local name and
836: namespace of the first and second cells of a row from the following
837: table, it must be written using the name given by the third cell
1.1136 mike 838: from the same row.</p>
839:
840: <table><thead><tr><th> Local name </th><th> Namespace </th><th> Attribute name
1.1047 mike 841: </th></tr></thead><tbody><tr><td> <code title="">actuate</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:actuate</code>
842: </td></tr><tr><td> <code title="">arcrole</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:arcrole</code>
843: </td></tr><tr><td> <code title="">href</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:href</code>
844: </td></tr><tr><td> <code title="">role</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:role</code>
845: </td></tr><tr><td> <code title="">show</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:show</code>
846: </td></tr><tr><td> <code title="">title</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:title</code>
847: </td></tr><tr><td> <code title="">type</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a> </td><td> <code title="">xlink:type</code>
1.1210 sruby 848: </td></tr><tr><td> <code title="">base</code> </td><td> <a href="namespaces.html#xml-namespace">XML namespace</a> <!-- attr-xml-base --> </td><td> <code title="">xml:base</code>
1.1047 mike 849: </td></tr><tr><td> <code title="">lang</code> </td><td> <a href="namespaces.html#xml-namespace">XML namespace</a> </td><td> <code title="">xml:lang</code>
850: </td></tr><tr><td> <code title="">space</code> </td><td> <a href="namespaces.html#xml-namespace">XML namespace</a> </td><td> <code title="">xml:space</code>
851: </td></tr><tr><td> <code title="">xmlns</code> </td><td> <a href="namespaces.html#xmlns-namespace">XMLNS namespace</a> </td><td> <code title="">xmlns</code>
852: </td></tr><tr><td> <code title="">xlink</code> </td><td> <a href="namespaces.html#xmlns-namespace">XMLNS namespace</a> </td><td> <code title="">xmlns:xlink</code>
1.671 mike 853: </td></tr></tbody></table><p>No other namespaced attribute can be expressed in <a href="#syntax">the
1.1136 mike 854: HTML syntax</a>.</p>
855:
856:
857: <h5 id="optional-tags"><span class="secno">8.1.2.4 </span>Optional tags</h5>
858:
859: <p>Certain tags can be <dfn id="syntax-tag-omission" title="syntax-tag-omission">omitted</dfn>.</p>
860:
861: <p class="note">Omitting an element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> in the situations
1.1045 mike 862: described below does not mean the element is not present; it is
863: implied, but it is still there. For example, an HTML document always
1.1136 mike 864: has a root <code><a href="the-html-element.html#the-html-element">html</a></code> element, even if the string <code title=""><html></code> doesn't appear anywhere in the markup.</p>
865:
1.1210 sruby 866: <!-- <html> -->
1.1136 mike 867: <p>An <code><a href="the-html-element.html#the-html-element">html</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
868: first thing inside the <code><a href="the-html-element.html#the-html-element">html</a></code> element is not a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p>
869:
1.1210 sruby 870: <!-- </html> -->
1.1136 mike 871: <p>An <code><a href="the-html-element.html#the-html-element">html</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1052 mike 872: tag</a> may be omitted if the <code><a href="the-html-element.html#the-html-element">html</a></code> element is not
1.1136 mike 873: immediately followed by a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p>
874:
1.1210 sruby 875: <!-- <head> -->
1.1136 mike 876: <p>A <code><a href="the-head-element.html#the-head-element">head</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
1.821 mike 877: element is empty, or if the first thing inside the
1.1136 mike 878: <code><a href="the-head-element.html#the-head-element">head</a></code> element is an element.</p>
879:
1.1210 sruby 880: <!-- </head> -->
1.1136 mike 881: <p>A <code><a href="the-head-element.html#the-head-element">head</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1052 mike 882: tag</a> may be omitted if the <code><a href="the-head-element.html#the-head-element">head</a></code> element is not
1.1136 mike 883: immediately followed by a <a href="common-microsyntaxes.html#space-character">space character</a> or a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p>
884:
1.1210 sruby 885: <!-- <body> -->
1.1136 mike 886: <p>A <code><a href="the-body-element.html#the-body-element">body</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
1.1052 mike 887: element is empty, or if the first thing inside the <code><a href="the-body-element.html#the-body-element">body</a></code>
1.996 mike 888: element is not a <a href="common-microsyntaxes.html#space-character">space character</a> or a <a href="#syntax-comments" title="syntax-comments">comment</a>, except if the first thing
1.1052 mike 889: inside the <code><a href="the-body-element.html#the-body-element">body</a></code> element is a <code><a href="the-script-element.html#the-script-element">script</a></code> or
1.1210 sruby 890: <code><a href="the-style-element.html#the-style-element">style</a></code> element. <!-- Note that even if the </head> end
891: tag is present, the parser makes <style> and <script> elements
892: between </head> and <body> end up in the <head> instead of implying
893: the <body> --></p>
1.1136 mike 894:
1.1210 sruby 895: <!-- </body> -->
1.1136 mike 896: <p>A <code><a href="the-body-element.html#the-body-element">body</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1052 mike 897: tag</a> may be omitted if the <code><a href="the-body-element.html#the-body-element">body</a></code> element is not
1.1136 mike 898: immediately followed by a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p>
899:
1.1210 sruby 900: <!-- </li> -->
1.1136 mike 901: <p>An <code><a href="the-li-element.html#the-li-element">li</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1052 mike 902: tag</a> may be omitted if the <code><a href="the-li-element.html#the-li-element">li</a></code> element is
903: immediately followed by another <code><a href="the-li-element.html#the-li-element">li</a></code> element or if there
1.1136 mike 904: is no more content in the parent element.</p>
905:
1.1210 sruby 906: <!-- </dt> -->
1.1136 mike 907: <p>A <code><a href="the-dt-element.html#the-dt-element">dt</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1052 mike 908: tag</a> may be omitted if the <code><a href="the-dt-element.html#the-dt-element">dt</a></code> element is
909: immediately followed by another <code><a href="the-dt-element.html#the-dt-element">dt</a></code> element or a
1.1136 mike 910: <code><a href="the-dd-element.html#the-dd-element">dd</a></code> element.</p>
911:
1.1210 sruby 912: <!-- </dd> -->
1.1136 mike 913: <p>A <code><a href="the-dd-element.html#the-dd-element">dd</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1052 mike 914: tag</a> may be omitted if the <code><a href="the-dd-element.html#the-dd-element">dd</a></code> element is
915: immediately followed by another <code><a href="the-dd-element.html#the-dd-element">dd</a></code> element or a
916: <code><a href="the-dt-element.html#the-dt-element">dt</a></code> element, or if there is no more content in the
1.1136 mike 917: parent element.</p>
918:
1.1210 sruby 919: <!-- </p> -->
1.1136 mike 920: <p>A <code><a href="the-p-element.html#the-p-element">p</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1052 mike 921: tag</a> may be omitted if the <code><a href="the-p-element.html#the-p-element">p</a></code> element is
922: immediately followed by an <code><a href="the-address-element.html#the-address-element">address</a></code>,
923: <code><a href="the-article-element.html#the-article-element">article</a></code>, <code><a href="the-aside-element.html#the-aside-element">aside</a></code>, <code><a href="the-blockquote-element.html#the-blockquote-element">blockquote</a></code>,
924: <code><a href="obsolete.html#dir">dir</a></code>, <code><a href="the-div-element.html#the-div-element">div</a></code>, <code><a href="the-dl-element.html#the-dl-element">dl</a></code>,
925: <code><a href="the-fieldset-element.html#the-fieldset-element">fieldset</a></code>, <code><a href="the-footer-element.html#the-footer-element">footer</a></code>, <code><a href="the-form-element.html#the-form-element">form</a></code>,
1.1210 sruby 926: <code><a href="the-aside-element.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements">h1</a></code>, <code><a href="the-aside-element.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements">h2</a></code>, <code><a href="the-aside-element.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements">h3</a></code>, <code><a href="the-aside-element.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements">h4</a></code>,
927: <code><a href="the-aside-element.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements">h5</a></code>, <code><a href="the-aside-element.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements">h6</a></code>, <code><a href="the-header-element.html#the-header-element">header</a></code>,
1.1052 mike 928: <code><a href="the-hgroup-element.html#the-hgroup-element">hgroup</a></code>, <code><a href="the-hr-element.html#the-hr-element">hr</a></code>, <code><a href="the-menu-element.html#the-menu-element">menu</a></code>,
929: <code><a href="the-nav-element.html#the-nav-element">nav</a></code>, <code><a href="the-ol-element.html#the-ol-element">ol</a></code>, <code><a href="the-p-element.html#the-p-element">p</a></code>, <code><a href="the-pre-element.html#the-pre-element">pre</a></code>,
930: <code><a href="the-section-element.html#the-section-element">section</a></code>, <code><a href="the-table-element.html#the-table-element">table</a></code>, or <code><a href="the-ul-element.html#the-ul-element">ul</a></code>,
1.1 mike 931: element, or if there is no more content in the parent element and
1.1136 mike 932: the parent element is not an <code><a href="the-a-element.html#the-a-element">a</a></code> element.</p>
933:
1.1210 sruby 934: <!-- </rt> -->
1.1136 mike 935: <p>An <code><a href="the-rt-element.html#the-rt-element">rt</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1052 mike 936: tag</a> may be omitted if the <code><a href="the-rt-element.html#the-rt-element">rt</a></code> element is
937: immediately followed by an <code><a href="the-rt-element.html#the-rt-element">rt</a></code> or <code><a href="the-rp-element.html#the-rp-element">rp</a></code>
1.1136 mike 938: element, or if there is no more content in the parent element.</p>
939:
1.1210 sruby 940: <!-- </rp> -->
1.1136 mike 941: <p>An <code><a href="the-rp-element.html#the-rp-element">rp</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1052 mike 942: tag</a> may be omitted if the <code><a href="the-rp-element.html#the-rp-element">rp</a></code> element is
943: immediately followed by an <code><a href="the-rt-element.html#the-rt-element">rt</a></code> or <code><a href="the-rp-element.html#the-rp-element">rp</a></code>
1.1136 mike 944: element, or if there is no more content in the parent element.</p>
945:
1.1210 sruby 946: <!-- </optgroup> (the text assumes <optgroup> can only be inside a
947: <select>; commented out text below can handle the non-<select> case
948: if we ever allow it) -->
1.1136 mike 949: <p>An <code><a href="the-optgroup-element.html#the-optgroup-element">optgroup</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end tag</a> may be omitted if the
1.1210 sruby 950: <code><a href="the-optgroup-element.html#the-optgroup-element">optgroup</a></code> element <!--has an ancestor
951: <code>select</code> element and--> is immediately followed by
952: another <code><a href="the-optgroup-element.html#the-optgroup-element">optgroup</a></code> element, or if <!--all of the elements
953: that are ancestors of the <code>optgroup</code> element, up to and
954: including the first ancestor element that is not an
955: <code>optgroup</code> element, have no more content--> there is no
1.1136 mike 956: more content in the parent element.</p>
1.1210 sruby 957: <!-- so e.g. the max number of </optgroup>s are omitted here:
958: <select><optgroup></select>
959: <p id=x><optgroup></optgroup>x</p>
960: <p id=x><optgroup><optgroup></optgroup></optgroup>x</p>
961: <p><optgroup id=x><optgroup></optgroup>x</p>
962: <p><optgroup><optgroup id=x>x</p>
963: -->
1.1136 mike 964:
1.1210 sruby 965: <!-- </option> -->
1.1136 mike 966: <p>An <code><a href="the-option-element.html#the-option-element">option</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1052 mike 967: tag</a> may be omitted if the <code><a href="the-option-element.html#the-option-element">option</a></code> element is
968: immediately followed by another <code><a href="the-option-element.html#the-option-element">option</a></code> element, or if
969: it is immediately followed by an <code><a href="the-optgroup-element.html#the-optgroup-element">optgroup</a></code> element, or
1.1136 mike 970: if there is no more content in the parent element.</p>
971:
1.1210 sruby 972: <!-- <colgroup> -->
1.1136 mike 973: <p>A <code><a href="the-colgroup-element.html#the-colgroup-element">colgroup</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
1.1052 mike 974: first thing inside the <code><a href="the-colgroup-element.html#the-colgroup-element">colgroup</a></code> element is a
975: <code><a href="the-col-element.html#the-col-element">col</a></code> element, and if the element is not immediately
976: preceded by another <code><a href="the-colgroup-element.html#the-colgroup-element">colgroup</a></code> element whose <a href="#syntax-end-tag" title="syntax-end-tag">end tag</a> has been omitted. (It can't be
1.1136 mike 977: omitted if the element is empty.)</p>
978:
1.1210 sruby 979: <!-- </colgroup> -->
1.1136 mike 980: <p>A <code><a href="the-colgroup-element.html#the-colgroup-element">colgroup</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end tag</a> may be omitted if the
1.1052 mike 981: <code><a href="the-colgroup-element.html#the-colgroup-element">colgroup</a></code> element is not immediately followed by a
1.1136 mike 982: <a href="common-microsyntaxes.html#space-character">space character</a> or a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p>
983:
1.1210 sruby 984: <!-- </thead> -->
1.1136 mike 985: <p>A <code><a href="the-thead-element.html#the-thead-element">thead</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1052 mike 986: tag</a> may be omitted if the <code><a href="the-thead-element.html#the-thead-element">thead</a></code> element is
987: immediately followed by a <code><a href="the-tbody-element.html#the-tbody-element">tbody</a></code> or <code><a href="the-tfoot-element.html#the-tfoot-element">tfoot</a></code>
1.1136 mike 988: element.</p>
989:
1.1210 sruby 990: <!-- <tbody> -->
1.1136 mike 991: <p>A <code><a href="the-tbody-element.html#the-tbody-element">tbody</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
1.1052 mike 992: first thing inside the <code><a href="the-tbody-element.html#the-tbody-element">tbody</a></code> element is a
993: <code><a href="the-tr-element.html#the-tr-element">tr</a></code> element, and if the element is not immediately
994: preceded by a <code><a href="the-tbody-element.html#the-tbody-element">tbody</a></code>, <code><a href="the-thead-element.html#the-thead-element">thead</a></code>, or
995: <code><a href="the-tfoot-element.html#the-tfoot-element">tfoot</a></code> element whose <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1 mike 996: tag</a> has been omitted. (It can't be omitted if the element is
1.1136 mike 997: empty.)</p>
998:
1.1210 sruby 999: <!-- </tbody> -->
1.1136 mike 1000: <p>A <code><a href="the-tbody-element.html#the-tbody-element">tbody</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1052 mike 1001: tag</a> may be omitted if the <code><a href="the-tbody-element.html#the-tbody-element">tbody</a></code> element is
1002: immediately followed by a <code><a href="the-tbody-element.html#the-tbody-element">tbody</a></code> or <code><a href="the-tfoot-element.html#the-tfoot-element">tfoot</a></code>
1.1136 mike 1003: element, or if there is no more content in the parent element.</p>
1004:
1.1210 sruby 1005: <!-- </tfoot> -->
1.1136 mike 1006: <p>A <code><a href="the-tfoot-element.html#the-tfoot-element">tfoot</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1052 mike 1007: tag</a> may be omitted if the <code><a href="the-tfoot-element.html#the-tfoot-element">tfoot</a></code> element is
1008: immediately followed by a <code><a href="the-tbody-element.html#the-tbody-element">tbody</a></code> element, or if there is
1.1136 mike 1009: no more content in the parent element.</p>
1010:
1.1210 sruby 1011: <!-- </tr> -->
1.1136 mike 1012: <p>A <code><a href="the-tr-element.html#the-tr-element">tr</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1052 mike 1013: tag</a> may be omitted if the <code><a href="the-tr-element.html#the-tr-element">tr</a></code> element is
1014: immediately followed by another <code><a href="the-tr-element.html#the-tr-element">tr</a></code> element, or if there
1.1136 mike 1015: is no more content in the parent element.</p>
1016:
1.1210 sruby 1017: <!-- </td> -->
1.1136 mike 1018: <p>A <code><a href="the-td-element.html#the-td-element">td</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1052 mike 1019: tag</a> may be omitted if the <code><a href="the-td-element.html#the-td-element">td</a></code> element is
1020: immediately followed by a <code><a href="the-td-element.html#the-td-element">td</a></code> or <code><a href="the-th-element.html#the-th-element">th</a></code>
1.1136 mike 1021: element, or if there is no more content in the parent element.</p>
1022:
1.1210 sruby 1023: <!-- </th> -->
1.1136 mike 1024: <p>A <code><a href="the-th-element.html#the-th-element">th</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1052 mike 1025: tag</a> may be omitted if the <code><a href="the-th-element.html#the-th-element">th</a></code> element is
1026: immediately followed by a <code><a href="the-td-element.html#the-td-element">td</a></code> or <code><a href="the-th-element.html#the-th-element">th</a></code>
1.1136 mike 1027: element, or if there is no more content in the parent element.</p>
1028:
1029: <p><strong>However</strong>, a <a href="#syntax-start-tag" title="syntax-start-tag">start
1030: tag</a> must never be omitted if it has any attributes.</p>
1031:
1032:
1033: <h5 id="element-restrictions"><span class="secno">8.1.2.5 </span>Restrictions on content models</h5>
1034:
1035: <p>For historical reasons, certain elements have extra restrictions
1036: beyond even the restrictions given by their content model.</p>
1037:
1038: <p>A <code><a href="the-table-element.html#the-table-element">table</a></code> element must not contain <code><a href="the-tr-element.html#the-tr-element">tr</a></code>
1.1 mike 1039: elements, even though these elements are technically allowed inside
1.1052 mike 1040: <code><a href="the-table-element.html#the-table-element">table</a></code> elements according to the content models
1041: described in this specification. (If a <code><a href="the-tr-element.html#the-tr-element">tr</a></code> element is
1042: put inside a <code><a href="the-table-element.html#the-table-element">table</a></code> in the markup, it will in fact imply
1.1136 mike 1043: a <code><a href="the-tbody-element.html#the-tbody-element">tbody</a></code> start tag before it.)</p>
1044:
1045: <p>A single <a href="#syntax-newlines" title="syntax-newlines">newline</a> may be
1.304 mike 1046: placed immediately after the <a href="#syntax-start-tag" title="syntax-start-tag">start
1.1052 mike 1047: tag</a> of <code><a href="the-pre-element.html#the-pre-element">pre</a></code> and <code><a href="the-textarea-element.html#the-textarea-element">textarea</a></code>
1.1 mike 1048: elements. This does not affect the processing of the element. The
1.304 mike 1049: otherwise optional <a href="#syntax-newlines" title="syntax-newlines">newline</a>
1.381 mike 1050: <em>must</em> be included if the element's contents themselves start
1051: with a <a href="#syntax-newlines" title="syntax-newlines">newline</a> (because
1052: otherwise the leading newline in the contents would be treated like
1.1136 mike 1053: the optional newline, and ignored).</p>
1054:
1055: <div class="example">
1.1052 mike 1056: <p>The following two <code><a href="the-pre-element.html#the-pre-element">pre</a></code> blocks are equivalent:</p>
1.1 mike 1057: <pre><pre>Hello</pre></pre>
1058: <pre><pre><br>Hello</pre></pre>
1.1136 mike 1059: </div>
1060:
1061:
1062: <h5 id="cdata-rcdata-restrictions"><span class="secno">8.1.2.6 </span>Restrictions on the contents of raw text and RCDATA elements</h5>
1063:
1064: <p>The text in <a href="#raw-text-elements" title="raw text elements">raw text</a> and
1.889 mike 1065: <a href="#rcdata-elements">RCDATA elements</a> must not contain any occurrences of the
1066: string "<code title=""></</code>" (U+003C LESS-THAN SIGN, U+002F
1067: SOLIDUS) followed by characters that case-insensitively match the
1.1210 sruby 1068: tag name of the element followed by one of "tab" (U+0009), "LF" (U+000A), "FF" (U+000C), "CR" (U+000D), U+0020 SPACE, ">" (U+003E), or
1.1136 mike 1069: "/" (U+002F).</p>
1070:
1071:
1.1210 sruby 1072: <h4 id="text"><span class="secno">8.1.3 </span>Text</h4>
1.1136 mike 1073:
1074: <p><dfn id="syntax-text" title="syntax-text">Text</dfn> is allowed inside elements,
1.1108 mike 1075: attribute values, and comments. Extra constraints are placed on what
1076: is and what is not allowed in text based on where the text is to be
1.1136 mike 1077: put, as described in the other sections.</p>
1078:
1079:
1080: <h5 id="newlines"><span class="secno">8.1.3.1 </span>Newlines</h5>
1081:
1082: <p><dfn id="syntax-newlines" title="syntax-newlines">Newlines</dfn> in HTML may be
1083: represented either as "CR" (U+000D) characters, "LF" (U+000A) characters, or pairs of "CR" (U+000D),
1084: "LF" (U+000A) characters in that order.</p>
1085:
1086: <p>Where <a href="#syntax-charref" title="syntax-charref">character references</a>
1087: are allowed, a character reference of a "LF" (U+000A)
1088: character (but not a "CR" (U+000D) character) also
1089: represents a <a href="#syntax-newlines" title="syntax-newlines">newline</a>.</p>
1090:
1091:
1092: <h4 id="character-references"><span class="secno">8.1.4 </span>Character references</h4>
1093:
1094: <p>In certain cases described in other sections, <a href="#syntax-text" title="syntax-text">text</a> may be mixed with <dfn id="syntax-charref" title="syntax-charref">character references</dfn>. These can be used
1.1 mike 1095: to escape characters that couldn't otherwise legally be included in
1.1136 mike 1096: <a href="#syntax-text" title="syntax-text">text</a>.</p>
1097:
1098: <p>Character references must start with a U+0026 AMPERSAND character
1.588 mike 1099: (&). Following this, there are three possible kinds of character
1.1136 mike 1100: references:</p>
1101:
1102: <dl><dt>Named character references</dt>
1.1 mike 1103:
1104: <dd>The ampersand must be followed by one of the names given in the
1105: <a href="named-character-references.html#named-character-references">named character references</a> section, using the same
1.677 mike 1106: case. <span class="impl">The name must be one that is terminated by
1.1136 mike 1107: a ";" (U+003B) character.</span></dd>
1.1 mike 1108:
1109:
1110: <dt>Decimal numeric character reference</dt>
1111:
1.1212 sruby 1112: <dd>The ampersand must be followed by a "#" (U+0023) character, followed by one or more digits in the range <a href="common-microsyntaxes.html#ascii-digits">ASCII digits</a>, representing a base-ten
1.588 mike 1113: integer that corresponds to a Unicode code point that is allowed
1114: according to the definition below. The digits must then be followed
1.1136 mike 1115: by a ";" (U+003B) character.</dd>
1.1 mike 1116:
1117:
1118: <dt>Hexadecimal numeric character reference</dt>
1119:
1.1136 mike 1120: <dd>The ampersand must be followed by a "#" (U+0023) character, which must be followed by either a "x" (U+0078) character or a "X" (U+0058) character, which must then be followed by one or more digits in
1.1212 sruby 1121: the range <a href="common-microsyntaxes.html#ascii-digits">ASCII digits</a>, U+0061
1.588 mike 1122: LATIN SMALL LETTER A to U+0066 LATIN SMALL LETTER F, and U+0041
1123: LATIN CAPITAL LETTER A to U+0046 LATIN CAPITAL LETTER F,
1.464 mike 1124: representing a base-sixteen integer that corresponds to a Unicode
1125: code point that is allowed according to the definition below. The
1126: digits must then be followed by a U+003B SEMICOLON character
1127: (;).</dd>
1.378 mike 1128:
1129: </dl><p>The numeric character reference forms described above are allowed
1.882 mike 1130: to reference any Unicode code point other than U+0000, U+000D,
1131: permanently undefined Unicode characters (noncharacters), and
1.996 mike 1132: control characters other than <a href="common-microsyntaxes.html#space-character" title="space character">space
1.1136 mike 1133: characters</a>.</p>
1134:
1135: <p>An <dfn id="syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.464 mike 1136: ampersand</dfn> is a U+0026 AMPERSAND character (&) that is
1.1212 sruby 1137: followed by one or more characters in the range <a href="common-microsyntaxes.html#ascii-digits">ASCII digits</a>, <a href="common-microsyntaxes.html#lowercase-ascii-letters">lowercase ASCII letters</a>, and <a href="common-microsyntaxes.html#uppercase-ascii-letters">uppercase ASCII letters</a>, followed by a U+003B SEMICOLON character
1.897 mike 1138: (;), where these characters do not match any of the names given in
1.1136 mike 1139: the <a href="named-character-references.html#named-character-references">named character references</a> section.</p>
1140:
1141:
1142: <h4 id="cdata-sections"><span class="secno">8.1.5 </span>CDATA sections</h4>
1143:
1144: <p><dfn id="syntax-cdata" title="syntax-cdata">CDATA sections</dfn> must consist of
1145: the following components, in this order:</p>
1146:
1147: <ol><li>The string "<code title=""><![CDATA[</code>".</li>
1.1029 mike 1148:
1149: <li>Optionally, <a href="#syntax-text" title="syntax-text">text</a>, with the
1150: additional restriction that the text must not contain the string
1151: "<code title="">]]></code>".</li>
1152:
1153: <li>The string "<code title="">]]></code>".</li>
1154:
1155: </ol><div class="example">
1.724 mike 1156:
1157: <p>CDATA sections can only be used in foreign content (MathML or
1158: SVG). In this example, a CDATA section is used to escape the
1159: contents of an <code>ms</code> element:</p>
1160:
1161: <pre><p>You can add a string to a number, but this stringifies the number:</p>
1162: <math>
1163: <ms><![CDATA[x<y]]></ms>
1164: <mo>+</mo>
1165: <mn>3</mn>
1166: <mo>=</mo>
1167: <ms><![CDATA[x<y3]]></ms>
1168: </math></pre>
1169:
1.1136 mike 1170: </div>
1171:
1172:
1173: <h4 id="comments"><span class="secno">8.1.6 </span>Comments</h4>
1174:
1175: <p><dfn id="syntax-comments" title="syntax-comments">Comments</dfn> must start with the
1.1 mike 1176: four character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
1177: MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS (<code title=""><!--</code>). Following this sequence, the comment may
1178: have <a href="#syntax-text" title="syntax-text">text</a>, with the additional
1179: restriction that the text must not start with a single U+003E
1.1136 mike 1180: GREATER-THAN SIGN character (>), nor start with a "-" (U+002D) character followed by a U+003E GREATER-THAN SIGN
1.588 mike 1181: (>) character, nor contain two consecutive U+002D HYPHEN-MINUS
1.1136 mike 1182: characters (<code title="">--</code>), nor end with a "-" (U+002D) character. Finally, the comment must be ended by
1.1 mike 1183: the three character sequence U+002D HYPHEN-MINUS, U+002D
1.1136 mike 1184: HYPHEN-MINUS, U+003E GREATER-THAN SIGN (<code title="">--></code>).</p>
1185:
1186:
1187: </body></html>
Webmaster