Another abandoned server code base... this is kind of an ancestor of taskrambler.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

4032 lines
213 KiB

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en-US-x-Hixie" ><head><title>8.2.5 Tree construction &#8212; HTML5 </title><style type="text/css">
pre { margin-left: 2em; white-space: pre-wrap; }
h2 { margin: 3em 0 1em 0; }
h3 { margin: 2.5em 0 1em 0; }
h4 { margin: 2.5em 0 0.75em 0; }
h5, h6 { margin: 2.5em 0 1em; }
h1 + h2, h1 + h2 + h2 { margin: 0.75em 0 0.75em; }
h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 0.5em; }
p { margin: 1em 0; }
hr:not(.top) { display: block; background: none; border: none; padding: 0; margin: 2em 0; height: auto; }
dl, dd { margin-top: 0; margin-bottom: 0; }
dt { margin-top: 0.75em; margin-bottom: 0.25em; clear: left; }
dt + dt { margin-top: 0; }
dd dt { margin-top: 0.25em; margin-bottom: 0; }
dd p { margin-top: 0; }
dd dl + p { margin-top: 1em; }
dd table + p { margin-top: 1em; }
p + * > li, dd li { margin: 1em 0; }
dt, dfn { font-weight: bold; font-style: normal; }
dt dfn { font-style: italic; }
pre, code { font-size: inherit; font-family: monospace; font-variant: normal; }
pre strong { color: black; font: inherit; font-weight: bold; background: yellow; }
pre em { font-weight: bolder; font-style: normal; }
@media screen { code { color: orangered; } code :link, code :visited { color: inherit; } }
var sub { vertical-align: bottom; font-size: smaller; position: relative; top: 0.1em; }
table { border-collapse: collapse; border-style: hidden hidden none hidden; }
table thead, table tbody { border-bottom: solid; }
table tbody th:first-child { border-left: solid; }
table tbody th { text-align: left; }
table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }
.bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
.matrix, .matrix td { border: none; text-align: right; }
.matrix { margin-left: 2em; }
.dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
.dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
.dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
.toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
img.extra { float: right; }
pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; }
pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
pre.css:first-line { color: #AAAA50; }
dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #DDFFDD; }
hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
dl.domintro dd p { margin: 0.5em 0; }
dl.switch { padding-left: 2em; }
dl.switch > dt { text-indent: -1.5em; }
dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
dl.triple { padding: 0 0 0 1em; }
dl.triple dt, dl.triple dd { margin: 0; display: inline }
dl.triple dt:after { content: ':'; }
dl.triple dd:after { content: '\A'; white-space: pre; }
.diff-old { text-decoration: line-through; color: silver; background: transparent; }
.diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
a .diff-new { border-bottom: 1px blue solid; }
h2 { page-break-before: always; }
h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
h1 + h2, hr + h2.no-toc { page-break-before: auto; }
p > span:not([title=""]):not([class="XXX"]):not([class="impl"]):not([class="note"]),
li > span:not([title=""]):not([class="XXX"]):not([class="impl"]):not([class="note"]), { border-bottom: solid #9999CC; }
div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
div.head p { margin: 0; }
div.head h1 { margin: 0; }
div.head .logo { float: right; margin: 0 1em; }
div.head .logo img { border: none } /* remove border from top image */
div.head dl { margin: 1em 0; }
div.head p.copyright, div.head p.alt { font-size: x-small; font-style: oblique; margin: 0; }
body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
body > .toc > li > * { margin-bottom: 0.5em; }
body > .toc > li > * > li > * { margin-bottom: 0.25em; }
.toc, .toc li { list-style: none; }
.brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
.brief li { margin: 0; padding: 0; }
.brief li p { margin: 0; padding: 0; }
.category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
.category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
.category-list li { display: inline; }
.category-list li:not(:last-child)::after { content: ', '; }
.category-list li > span, .category-list li > a { text-transform: lowercase; }
.category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
.XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
.XXX > :first-child { margin-top: 0; }
p .XXX { line-height: 3em; }
.annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
.annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
.annotation :link, .annotation :visited { color: inherit; }
.annotation :link:hover, .annotation :visited:hover { background: transparent; }
.annotation span { border: none ! important; }
.note { color: green; background: transparent; font-family: sans-serif; }
.warning { color: red; background: transparent; }
.note, .warning { font-weight: bolder; font-style: italic; }
p.note, div.note { padding: 0.5em 2em; }
span.note { padding: 0 2em; }
.note p:first-child, .warning p:first-child { margin-top: 0; }
.note p:last-child, .warning p:last-child { margin-bottom: 0; }
.warning:before { font-style: normal; }
p.note:before { content: 'Note: '; }
p.warning:before { content: '\26A0 Warning! '; }
.bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
.bookkeeping { font-size: 0.8em; margin: 2em 0; }
.bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
.bookkeeping dt { margin: 0.5em 2em 0; }
.bookkeeping dd { margin: 0 3em 0.5em; }
h4 { position: relative; z-index: 3; }
h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
.element {
background: #EEEEFF;
color: black;
margin: 0 0 1em 0.15em;
padding: 0 1em 0.25em 0.75em;
border-left: solid #9999FF 0.25em;
position: relative;
z-index: 1;
}
.element:before {
position: absolute;
z-index: 2;
top: 0;
left: -1.15em;
height: 2em;
width: 0.9em;
background: #EEEEFF;
content: ' ';
border-style: none none solid solid;
border-color: #9999FF;
border-width: 0.25em;
}
.example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
td > .example:only-child { margin: 0 0 0 0.1em; }
ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
ul.domTree li li { list-style: none; }
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; }
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; }
ul.domTree span { font-style: italic; font-family: serif; }
ul.domTree .t1 code { color: purple; font-weight: bold; }
ul.domTree .t2 { font-style: normal; font-family: monospace; }
ul.domTree .t2 .name { color: black; font-weight: bold; }
ul.domTree .t2 .value { color: blue; font-weight: normal; }
ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
ul.domTree .t7 code, .domTree .t8 code { color: green; }
ul.domTree .t10 code { color: teal; }
body.dfnEnabled dfn { cursor: pointer; }
.dfnPanel {
display: inline;
position: absolute;
z-index: 10;
height: auto;
width: auto;
padding: 0.5em 0.75em;
font: small sans-serif, Droid Sans Fallback;
background: #DDDDDD;
color: black;
border: outset 0.2em;
}
.dfnPanel * { margin: 0; padding: 0; font: inherit; text-indent: 0; }
.dfnPanel :link, .dfnPanel :visited { color: black; }
.dfnPanel p { font-weight: bolder; }
.dfnPanel * + p { margin-top: 0.25em; }
.dfnPanel li { list-style-position: inside; }
#configUI { position: absolute; z-index: 20; top: 10em; right: 1em; width: 11em; font-size: small; }
#configUI p { margin: 0.5em 0; padding: 0.3em; background: #EEEEEE; color: black; border: inset thin; }
#configUI p label { display: block; }
#configUI #updateUI, #configUI .loginUI { text-align: center; }
#configUI input[type=button] { display: block; margin: auto; }
fieldset { margin: 1em; padding: 0.5em 1em; }
fieldset > legend + * { margin-top: 0; }
fieldset > :last-child { margin-bottom: 0; }
fieldset p { margin: 0.5em 0; }
.stability {
position: fixed;
bottom: 0;
left: 0; right: 0;
margin: 0 auto 0 auto !important;
z-index: 1000;
width: 50%;
background: maroon; color: yellow;
-webkit-border-radius: 1em 1em 0 0;
-moz-border-radius: 1em 1em 0 0;
border-radius: 1em 1em 0 0;
-moz-box-shadow: 0 0 1em #500;
-webkit-box-shadow: 0 0 1em #500;
box-shadow: 0 0 1em red;
padding: 0.5em 1em;
text-align: center;
}
.stability strong {
display: block;
}
.stability input {
appearance: none; margin: 0; border: 0; padding: 0.25em 0.5em; background: transparent; color: black;
position: absolute; top: -0.5em; right: 0; font: 1.25em sans-serif; text-align: center;
}
.stability input:hover {
color: white;
text-shadow: 0 0 2px black;
}
.stability input:active {
padding: 0.3em 0.45em 0.2em 0.55em;
}
.stability :link, .stability :visited,
.stability :link:hover, .stability :visited:hover {
background: transparent;
color: white;
}
</style><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"><link href="http://www.w3.org/StyleSheets/TR/W3C-WD" rel="stylesheet" type="text/css"><style type="text/css">
.applies thead th > * { display: block; }
.applies thead code { display: block; }
.applies tbody th { whitespace: nowrap; }
.applies td { text-align: center; }
.applies .yes { background: yellow; }
.matrix, .matrix td { border: hidden; text-align: right; }
.matrix { margin-left: 2em; }
.dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
.dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
.dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
td.eg { border-width: thin; text-align: center; }
#table-example-1 { border: solid thin; border-collapse: collapse; margin-left: 3em; }
#table-example-1 * { font-family: "Essays1743", serif; line-height: 1.01em; }
#table-example-1 caption { padding-bottom: 0.5em; }
#table-example-1 thead, #table-example-1 tbody { border: none; }
#table-example-1 th, #table-example-1 td { border: solid thin; }
#table-example-1 th { font-weight: normal; }
#table-example-1 td { border-style: none solid; vertical-align: top; }
#table-example-1 th { padding: 0.5em; vertical-align: middle; text-align: center; }
#table-example-1 tbody tr:first-child td { padding-top: 0.5em; }
#table-example-1 tbody tr:last-child td { padding-bottom: 1.5em; }
#table-example-1 tbody td:first-child { padding-left: 2.5em; padding-right: 0; width: 9em; }
#table-example-1 tbody td:first-child::after { content: leader(". "); }
#table-example-1 tbody td { padding-left: 2em; padding-right: 2em; }
#table-example-1 tbody td:first-child + td { width: 10em; }
#table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
#table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
.apple-table-examples { border: none; border-collapse: separate; border-spacing: 1.5em 0em; width: 40em; margin-left: 3em; }
.apple-table-examples * { font-family: "Times", serif; }
.apple-table-examples td, .apple-table-examples th { border: none; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
.apple-table-examples tbody th:first-child { border-left: none; width: 100%; }
.apple-table-examples thead th:first-child ~ th { font-size: smaller; font-weight: bolder; border-bottom: solid 2px; text-align: center; }
.apple-table-examples tbody th::after, .apple-table-examples tfoot th::after { content: leader(". ") }
.apple-table-examples tbody th, .apple-table-examples tfoot th { font: inherit; text-align: left; }
.apple-table-examples td { text-align: right; vertical-align: top; }
.apple-table-examples.e1 tbody tr:last-child td { border-bottom: solid 1px; }
.apple-table-examples.e1 tbody + tbody tr:last-child td { border-bottom: double 3px; }
.apple-table-examples.e2 th[scope=row] { padding-left: 1em; }
.apple-table-examples sup { line-height: 0; }
.details-example img { vertical-align: top; }
#base64-table {
white-space: nowrap;
font-size: 0.6em;
column-width: 6em;
column-count: 5;
column-gap: 1em;
-moz-column-width: 6em;
-moz-column-count: 5;
-moz-column-gap: 1em;
-webkit-column-width: 6em;
-webkit-column-count: 5;
-webkit-column-gap: 1em;
}
#base64-table thead { display: none; }
#base64-table * { border: none; }
#base64-table tbody td:first-child:after { content: ':'; }
#base64-table tbody td:last-child { text-align: right; }
#named-character-references-table {
white-space: nowrap;
font-size: 0.6em;
column-width: 30em;
column-gap: 1em;
-moz-column-width: 30em;
-moz-column-gap: 1em;
-webkit-column-width: 30em;
-webkit-column-gap: 1em;
}
#named-character-references-table > table > tbody > tr > td:first-child + td,
#named-character-references-table > table > tbody > tr > td:last-child { text-align: center; }
#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; }
#named-character-references-table > table > tbody > tr#entity-CounterClockwiseContourIntegral > td:first-child { font-size: 0.5em; }
.glyph.control { color: red; }
@font-face {
font-family: 'Essays1743';
src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743.ttf');
}
@font-face {
font-family: 'Essays1743';
font-weight: bold;
src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-Bold.ttf');
}
@font-face {
font-family: 'Essays1743';
font-style: italic;
src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-Italic.ttf');
}
@font-face {
font-family: 'Essays1743';
font-style: italic;
font-weight: bold;
src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-BoldItalic.ttf');
}
</style><style type="text/css">
.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; }
</style><script type="text/javascript">
function getCookie(name) {
var params = location.search.substr(1).split("&");
for (var index = 0; index < params.length; index++) {
if (params[index] == name)
return "1";
var data = params[index].split("=");
if (data[0] == name)
return unescape(data[1]);
}
var cookies = document.cookie.split("; ");
for (var index = 0; index < cookies.length; index++) {
var data = cookies[index].split("=");
if (data[0] == name)
return unescape(data[1]);
}
return null;
}
</script>
<script src="link-fixup.js" type="text/javascript"></script>
<link href="style.css" rel="stylesheet"><link href="tokenization.html" title="8.2.4 Tokenization" rel="prev">
<link href="spec.html#contents" title="Table of contents" rel="index">
<link href="the-end.html" title="8.2.6 The end" rel="next">
</head><body><div class="head" id="head">
<div id="multipage-common">
<p class="stability" id="wip"><strong>This is a work in
progress!</strong> For the latest updates from the HTML WG, possibly
including important bug fixes, please look at the <a href="http://dev.w3.org/html5/spec/Overview.html">editor's draft</a> instead.
There may also be a more
<a href="http://www.w3.org/TR/html5">up-to-date Working Draft</a>
with changes based on resolution of Last Call issues.
<input onclick="closeWarning(this.parentNode)" type="button" value="&#9587;&#8413;"></p>
<script type="text/javascript">
function closeWarning(element) {
element.parentNode.removeChild(element);
var date = new Date();
date.setDate(date.getDate()+4);
document.cookie = 'hide-obsolescence-warning=1; expires=' + date.toGMTString();
}
if (getCookie('hide-obsolescence-warning') == '1')
setTimeout(function () { document.getElementById('wip').parentNode.removeChild(document.getElementById('wip')); }, 2000);
</script></div>
<p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="http://www.w3.org/Icons/w3c_home" width="72"></a></p>
<h1>HTML5</h1>
</div><div>
<a href="tokenization.html" class="prev">8.2.4 Tokenization</a> &#8211;
<a href="spec.html#contents">Table of contents</a> &#8211;
<a href="the-end.html" class="next">8.2.6 The end</a>
<ol class="toc"><li><ol><li><ol><li><a href="tree-construction.html#tree-construction"><span class="secno">8.2.5 </span>Tree construction</a>
<ol><li><a href="tree-construction.html#creating-and-inserting-elements"><span class="secno">8.2.5.1 </span>Creating and inserting elements</a></li><li><a href="tree-construction.html#closing-elements-that-have-implied-end-tags"><span class="secno">8.2.5.2 </span>Closing elements that have implied end tags</a></li><li><a href="tree-construction.html#foster-parenting"><span class="secno">8.2.5.3 </span>Foster parenting</a></li><li><a href="tree-construction.html#parsing-main-inhtml"><span class="secno">8.2.5.4 </span>The rules for parsing tokens in HTML content</a>
<ol><li><a href="tree-construction.html#the-initial-insertion-mode"><span class="secno">8.2.5.4.1 </span>The "initial" insertion mode</a></li><li><a href="tree-construction.html#the-before-html-insertion-mode"><span class="secno">8.2.5.4.2 </span>The "before html" insertion mode</a></li><li><a href="tree-construction.html#the-before-head-insertion-mode"><span class="secno">8.2.5.4.3 </span>The "before head" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-inhead"><span class="secno">8.2.5.4.4 </span>The "in head" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-inheadnoscript"><span class="secno">8.2.5.4.5 </span>The "in head noscript" insertion mode</a></li><li><a href="tree-construction.html#the-after-head-insertion-mode"><span class="secno">8.2.5.4.6 </span>The "after head" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-inbody"><span class="secno">8.2.5.4.7 </span>The "in body" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-incdata"><span class="secno">8.2.5.4.8 </span>The "text" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-intable"><span class="secno">8.2.5.4.9 </span>The "in table" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-intabletext"><span class="secno">8.2.5.4.10 </span>The "in table text" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-incaption"><span class="secno">8.2.5.4.11 </span>The "in caption" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-incolgroup"><span class="secno">8.2.5.4.12 </span>The "in column group" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-intbody"><span class="secno">8.2.5.4.13 </span>The "in table body" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-intr"><span class="secno">8.2.5.4.14 </span>The "in row" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-intd"><span class="secno">8.2.5.4.15 </span>The "in cell" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-inselect"><span class="secno">8.2.5.4.16 </span>The "in select" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-inselectintable"><span class="secno">8.2.5.4.17 </span>The "in select in table" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-afterbody"><span class="secno">8.2.5.4.18 </span>The "after body" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-inframeset"><span class="secno">8.2.5.4.19 </span>The "in frameset" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-afterframeset"><span class="secno">8.2.5.4.20 </span>The "after frameset" insertion mode</a></li><li><a href="tree-construction.html#the-after-after-body-insertion-mode"><span class="secno">8.2.5.4.21 </span>The "after after body" insertion mode</a></li><li><a href="tree-construction.html#the-after-after-frameset-insertion-mode"><span class="secno">8.2.5.4.22 </span>The "after after frameset" insertion mode</a></li></ol></li><li><a href="tree-construction.html#parsing-main-inforeign"><span class="secno">8.2.5.5 </span>The rules for parsing tokens in foreign content</a></li></ol></li></ol></li></ol></li></ol></div>
<div class="impl">
<h4 id="tree-construction"><span class="secno">8.2.5 </span><dfn>Tree construction</dfn></h4>
<p>The input to the tree construction stage is a sequence of tokens
from the <a href="tokenization.html#tokenization">tokenization</a> stage. The tree construction
stage is associated with a DOM <code><a href="infrastructure.html#document">Document</a></code> object when a
parser is created. The "output" of this stage consists of
dynamically modifying or extending that document's DOM tree.</p>
<p>This specification does not define when an interactive user agent
has to render the <code><a href="infrastructure.html#document">Document</a></code> so that it is available to
the user, or when it has to begin accepting user input.</p>
<hr><p>As each token is emitted from the tokenizer, the user agent must
follow the appropriate steps from the following list:</p>
<dl class="switch"><dt>If there is no <a href="parsing.html#current-node">current node</a></dt>
<dt>If the <a href="parsing.html#current-node">current node</a> is an element in the <a href="namespaces.html#html-namespace-0">HTML namespace</a></dt>
<dt>If the <a href="parsing.html#current-node">current node</a> is a <a href="#mathml-text-integration-point">MathML text integration point</a> and the token is a start tag whose tag name is neither "mglyph" nor "malignmark"</dt>
<dt>If the <a href="parsing.html#current-node">current node</a> is an <code title="">annotation-xml</code> element in the <a href="namespaces.html#mathml-namespace">MathML namespace</a> and the token is a start tag whose tag name is "svg"</dt>
<dt>If the <a href="parsing.html#current-node">current node</a> is an <a href="#html-integration-point">HTML integration point</a> and the token is a start tag</dt>
<dt>If the <a href="parsing.html#current-node">current node</a> is an <a href="#html-integration-point">HTML integration point</a> and the token is a character token</dt>
<dt>If the token is an end-of-file token</dt>
<dd>Process the token according to the rules given in the section
corresponding to the current <a href="parsing.html#insertion-mode">insertion mode</a> in HTML
content.</dd>
<dt>Otherwise</dt>
<dd>Process the token according to the rules given in the section
for parsing tokens <a href="#parsing-main-inforeign" title="insertion mode: in foreign
content">in foreign content</a>.</dd>
</dl><p>The <a href="parsing.html#current-node">current node</a> is a <dfn id="mathml-text-integration-point">MathML text
integration point</dfn> if it is one of the following elements:</p>
<ul class="brief"><li>An <code title="">mi</code> element in the <a href="namespaces.html#mathml-namespace">MathML namespace</a></li>
<li>An <code title="">mo</code> element in the <a href="namespaces.html#mathml-namespace">MathML namespace</a></li>
<li>An <code title="">mn</code> element in the <a href="namespaces.html#mathml-namespace">MathML namespace</a></li>
<li>An <code title="">ms</code> element in the <a href="namespaces.html#mathml-namespace">MathML namespace</a></li>
<li>An <code title="">mtext</code> element in the <a href="namespaces.html#mathml-namespace">MathML namespace</a></li>
</ul><p>The <a href="parsing.html#current-node">current node</a> is an <dfn id="html-integration-point">HTML
integration point</dfn> if it is one of the following elements:</p>
<ul class="brief"><li>An <code title="">annotation-xml</code> element in the <a href="namespaces.html#mathml-namespace">MathML namespace</a> whose start tag token had an attribute with the name "encoding" whose value was an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">text/html</code>"</li>
<li>An <code title="">annotation-xml</code> element in the <a href="namespaces.html#mathml-namespace">MathML namespace</a> whose start tag token had an attribute with the name "encoding" whose value was an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">application/xhtml+xml</code>"</li>
<li>A <code title="">foreignObject</code> element in the <a href="namespaces.html#svg-namespace">SVG namespace</a></li>
<li>A <code title="">desc</code> element in the <a href="namespaces.html#svg-namespace">SVG namespace</a></li>
<li>A <code title="">title</code> element in the <a href="namespaces.html#svg-namespace">SVG namespace</a></li>
</ul><hr><p>When the steps below require the UA to <dfn id="insert-a-character">insert a
character</dfn> into a node, if that node has a child immediately
before where the character is to be inserted, and that child is a
<code><a href="infrastructure.html#text">Text</a></code> node, then the character must be appended to that
<code><a href="infrastructure.html#text">Text</a></code> node; otherwise, a new <code><a href="infrastructure.html#text">Text</a></code> node
whose data is just that character must be inserted in the
appropriate place.</p>
<div class="example">
<p>Here are some sample inputs to the parser and the corresponding
number of text nodes that they result in, assuming a user agent
that executes scripts.</p>
<table><thead><tr><th>Input </th><th>Number of text nodes
</th></tr></thead><tbody><tr><td><pre>A&lt;script&gt;
var&#160;script&#160;=&#160;document.getElementsByTagName('script')[0];
document.body.removeChild(script);
&lt;/script&gt;B</pre>
</td><td>One text node in the document, containing "AB".
</td></tr><tr><td><pre>A&lt;script&gt;
var&#160;text&#160;=&#160;document.createTextNode('B');
document.body.appendChild(text);
&lt;/script&gt;C</pre>
</td><td>Three text nodes; "A" before the script, the script's contents, and "BC" after the script (the parser appends to the text node created by the script).
</td></tr><tr><td><pre>A&lt;script&gt;
var&#160;text&#160;=&#160;document.getElementsByTagName('script')[0].firstChild;
text.data&#160;=&#160;'B';
document.body.appendChild(text);
&lt;/script&gt;C</pre>
</td><td>Two adjacent text nodes in the document, containing "A" and "BC".
</td></tr><tr><td><pre>A&lt;table&gt;B&lt;tr&gt;C&lt;/tr&gt;D&lt;/table&gt;</pre>
</td><td>One text node before the table, containing "ABCD". (This is caused by <a href="#foster-parent" title="foster parent">foster parenting</a>.)
</td></tr><tr><td><pre>A&lt;table&gt;&lt;tr&gt;&#160;B&lt;/tr&gt;&#160;C&lt;/table&gt;</pre>
</td><td>One text node before the table, containing "A&#160;B&#160;C" (A-space-B-space-C). (This is caused by <a href="#foster-parent" title="foster parent">foster parenting</a>.)
</td></tr><tr><td><pre>A&lt;table&gt;&lt;tr&gt;&#160;B&lt;/tr&gt;&#160;&lt;/em&gt;C&lt;/table&gt;</pre>
</td><td>One text node before the table, containing "A&#160;BC" (A-space-B-C), and one text node inside the table (as a child of a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>) with a single space character. (Space characters separated from non-space characters by non-character tokens are not affected by <a href="#foster-parent" title="foster parent">foster parenting</a>, even if those other tokens then get ignored.)
</td></tr></tbody></table></div>
<p id="mutation-during-parsing">DOM mutation events must not fire
for changes caused by the UA parsing the document. (Conceptually,
the parser is not mutating the DOM, it is constructing it.) This
includes the parsing of any content inserted using <code title="dom-document-write"><a href="apis-in-html-documents.html#dom-document-write">document.write()</a></code> and <code title="dom-document-writeln"><a href="apis-in-html-documents.html#dom-document-writeln">document.writeln()</a></code> calls. <a href="references.html#refsDOMEVENTS">[DOMEVENTS]</a></p>
<p class="note">Not all of the tag names mentioned below are
conformant tag names in this specification; many are included to
handle legacy content. They still form part of the algorithm that
implementations are required to implement to claim conformance.</p>
<p class="note">The algorithm described below places no limit on the
depth of the DOM tree generated, or on the length of tag names,
attribute names, attribute values, text nodes, etc. While
implementors are encouraged to avoid arbitrary limits, it is
recognized that <a href="infrastructure.html#hardwareLimitations">practical
concerns</a> will likely force user agents to impose nesting depth
constraints.</p>
<h5 id="creating-and-inserting-elements"><span class="secno">8.2.5.1 </span>Creating and inserting elements</h5>
<p>When the steps below require the UA to <dfn id="create-an-element-for-the-token" title="create an
element for the token">create an element for a token</dfn> in a
particular namespace, the UA must create a node implementing the
interface appropriate for the element type corresponding to the tag
name of the token in the given namespace (as given in the
specification that defines that element, e.g. for an <code><a href="text-level-semantics.html#the-a-element">a</a></code>
element in the <a href="namespaces.html#html-namespace-0">HTML namespace</a>, this specification
defines it to be the <code><a href="text-level-semantics.html#htmlanchorelement">HTMLAnchorElement</a></code> interface), with
the tag name being the name of that element, with the node being in
the given namespace, and with the attributes on the node being those
given in the given token.</p>
<p>The interface appropriate for an element in the <a href="namespaces.html#html-namespace-0">HTML
namespace</a> that is not defined in this specification (or
<a href="infrastructure.html#other-applicable-specifications">other applicable specifications</a>) is
<code><a href="elements.html#htmlunknownelement">HTMLUnknownElement</a></code>. Element in other namespaces whose
interface is not defined by that namespace's specification must use
the interface <code><a href="infrastructure.html#element">Element</a></code>.</p>
<p>When a <a href="forms.html#category-reset" title="category-reset">resettable element</a> is
created in this manner, its <a href="association-of-controls-and-forms.html#concept-form-reset-control" title="concept-form-reset-control">reset algorithm</a> must be
invoked once the attributes are set. (This initializes the element's
<a href="association-of-controls-and-forms.html#concept-fe-value" title="concept-fe-value">value</a> and <a href="association-of-controls-and-forms.html#concept-fe-checked" title="concept-fe-checked">checkedness</a> based on the element's
attributes.)</p>
<hr><p>When the steps below require the UA to <dfn id="insert-an-html-element">insert an HTML
element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
for the token</a> in the <a href="namespaces.html#html-namespace-0">HTML namespace</a>, and then
append this node to the <a href="parsing.html#current-node">current node</a>, and push it onto
the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> so that it is the new
<a href="parsing.html#current-node">current node</a>.</p>
<p>The steps below may also require that the UA insert an HTML
element in a particular place, in which case the UA must follow the
same steps except that it must insert or append the new node in the
location specified instead of appending it to the <a href="parsing.html#current-node">current
node</a>. (This happens in particular during the parsing of
tables with invalid content.)</p>
<p>If an element created by the <a href="#insert-an-html-element">insert an HTML element</a>
algorithm is a <a href="forms.html#form-associated-element">form-associated element</a>, and the
<a href="parsing.html#form-element-pointer"><code title="">form</code> element pointer</a> is not null,
and the newly created element doesn't have a <code title="attr-fae-form"><a href="association-of-controls-and-forms.html#attr-fae-form">form</a></code> attribute, the user agent must
<a href="association-of-controls-and-forms.html#concept-form-association" title="concept-form-association">associate</a> the newly
created element with the <code><a href="forms.html#the-form-element">form</a></code> element pointed to by the
<a href="parsing.html#form-element-pointer"><code title="">form</code> element pointer</a> when the
element is inserted, instead of running the <a href="association-of-controls-and-forms.html#reset-the-form-owner">reset the form
owner</a> algorithm.</p>
<hr><p>When the steps below require the UA to <dfn id="insert-a-foreign-element">insert a foreign
element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
for the token</a> in the given namespace, and then append this
node to the <a href="parsing.html#current-node">current node</a>, and push it onto the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a> so that it is the new
<a href="parsing.html#current-node">current node</a>. If the newly created element has an <code title="">xmlns</code> attribute in the <a href="namespaces.html#xmlns-namespace">XMLNS namespace</a>
whose value is not exactly the same as the element's namespace, that
is a <a href="parsing.html#parse-error">parse error</a>. Similarly, if the newly created
element has an <code title="">xmlns:xlink</code> attribute in the
<a href="namespaces.html#xmlns-namespace">XMLNS namespace</a> whose value is not the <a href="namespaces.html#xlink-namespace">XLink
Namespace</a>, that is a <a href="parsing.html#parse-error">parse error</a>.</p>
<p>When the steps below require the user agent to <dfn id="adjust-mathml-attributes">adjust MathML
attributes</dfn> for a token, then, if the token has an attribute
named <code title="">definitionurl</code>, change its name to <code title="">definitionURL</code> (note the case difference).</p>
<p>When the steps below require the user agent to <dfn id="adjust-svg-attributes">adjust SVG
attributes</dfn> for a token, then, for each attribute on the token
whose attribute name is one of the ones in the first column of the
following table, change the attribute's name to the name given in
the corresponding cell in the second column. (This fixes the case of
SVG attributes that are not all lowercase.)</p>
<table><thead><tr><th> Attribute name on token </th><th> Attribute name on element
</th></tr></thead><tbody><tr><td> <code title="">attributename</code> </td><td> <code title="">attributeName</code>
</td></tr><tr><td> <code title="">attributetype</code> </td><td> <code title="">attributeType</code>
</td></tr><tr><td> <code title="">basefrequency</code> </td><td> <code title="">baseFrequency</code>
</td></tr><tr><td> <code title="">baseprofile</code> </td><td> <code title="">baseProfile</code>
</td></tr><tr><td> <code title="">calcmode</code> </td><td> <code title="">calcMode</code>
</td></tr><tr><td> <code title="">clippathunits</code> </td><td> <code title="">clipPathUnits</code>
</td></tr><tr><td> <code title="">contentscripttype</code> </td><td> <code title="">contentScriptType</code>
</td></tr><tr><td> <code title="">contentstyletype</code> </td><td> <code title="">contentStyleType</code>
</td></tr><tr><td> <code title="">diffuseconstant</code> </td><td> <code title="">diffuseConstant</code>
</td></tr><tr><td> <code title="">edgemode</code> </td><td> <code title="">edgeMode</code>
</td></tr><tr><td> <code title="">externalresourcesrequired</code> </td><td> <code title="">externalResourcesRequired</code>
</td></tr><tr><td> <code title="">filterres</code> </td><td> <code title="">filterRes</code>
</td></tr><tr><td> <code title="">filterunits</code> </td><td> <code title="">filterUnits</code>
</td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
</td></tr><tr><td> <code title="">gradienttransform</code> </td><td> <code title="">gradientTransform</code>
</td></tr><tr><td> <code title="">gradientunits</code> </td><td> <code title="">gradientUnits</code>
</td></tr><tr><td> <code title="">kernelmatrix</code> </td><td> <code title="">kernelMatrix</code>
</td></tr><tr><td> <code title="">kernelunitlength</code> </td><td> <code title="">kernelUnitLength</code>
</td></tr><tr><td> <code title="">keypoints</code> </td><td> <code title="">keyPoints</code>
</td></tr><tr><td> <code title="">keysplines</code> </td><td> <code title="">keySplines</code>
</td></tr><tr><td> <code title="">keytimes</code> </td><td> <code title="">keyTimes</code>
</td></tr><tr><td> <code title="">lengthadjust</code> </td><td> <code title="">lengthAdjust</code>
</td></tr><tr><td> <code title="">limitingconeangle</code> </td><td> <code title="">limitingConeAngle</code>
</td></tr><tr><td> <code title="">markerheight</code> </td><td> <code title="">markerHeight</code>
</td></tr><tr><td> <code title="">markerunits</code> </td><td> <code title="">markerUnits</code>
</td></tr><tr><td> <code title="">markerwidth</code> </td><td> <code title="">markerWidth</code>
</td></tr><tr><td> <code title="">maskcontentunits</code> </td><td> <code title="">maskContentUnits</code>
</td></tr><tr><td> <code title="">maskunits</code> </td><td> <code title="">maskUnits</code>
</td></tr><tr><td> <code title="">numoctaves</code> </td><td> <code title="">numOctaves</code>
</td></tr><tr><td> <code title="">pathlength</code> </td><td> <code title="">pathLength</code>
</td></tr><tr><td> <code title="">patterncontentunits</code> </td><td> <code title="">patternContentUnits</code>
</td></tr><tr><td> <code title="">patterntransform</code> </td><td> <code title="">patternTransform</code>
</td></tr><tr><td> <code title="">patternunits</code> </td><td> <code title="">patternUnits</code>
</td></tr><tr><td> <code title="">pointsatx</code> </td><td> <code title="">pointsAtX</code>
</td></tr><tr><td> <code title="">pointsaty</code> </td><td> <code title="">pointsAtY</code>
</td></tr><tr><td> <code title="">pointsatz</code> </td><td> <code title="">pointsAtZ</code>
</td></tr><tr><td> <code title="">preservealpha</code> </td><td> <code title="">preserveAlpha</code>
</td></tr><tr><td> <code title="">preserveaspectratio</code> </td><td> <code title="">preserveAspectRatio</code>
</td></tr><tr><td> <code title="">primitiveunits</code> </td><td> <code title="">primitiveUnits</code>
</td></tr><tr><td> <code title="">refx</code> </td><td> <code title="">refX</code>
</td></tr><tr><td> <code title="">refy</code> </td><td> <code title="">refY</code>
</td></tr><tr><td> <code title="">repeatcount</code> </td><td> <code title="">repeatCount</code>
</td></tr><tr><td> <code title="">repeatdur</code> </td><td> <code title="">repeatDur</code>
</td></tr><tr><td> <code title="">requiredextensions</code> </td><td> <code title="">requiredExtensions</code>
</td></tr><tr><td> <code title="">requiredfeatures</code> </td><td> <code title="">requiredFeatures</code>
</td></tr><tr><td> <code title="">specularconstant</code> </td><td> <code title="">specularConstant</code>
</td></tr><tr><td> <code title="">specularexponent</code> </td><td> <code title="">specularExponent</code>
</td></tr><tr><td> <code title="">spreadmethod</code> </td><td> <code title="">spreadMethod</code>
</td></tr><tr><td> <code title="">startoffset</code> </td><td> <code title="">startOffset</code>
</td></tr><tr><td> <code title="">stddeviation</code> </td><td> <code title="">stdDeviation</code>
</td></tr><tr><td> <code title="">stitchtiles</code> </td><td> <code title="">stitchTiles</code>
</td></tr><tr><td> <code title="">surfacescale</code> </td><td> <code title="">surfaceScale</code>
</td></tr><tr><td> <code title="">systemlanguage</code> </td><td> <code title="">systemLanguage</code>
</td></tr><tr><td> <code title="">tablevalues</code> </td><td> <code title="">tableValues</code>
</td></tr><tr><td> <code title="">targetx</code> </td><td> <code title="">targetX</code>
</td></tr><tr><td> <code title="">targety</code> </td><td> <code title="">targetY</code>
</td></tr><tr><td> <code title="">textlength</code> </td><td> <code title="">textLength</code>
</td></tr><tr><td> <code title="">viewbox</code> </td><td> <code title="">viewBox</code>
</td></tr><tr><td> <code title="">viewtarget</code> </td><td> <code title="">viewTarget</code>
</td></tr><tr><td> <code title="">xchannelselector</code> </td><td> <code title="">xChannelSelector</code>
</td></tr><tr><td> <code title="">ychannelselector</code> </td><td> <code title="">yChannelSelector</code>
</td></tr><tr><td> <code title="">zoomandpan</code> </td><td> <code title="">zoomAndPan</code>
</td></tr></tbody></table><p>When the steps below require the user agent to <dfn id="adjust-foreign-attributes">adjust
foreign attributes</dfn> for a token, then, if any of the attributes
on the token match the strings given in the first column of the
following table, let the attribute be a namespaced attribute, with
the prefix being the string given in the corresponding cell in the
second column, the local name being the string given in the
corresponding cell in the third column, and the namespace being the
namespace given in the corresponding cell in the fourth
column. (This fixes the use of namespaced attributes, in particular
<a href="elements.html#attr-xml-lang" title="attr-xml-lang"><code title="">lang</code> attributes in
the <span>XML namespace</span></a>.)</p>
<table><thead><tr><th> Attribute name </th><th> Prefix </th><th> Local name </th><th> Namespace
</th></tr></thead><tbody><tr><td> <code title="">xlink:actuate</code> </td><td> <code title="">xlink</code> </td><td> <code title="">actuate</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a>
</td></tr><tr><td> <code title="">xlink:arcrole</code> </td><td> <code title="">xlink</code> </td><td> <code title="">arcrole</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a>
</td></tr><tr><td> <code title="">xlink:href</code> </td><td> <code title="">xlink</code> </td><td> <code title="">href</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a>
</td></tr><tr><td> <code title="">xlink:role</code> </td><td> <code title="">xlink</code> </td><td> <code title="">role</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a>
</td></tr><tr><td> <code title="">xlink:show</code> </td><td> <code title="">xlink</code> </td><td> <code title="">show</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a>
</td></tr><tr><td> <code title="">xlink:title</code> </td><td> <code title="">xlink</code> </td><td> <code title="">title</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a>
</td></tr><tr><td> <code title="">xlink:type</code> </td><td> <code title="">xlink</code> </td><td> <code title="">type</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a>
</td></tr><tr><td> <code title="">xml:base</code> </td><td> <code title="">xml</code> </td><td> <code title="">base</code> </td><td> <a href="namespaces.html#xml-namespace">XML namespace</a>
</td></tr><tr><td> <code title="">xml:lang</code> </td><td> <code title="">xml</code> </td><td> <code title="">lang</code> </td><td> <a href="namespaces.html#xml-namespace">XML namespace</a>
</td></tr><tr><td> <code title="">xml:space</code> </td><td> <code title="">xml</code> </td><td> <code title="">space</code> </td><td> <a href="namespaces.html#xml-namespace">XML namespace</a>
</td></tr><tr><td> <code title="">xmlns</code> </td><td> (none) </td><td> <code title="">xmlns</code> </td><td> <a href="namespaces.html#xmlns-namespace">XMLNS namespace</a>
</td></tr><tr><td> <code title="">xmlns:xlink</code> </td><td> <code title="">xmlns</code> </td><td> <code title="">xlink</code> </td><td> <a href="namespaces.html#xmlns-namespace">XMLNS namespace</a>
</td></tr></tbody></table><hr><p>The <dfn id="generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</dfn> and the
<dfn id="generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</dfn> consist of the
following steps. These algorithms are always invoked in response to
a start tag token.</p>
<ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p></li>
<li><p>If the algorithm that was invoked is the <a href="#generic-raw-text-element-parsing-algorithm">generic raw
text element parsing algorithm</a>, switch the tokenizer to the
<a href="tokenization.html#rawtext-state">RAWTEXT state</a>; otherwise the algorithm invoked
was the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>,
switch the tokenizer to the <a href="tokenization.html#rcdata-state">RCDATA state</a>.</p></li>
<li><p>Let the <a href="parsing.html#original-insertion-mode">original insertion mode</a> be the current
<a href="parsing.html#insertion-mode">insertion mode</a>.</p>
</li><li><p>Then, switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: text">text</a>".</p></li>
</ol><h5 id="closing-elements-that-have-implied-end-tags"><span class="secno">8.2.5.2 </span>Closing elements that have implied end tags</h5>
<p>When the steps below require the UA to <dfn id="generate-implied-end-tags">generate implied end
tags</dfn>, then, while the <a href="parsing.html#current-node">current node</a> is a
<code><a href="grouping-content.html#the-dd-element">dd</a></code> element, a <code><a href="grouping-content.html#the-dt-element">dt</a></code> element, an
<code><a href="grouping-content.html#the-li-element">li</a></code> element, an <code><a href="the-button-element.html#the-option-element">option</a></code> element, an
<code><a href="the-button-element.html#the-optgroup-element">optgroup</a></code> element, a <code><a href="grouping-content.html#the-p-element">p</a></code> element, an
<code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element, or an <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element, the UA must
pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p>If a step requires the UA to generate implied end tags but lists
an element to exclude from the process, then the UA must perform the
above steps as if that element was not in the above list.</p>
<h5 id="foster-parenting"><span class="secno">8.2.5.3 </span>Foster parenting</h5>
<p>Foster parenting happens when content is misnested in tables.</p>
<p>When a node <var title="">node</var> is to be <dfn id="foster-parent" title="foster
parent">foster parented</dfn>, the node <var title="">node</var>
must be inserted into the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
<p>The <dfn id="foster-parent-element">foster parent element</dfn> is the parent element of the
last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>, if there is a <code><a href="tabular-data.html#the-table-element">table</a></code> element and it has
such a parent element.</p>
<p class="note">It might have no parent or some other kind parent if
a script manipulated the DOM after the element was inserted by the
parser.</p>
<p>If there is no <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="parsing.html#stack-of-open-elements">stack of
open elements</a> (<a href="the-end.html#fragment-case">fragment case</a>), then the
<i><a href="#foster-parent-element">foster parent element</a></i> is the first element in the <a href="parsing.html#stack-of-open-elements">stack
of open elements</a> (the <code><a href="semantics.html#the-html-element">html</a></code> element). Otherwise,
if there is a <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>, but the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a> has no parent, or its parent
node is not an element, then the <i><a href="#foster-parent-element">foster parent element</a></i> is the
element before the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p>
<p>If the <i><a href="#foster-parent-element">foster parent element</a></i> is the parent element of the
last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>, then <var title="">node</var> must be inserted into
the <i><a href="#foster-parent-element">foster parent element</a></i>, immediately <em>before</em> the
last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>; otherwise, <var title="">node</var> must be
<em>appended</em> to the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
<h5 id="parsing-main-inhtml"><span class="secno">8.2.5.4 </span>The rules for parsing tokens in HTML content</h5>
<h6 id="the-initial-insertion-mode"><span class="secno">8.2.5.4.1 </span>The "<dfn title="insertion mode: initial">initial</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#the-initial-insertion-mode" title="insertion mode: initial">initial</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p>Ignore the token.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <code><a href="infrastructure.html#document">Document</a></code>
object with the <code title="">data</code> attribute set to the
data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p>If the DOCTYPE token's name is not a
<a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string "<code title="">html</code>", or the token's public identifier is not
missing, or the token's system identifier is neither missing nor a
<a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string
"<code><a href="urls.html#about:legacy-compat">about:legacy-compat</a></code>", and none of the sets of
conditions in the following list are matched, then there is a
<a href="parsing.html#parse-error">parse error</a>.</p>
<ul><li>The DOCTYPE token's name is a <a href="infrastructure.html#case-sensitive">case-sensitive</a>
match for the string "<code title="">html</code>", the token's
public identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a> string
"<code title="">-//W3C//DTD&#160;HTML&#160;4.0//EN</code>", and
the token's system identifier is either missing or the
<a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/REC-html40/strict.dtd</code>".</li>
<li>The DOCTYPE token's name is a <a href="infrastructure.html#case-sensitive">case-sensitive</a>
match for the string "<code title="">html</code>", the token's
public identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a> string
"<code title="">-//W3C//DTD&#160;HTML&#160;4.01//EN</code>", and
the token's system identifier is either missing or the
<a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/html4/strict.dtd</code>".</li>
<li>The DOCTYPE token's name is a <a href="infrastructure.html#case-sensitive">case-sensitive</a>
match for the string "<code title="">html</code>", the token's
public identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a> string
"<code title="">-//W3C//DTD&#160;XHTML&#160;1.0&#160;Strict//EN</code>",
and the token's system identifier is the
<a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</code>".</li>
<li>The DOCTYPE token's name is a <a href="infrastructure.html#case-sensitive">case-sensitive</a>
match for the string "<code title="">html</code>", the token's
public identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a> string
"<code title="">-//W3C//DTD&#160;XHTML&#160;1.1//EN</code>", and
the token's system identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a>
string "<code title="">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</code>".</li>
</ul><p>Conformance checkers may, based on the values (including
presence or lack thereof) of the DOCTYPE token's name, public
identifier, or system identifier, switch to a conformance checking
mode for another language (e.g. based on the DOCTYPE token a
conformance checker could recognize that the document is an
HTML4-era document, and defer to an HTML4 conformance
checker.)</p>
<p>Append a <code><a href="infrastructure.html#documenttype">DocumentType</a></code> node to the
<code><a href="infrastructure.html#document">Document</a></code> node, with the <code title="">name</code>
attribute set to the name given in the DOCTYPE token, or the empty
string if the name was missing; the <code title="">publicId</code>
attribute set to the public identifier given in the DOCTYPE token,
or the empty string if the public identifier was missing; the
<code title="">systemId</code> attribute set to the system
identifier given in the DOCTYPE token, or the empty string if the
system identifier was missing; and the other attributes specific
to <code><a href="infrastructure.html#documenttype">DocumentType</a></code> objects set to null and empty lists
as appropriate. Associate the <code><a href="infrastructure.html#documenttype">DocumentType</a></code> node with
the <code><a href="infrastructure.html#document">Document</a></code> object so that it is returned as the
value of the <code title="">doctype</code> attribute of the
<code><a href="infrastructure.html#document">Document</a></code> object.</p>
<p id="quirks-mode-doctypes">Then, if the DOCTYPE token matches
one of the conditions in the following list, then set the
<code><a href="infrastructure.html#document">Document</a></code> to <a href="dom.html#quirks-mode">quirks mode</a>:</p>
<ul class="brief"><li> The <i>force-quirks flag</i> is set to <i>on</i>. </li>
<li> The name is set to anything other than "<code title="">html</code>" (compared <a href="infrastructure.html#case-sensitive" title="case-sensitive">case-sensitively</a>). </li>
<li> The public identifier starts with: "<code title="">+//Silmaril//dtd html Pro v0r11 19970101//</code>" </li>
<li> The public identifier starts with: "<code title="">-//AdvaSoft Ltd//DTD HTML 3.0 asWedit + extensions//</code>" </li>
<li> The public identifier starts with: "<code title="">-//AS//DTD HTML 3.0 asWedit + extensions//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 1//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 2//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 1//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 2//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.1E//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2 Final//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 1//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 2//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 3//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 1//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 2//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 3//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Metrius//DTD Metrius Presentational//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML Strict//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 Tables//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML Strict//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 Tables//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD HTML//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD Strict HTML//</code>" </li>
<li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML 2.0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended 1.0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended Relaxed 1.0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//SoftQuad Software//DTD HoTMetaL PRO 6.0::19990601::extensions to HTML 4.0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//SoftQuad//DTD HoTMetaL PRO 4.0::19971010::extensions to HTML 4.0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Spyglass//DTD HTML 2.0 Extended//</code>" </li>
<li> The public identifier starts with: "<code title="">-//SQ//DTD HTML 2.0 HoTMetaL + extensions//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava HTML//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava Strict HTML//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3 1995-03-24//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Draft//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Final//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2S Draft//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Frameset//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Transitional//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 19960712//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 970421//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD W3 HTML//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3O//DTD W3 HTML 3.0//</code>" </li>
<li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML Strict 3.0//EN//</code>" </li>
<li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML 2.0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML//</code>" </li>
<li> The public identifier is set to: "<code title="">-/W3C/DTD HTML 4.0 Transitional/EN</code>" </li>
<li> The public identifier is set to: "<code title="">HTML</code>" </li>
<li> The system identifier is set to: "<code title="">http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd</code>" </li>
<li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//</code>" </li>
<li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//</code>" </li>
</ul><p>Otherwise, if the DOCTYPE token matches one of the conditions
in the following list, then set the <code><a href="infrastructure.html#document">Document</a></code> to
<a href="dom.html#limited-quirks-mode">limited-quirks mode</a>:</p>
<ul class="brief"><li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Frameset//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Transitional//</code>" </li>
<li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//</code>" </li>
<li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//</code>" </li>
</ul><p>The system identifier and public identifier strings must be
compared to the values given in the lists above in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
case-insensitive</a> manner. A system identifier whose value is
the empty string is not considered missing for the purposes of the
conditions above.</p>
<p>Then, switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>".</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>If the document is <em>not</em> <a href="the-iframe-element.html#an-iframe-srcdoc-document">an <code>iframe</code>
<code title="attr-iframe-srcdoc">srcdoc</code> document</a>,
then this is a <a href="parsing.html#parse-error">parse error</a>; set the
<code><a href="infrastructure.html#document">Document</a></code> to <a href="dom.html#quirks-mode">quirks mode</a>.</p>
<p>In any case, switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>", then
reprocess the current token.</p>
</dd>
</dl><h6 id="the-before-html-insertion-mode"><span class="secno">8.2.5.4.2 </span>The "<dfn title="insertion mode: before html">before html</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <code><a href="infrastructure.html#document">Document</a></code>
object with the <code title="">data</code> attribute set to the
data given in the comment token.</p>
</dd>
<dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p>Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the <a href="namespaces.html#html-namespace-0">HTML
namespace</a>. Append it to the <code><a href="infrastructure.html#document">Document</a></code>
object. Put this element in the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p id="parser-appcache">If the <code><a href="infrastructure.html#document">Document</a></code> is being
loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a
<a href="browsers.html#browsing-context">browsing context</a>, then: if the newly created element
has a <code title="attr-html-manifest"><a href="semantics.html#attr-html-manifest">manifest</a></code> attribute
whose value is not the empty string, then <a href="urls.html#resolve-a-url" title="resolve a
url">resolve</a> the value of that attribute to an
<a href="urls.html#absolute-url">absolute URL</a>, relative to the newly created element,
and if that is successful, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
algorithm</a> with the resulting <a href="urls.html#absolute-url">absolute URL</a> with
any <a href="urls.html#url-fragment" title="url-fragment">&lt;fragment&gt;</a> component
removed; otherwise, if there is no such attribute, or its value is
the empty string, or resolving its value fails, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
algorithm</a> with no manifest. The algorithm must be passed
the <code><a href="infrastructure.html#document">Document</a></code> object.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>".</p>
</dd>
<dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
<dd>
<p>Act as described in the "anything else" entry below.</p>
</dd>
<dt>Any other end tag</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Create an <code><a href="semantics.html#the-html-element">html</a></code> element. Append it to the
<code><a href="infrastructure.html#document">Document</a></code> object. Put this element in the <a href="parsing.html#stack-of-open-elements">stack
of open elements</a>.</p>
<p>If the <code><a href="infrastructure.html#document">Document</a></code> is being loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a <a href="browsers.html#browsing-context">browsing
context</a>, then: run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
algorithm</a> with no manifest, passing it the
<code><a href="infrastructure.html#document">Document</a></code> object.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>", then
reprocess the current token.</p>
</dd>
</dl><p>The root element can end up being removed from the
<code><a href="infrastructure.html#document">Document</a></code> object, e.g. by scripts; nothing in particular
happens in such cases, content continues being appended to the nodes
as described in the next section.</p>
<h6 id="the-before-head-insertion-mode"><span class="secno">8.2.5.4.3 </span>The "<dfn title="insertion mode: before head">before head</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p>Ignore the token.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>A start tag whose tag name is "head"</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Set the <a href="parsing.html#head-element-pointer"><code title="">head</code> element pointer</a>
to the newly created <code><a href="semantics.html#the-head-element">head</a></code> element.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>".</p>
</dd>
<dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
<dd>
<p>Act as if a start tag token with the tag name "head" and no
attributes had been seen, then reprocess the current token.</p>
</dd>
<dt>Any other end tag</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Act as if a start tag token with the tag name "head" and no
attributes had been seen, then reprocess the current
token.</p>
</dd>
</dl><h6 id="parsing-main-inhead"><span class="secno">8.2.5.4.4 </span>The "<dfn title="insertion mode: in head">in head</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
the <a href="parsing.html#current-node">current node</a>.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>A start tag whose tag name is one of: "base", "basefont",
"bgsound", "command", "link"</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p><a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
token's <i>self-closing flag</i></a>, if it is set.</p>
</dd>
<dt>A start tag whose tag name is "meta"</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p><a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
token's <i>self-closing flag</i></a>, if it is set.</p>
<p id="meta-charset-during-parse">If the element has a <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute, and its value
is either a supported <a href="infrastructure.html#ascii-compatible-character-encoding">ASCII-compatible character
encoding</a> or a UTF-16 encoding, and the <a href="parsing.html#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is currently
<i>tentative</i>, then <a href="parsing.html#change-the-encoding">change the encoding</a> to the
encoding given by the value of the <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute.</p>
<p>Otherwise, if the element has an <code title="attr-meta-http-equiv"><a href="semantics.html#attr-meta-http-equiv">http-equiv</a></code> attribute whose
value is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the
string "<code title="">Content-Type</code>", and the element has a
<code title="attr-meta-content"><a href="semantics.html#attr-meta-content">content</a></code> attribute, and
applying the <a href="fetching-resources.html#algorithm-for-extracting-an-encoding-from-a-meta-element">algorithm for extracting an encoding from a
<code>meta</code> element</a> to that attribute's value returns
a supported <a href="infrastructure.html#ascii-compatible-character-encoding">ASCII-compatible character encoding</a> or a
UTF-16 encoding, and the <a href="parsing.html#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is currently
<i>tentative</i>, then <a href="parsing.html#change-the-encoding">change the encoding</a> to the
extracted encoding.</p>
</dd>
<dt>A start tag whose tag name is "title"</dt>
<dd>
<p>Follow the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>.</p>
</dd>
<dt>A start tag whose tag name is "noscript", if the <a href="parsing.html#scripting-flag">scripting flag</a> is enabled</dt>
<dt>A start tag whose tag name is one of: "noframes", "style"</dt>
<dd>
<p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
</dd>
<dt>A start tag whose tag name is "noscript", if the <a href="parsing.html#scripting-flag">scripting flag</a> is disabled</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head
noscript</a>".</p>
</dd>
<dt id="scriptTag">A start tag whose tag name is "script"</dt>
<dd>
<p>Run these steps:</p>
<ol><li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the
<a href="namespaces.html#html-namespace-0">HTML namespace</a>.</p></li>
<li>
<p>Mark the element as being <a href="scripting-1.html#parser-inserted">"parser-inserted"</a> and
unset the element's <a href="scripting-1.html#force-async">"force-async"</a> flag.</p>
<p class="note">This ensures that, if the script is external,
any <code title="dom-document-write"><a href="apis-in-html-documents.html#dom-document-write">document.write()</a></code>
calls in the script will execute in-line, instead of blowing the
document away, as would happen in most other cases. It also
prevents the script from executing until the end tag is
seen.</p>
</li>
<li><p>If the parser was originally created for the <a href="the-end.html#html-fragment-parsing-algorithm">HTML
fragment parsing algorithm</a>, then mark the
<code><a href="scripting-1.html#the-script-element">script</a></code> element as <a href="scripting-1.html#already-started">"already
started"</a>. (<a href="the-end.html#fragment-case">fragment case</a>)</p></li>
<li><p>Append the new element to the <a href="parsing.html#current-node">current node</a>
and push it onto the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p></li>
<li><p>Switch the tokenizer to the <a href="tokenization.html#script-data-state">script data
state</a>.</p></li>
<li><p>Let the <a href="parsing.html#original-insertion-mode">original insertion mode</a> be the current
<a href="parsing.html#insertion-mode">insertion mode</a>.</p>
</li><li><p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: text">text</a>".</p></li>
</ol></dd>
<dt>An end tag whose tag name is "head"</dt>
<dd>
<p>Pop the <a href="parsing.html#current-node">current node</a> (which will be the
<code><a href="semantics.html#the-head-element">head</a></code> element) off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#the-after-head-insertion-mode" title="insertion mode: after head">after head</a>".</p>
</dd>
<dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
<dd>
<p>Act as described in the "anything else" entry below.</p>
</dd>
<dt>A start tag whose tag name is "head"</dt>
<dt>Any other end tag</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Act as if an end tag token with the tag name "head" had
been seen, and reprocess the current token.</p>
</dd>
</dl><h6 id="parsing-main-inheadnoscript"><span class="secno">8.2.5.4.5 </span>The "<dfn title="insertion mode: in head noscript">in head noscript</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head noscript</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>An end tag whose tag name is "noscript"</dt>
<dd>
<p>Pop the <a href="parsing.html#current-node">current node</a> (which will be a
<code><a href="scripting-1.html#the-noscript-element">noscript</a></code> element) from the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>; the new <a href="parsing.html#current-node">current node</a> will be a
<code><a href="semantics.html#the-head-element">head</a></code> element.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>".</p>
</dd>
<dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dt>A comment token</dt>
<dt>A start tag whose tag name is one of: "basefont", "bgsound",
"link", "meta", "noframes", "style"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>An end tag whose tag name is "br"</dt>
<dd>
<p>Act as described in the "anything else" entry below.</p>
</dd>
<dt>A start tag whose tag name is one of: "head", "noscript"</dt>
<dt>Any other end tag</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Act as if an end tag with the tag
name "noscript" had been seen and reprocess the current
token.</p>
</dd>
</dl><h6 id="the-after-head-insertion-mode"><span class="secno">8.2.5.4.6 </span>The "<dfn title="insertion mode: after head">after head</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#the-after-head-insertion-mode" title="insertion mode: after head">after head</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
the <a href="parsing.html#current-node">current node</a>.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>A start tag whose tag name is "body"</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>".</p>
</dd>
<dt>A start tag whose tag name is "frameset"</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inframeset" title="insertion mode: in frameset">in frameset</a>".</p>
</dd>
<dt>A start tag token whose tag name is one of: "base", "basefont",
"bgsound", "link", "meta", "noframes", "script", "style",
"title"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p>Push the node pointed to by the <a href="parsing.html#head-element-pointer"><code title="">head</code> element pointer</a> onto the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
<p>Remove the node pointed to by the <a href="parsing.html#head-element-pointer"><code title="">head</code> element pointer</a> from the <a href="parsing.html#stack-of-open-elements">stack
of open elements</a>.</p>
<p class="note">The <a href="parsing.html#head-element-pointer"><code title="">head</code> element
pointer</a> cannot be null at this point.</p>
</dd>
<dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
<dd>
<p>Act as described in the "anything else" entry below.</p>
</dd>
<dt>A start tag whose tag name is "head"</dt>
<dt>Any other end tag</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Act as if a start tag token with the tag name "body" and no
attributes had been seen, then set the <a href="parsing.html#frameset-ok-flag">frameset-ok
flag</a> back to "ok", and then reprocess the current
token.</p>
</dd>
</dl><h6 id="parsing-main-inbody"><span class="secno">8.2.5.4.7 </span>The "<dfn title="insertion mode: in body">in body</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is U+0000 NULL</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A character token that is one of U+0009 CHARACTER TABULATION,
U+000A LINE FEED (LF), U+000C FORM FEED (FF), U+000D CARRIAGE
RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-a-character" title="insert a character">Insert the token's
character</a> into the <a href="parsing.html#current-node">current node</a>.</p>
</dd>
<dt>Any other character token</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-a-character" title="insert a character">Insert the token's
character</a> into the <a href="parsing.html#current-node">current node</a>.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. For each attribute on the token,
check to see if the attribute is already present on the top
element of the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>. If it is not,
add the attribute and its corresponding value to that element.</p>
</dd>
<dt>A start tag token whose tag name is one of: "base", "basefont",
"bgsound", "command", "link", "meta", "noframes", "script",
"style", "title"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>A start tag whose tag name is "body"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p>If the second element on the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> is not a <code><a href="sections.html#the-body-element">body</a></code> element, or, if the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a> has only one node on it,
then ignore the token. (<a href="the-end.html#fragment-case">fragment case</a>)</p>
<p>Otherwise, set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok";
then, for each attribute on the token, check to see if the
attribute is already present on the <code><a href="sections.html#the-body-element">body</a></code> element (the
second element) on the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>, and if
it is not, add the attribute and its corresponding value to that
element.</p>
</dd>
<dt>A start tag whose tag name is "frameset"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p>If the second element on the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> is not a <code><a href="sections.html#the-body-element">body</a></code> element, or, if the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a> has only one node on it,
then ignore the token. (<a href="the-end.html#fragment-case">fragment case</a>)</p>
<p>If the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> is set to "not ok", ignore
the token.</p>
<p>Otherwise, run the following steps:</p>
<ol><li><p>Remove the second element on the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> from its parent node, if it has one.</p></li>
<li><p>Pop all the nodes from the bottom of the <a href="parsing.html#stack-of-open-elements">stack of
open elements</a>, from the <a href="parsing.html#current-node">current node</a> up to,
but not including, the root <code><a href="semantics.html#the-html-element">html</a></code> element.</p>
</li><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
token.</p></li>
<li><p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inframeset" title="insertion mode: in frameset">in frameset</a>".</p>
</li></ol></dd>
<dt>An end-of-file token</dt>
<dd>
<p>If there is a node in the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>
that is not either a <code><a href="grouping-content.html#the-dd-element">dd</a></code> element, a <code><a href="grouping-content.html#the-dt-element">dt</a></code>
element, an <code><a href="grouping-content.html#the-li-element">li</a></code> element, a <code><a href="grouping-content.html#the-p-element">p</a></code> element, a
<code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, a <code><a href="tabular-data.html#the-td-element">td</a></code> element, a
<code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element, a <code><a href="tabular-data.html#the-th-element">th</a></code> element, a
<code><a href="tabular-data.html#the-thead-element">thead</a></code> element, a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, the
<code><a href="sections.html#the-body-element">body</a></code> element, or the <code><a href="semantics.html#the-html-element">html</a></code> element, then
this is a <a href="parsing.html#parse-error">parse error</a>.</p>
<p><a href="the-end.html#stop-parsing">Stop parsing</a>.</p>
</dd>
<dt>An end tag whose tag name is "body"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-scope" title="has an element in scope">have a <code>body</code> element
in scope</a>, this is a <a href="parsing.html#parse-error">parse error</a>; ignore the
token.</p>
<p>Otherwise, if there is a node in the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> that is not either a <code><a href="grouping-content.html#the-dd-element">dd</a></code> element, a
<code><a href="grouping-content.html#the-dt-element">dt</a></code> element, an <code><a href="grouping-content.html#the-li-element">li</a></code> element, an
<code><a href="the-button-element.html#the-optgroup-element">optgroup</a></code> element, an <code><a href="the-button-element.html#the-option-element">option</a></code> element, a
<code><a href="grouping-content.html#the-p-element">p</a></code> element, an <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element, an
<code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element, a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, a
<code><a href="tabular-data.html#the-td-element">td</a></code> element, a <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element, a
<code><a href="tabular-data.html#the-th-element">th</a></code> element, a <code><a href="tabular-data.html#the-thead-element">thead</a></code> element, a
<code><a href="tabular-data.html#the-tr-element">tr</a></code> element, the <code><a href="sections.html#the-body-element">body</a></code> element, or the
<code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="parsing.html#parse-error">parse
error</a>.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterbody" title="insertion mode: after body">after body</a>".</p>
</dd>
<dt>An end tag whose tag name is "html"</dt>
<dd>
<p>Act as if an end tag with tag name "body" had been seen,
then, if that token wasn't ignored, reprocess the current
token.</p>
</dd>
<dt>A start tag whose tag name is one of: "address", "article",
"aside", "blockquote", "center", "details", "dir", "div", "dl",
"fieldset", "figcaption", "figure", "footer", "header", "hgroup",
"menu", "nav", "ol", "p", "section", "summary", "ul"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has an
element in button scope">has a <code>p</code> element in button
scope</a>, then act as if an end tag with the tag name "p" had
been seen.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
</dd>
<dt>A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
"h5", "h6"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has
an element in button scope">has a <code>p</code> element in button
scope</a>, then act as if an end tag with the tag name
"p" had been seen.</p>
<p>If the <a href="parsing.html#current-node">current node</a> is an element whose tag name
is one of "h1", "h2", "h3", "h4", "h5", or "h6", then this is a
<a href="parsing.html#parse-error">parse error</a>; pop the <a href="parsing.html#current-node">current node</a> off
the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
</dd>
<dt>A start tag whose tag name is one of: "pre", "listing"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has
an element in button scope">has a <code>p</code> element in button
scope</a>, then act as if an end tag with the tag name
"p" had been seen.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>If the next token is a U+000A LINE FEED (LF) character
token, then ignore that token and move on to the next
one. (Newlines at the start of <code><a href="grouping-content.html#the-pre-element">pre</a></code> blocks are
ignored as an authoring convenience.)</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
</dd>
<dt>A start tag whose tag name is "form"</dt>
<dd>
<p>If the <a href="parsing.html#form-element-pointer"><code title="form">form</code> element
pointer</a> is not null, then this is a <a href="parsing.html#parse-error">parse
error</a>; ignore the token.</p>
<p>Otherwise:</p>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has
an element in button scope">has a <code>p</code> element in button
scope</a>, then act as if an end tag with the tag name
"p" had been seen.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, and set the
<a href="parsing.html#form-element-pointer"><code title="form">form</code> element pointer</a> to
point to the element created.</p>
</dd>
<dt>A start tag whose tag name is "li"</dt>
<dd>
<p>Run these steps:</p>
<ol><li><p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
<li><p>Initialize <var title="">node</var> to be the <a href="parsing.html#current-node">current
node</a> (the bottommost node of the stack).</p></li>
<li><p><i>Loop</i>: If <var title="">node</var> is an
<code><a href="grouping-content.html#the-li-element">li</a></code> element, then act as if an end tag with the tag
name "li" had been seen, then jump to the last step.</p></li>
<li><p>If <var title="">node</var> is in the <a href="parsing.html#special">special</a>
category, but is not an <code><a href="sections.html#the-address-element">address</a></code>, <code><a href="grouping-content.html#the-div-element">div</a></code>,
or <code><a href="grouping-content.html#the-p-element">p</a></code> element, then jump to the last step.</p></li>
<li><p>Otherwise, set <var title="">node</var> to the previous
entry in the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> and return to
the step labeled <i>loop</i>.</p></li>
<li>
<p>This is the last step.</p>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has
an element in button scope">has a <code>p</code> element in button
scope</a>, then act as if an end tag with the tag name
"p" had been seen.</p>
<p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
token.</p>
</li>
</ol></dd>
<dt>A start tag whose tag name is one of: "dd", "dt"</dt>
<dd>
<p>Run these steps:</p>
<ol><li><p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
<li><p>Initialize <var title="">node</var> to be the <a href="parsing.html#current-node">current
node</a> (the bottommost node of the stack).</p></li>
<li><p><i>Loop</i>: If <var title="">node</var> is a
<code><a href="grouping-content.html#the-dd-element">dd</a></code> or <code><a href="grouping-content.html#the-dt-element">dt</a></code> element, then act as if an end
tag with the same tag name as <var title="">node</var> had been
seen, then jump to the last step.</p></li>
<li><p>If <var title="">node</var> is in the <a href="parsing.html#special">special</a>
category, but is not an <code><a href="sections.html#the-address-element">address</a></code>, <code><a href="grouping-content.html#the-div-element">div</a></code>,
or <code><a href="grouping-content.html#the-p-element">p</a></code> element, then jump to the last step.</p></li>
<li><p>Otherwise, set <var title="">node</var> to the previous
entry in the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> and return to
the step labeled <i>loop</i>.</p></li>
<li>
<p>This is the last step.</p>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has
an element in button scope">has a <code>p</code> element in button
scope</a>, then act as if an end tag with the tag name
"p" had been seen.</p>
<p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
token.</p>
</li>
</ol></dd>
<dt>A start tag whose tag name is "plaintext"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has
an element in button scope">has a <code>p</code> element in button
scope</a>, then act as if an end tag with the tag name
"p" had been seen.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Switch the tokenizer to the <a href="tokenization.html#plaintext-state">PLAINTEXT state</a>.</p>
<p class="note">Once a start tag with the tag name "plaintext" has
been seen, that will be the last token ever seen other than
character tokens (and the end-of-file token), because there is no
way to switch out of the <a href="tokenization.html#plaintext-state">PLAINTEXT state</a>.</p>
</dd>
<dt>A start tag whose tag name is "button"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-scope" title="has
an element in scope">has a <code>button</code> element in
scope</a>, then this is a <a href="parsing.html#parse-error">parse error</a>;
act as if an end tag with the tag name "button" had been seen,
then reprocess the token.</p>
<p>Otherwise:</p>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
</dd>
<dt>An end tag whose tag name is one of: "address", "article",
"aside", "blockquote", "button", "center", "details", "dir", "div",
"dl", "fieldset", "figcaption", "figure", "footer", "header",
"hgroup", "listing", "menu", "nav", "ol", "pre", "section",
"summary", "ul"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-scope" title="has an element in scope">have an element in scope</a>
with the same tag name as that of the token, then this is a
<a href="parsing.html#parse-error">parse error</a>; ignore the token.</p>
<p>Otherwise, run these steps:</p>
<ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
<li><p>If the <a href="parsing.html#current-node">current node</a> is not an element with
the same tag name as that of the token, then this is a
<a href="parsing.html#parse-error">parse error</a>.</p></li>
<li><p>Pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>
until an element with the same tag name as the token has been
popped from the stack.</p></li>
</ol></dd>
<dt>An end tag whose tag name is "form"</dt>
<dd>
<p>Let <var title="">node</var> be the element that the
<a href="parsing.html#form-element-pointer"><code title="">form</code> element pointer</a> is set
to.</p>
<p>Set the <a href="parsing.html#form-element-pointer"><code title="">form</code> element pointer</a>
to null.</p>
<p>If <var title="">node</var> is null or the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> does not <a href="parsing.html#has-an-element-in-scope" title="has an element in
scope">have <var title="">node</var> in scope</a>, then this is
a <a href="parsing.html#parse-error">parse error</a>; ignore the token.</p>
<p>Otherwise, run these steps:</p>
<ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
<li><p>If the <a href="parsing.html#current-node">current node</a> is not <var title="">node</var>, then this is a <a href="parsing.html#parse-error">parse
error</a>.</p></li>
<li><p>Remove <var title="">node</var> from the <a href="parsing.html#stack-of-open-elements">stack of
open elements</a>.</p></li>
</ol></dd>
<dt>An end tag whose tag name is "p"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-button-scope" title="has an element in button scope">have an element in button
scope</a> with the same tag name as that of the token, then this
is a <a href="parsing.html#parse-error">parse error</a>; act as if a start tag with the tag
name "p" had been seen, then reprocess the current token.</p>
<p>Otherwise, run these steps:</p>
<ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
for elements with the same tag name as the token.</p></li>
<li><p>If the <a href="parsing.html#current-node">current node</a> is not an element with
the same tag name as that of the token, then this is a
<a href="parsing.html#parse-error">parse error</a>.</p></li>
<li><p>Pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>
until an element with the same tag name as the token has been
popped from the stack.</p></li>
</ol></dd>
<dt>An end tag whose tag name is "li"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-list-item-scope" title="has an element in list item scope">have an element in list
item scope</a> with the same tag name as that of the token,
then this is a <a href="parsing.html#parse-error">parse error</a>; ignore the token.</p>
<p>Otherwise, run these steps:</p>
<ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
for elements with the same tag name as the token.</p></li>
<li><p>If the <a href="parsing.html#current-node">current node</a> is not an element with
the same tag name as that of the token, then this is a
<a href="parsing.html#parse-error">parse error</a>.</p></li>
<li><p>Pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>
until an element with the same tag name as the token has been
popped from the stack.</p></li>
</ol></dd>
<dt>An end tag whose tag name is one of: "dd", "dt"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-scope" title="has an element in scope">have an element in scope</a>
with the same tag name as that of the token, then this is a
<a href="parsing.html#parse-error">parse error</a>; ignore the token.</p>
<p>Otherwise, run these steps:</p>
<ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
for elements with the same tag name as the token.</p></li>
<li><p>If the <a href="parsing.html#current-node">current node</a> is not an element with
the same tag name as that of the token, then this is a
<a href="parsing.html#parse-error">parse error</a>.</p></li>
<li><p>Pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>
until an element with the same tag name as the token has been
popped from the stack.</p></li>
</ol></dd>
<dt>An end tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-scope" title="has an element in scope">have an element in scope</a>
whose tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6",
then this is a <a href="parsing.html#parse-error">parse error</a>; ignore the token.</p>
<p>Otherwise, run these steps:</p>
<ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
<li><p>If the <a href="parsing.html#current-node">current node</a> is not an element with
the same tag name as that of the token, then this is a
<a href="parsing.html#parse-error">parse error</a>.</p></li>
<li><p>Pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>
until an element whose tag name is one of "h1", "h2", "h3", "h4",
"h5", or "h6" has been popped from the stack.</p></li>
</ol></dd>
<dt>An end tag whose tag name is "sarcasm"</dt>
<dd>
<p>Take a deep breath, then act as described in the "any other end
tag" entry below.</p>
</dd>
<dt>A start tag whose tag name is "a"</dt>
<dd>
<p>If the <a href="parsing.html#list-of-active-formatting-elements">list of active formatting elements</a>
contains an element whose tag name is "a" between the end of
the list and the last marker on the list (or the start of the
list if there is no marker on the list), then this is a
<a href="parsing.html#parse-error">parse error</a>; act as if an end tag with the tag
name "a" had been seen, then remove that element from the
<a href="parsing.html#list-of-active-formatting-elements">list of active formatting elements</a> and the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a> if the end tag didn't
already remove it (it might not have if the element is not
<a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">in table
scope</a>).</p>
<p class="example">In the non-conforming stream
<code>&lt;a&#160;href="a"&gt;a&lt;table&gt;&lt;a&#160;href="b"&gt;b&lt;/table&gt;x</code>,
the first <code><a href="text-level-semantics.html#the-a-element">a</a></code> element would be closed upon seeing the
second one, and the "x" character would be inside a link to "b",
not to "a". This is despite the fact that the outer <code><a href="text-level-semantics.html#the-a-element">a</a></code>
element is not in table scope (meaning that a regular
<code>&lt;/a&gt;</code> end tag at the start of the table wouldn't
close the outer <code><a href="text-level-semantics.html#the-a-element">a</a></code> element). The result is that the
two <code><a href="text-level-semantics.html#the-a-element">a</a></code> elements are indirectly nested inside each
other &#8212; non-conforming markup will often result in
non-conforming DOMs when parsed.</p>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. <a href="parsing.html#push-onto-the-list-of-active-formatting-elements">Push
onto the list of active formatting elements</a> that
element.</p>
</dd>
<dt>A start tag whose tag name is one of: "b", "big", "code", "em",
"font", "i", "s", "small", "strike", "strong", "tt", "u"</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. <a href="parsing.html#push-onto-the-list-of-active-formatting-elements">Push
onto the list of active formatting elements</a> that
element.</p>
</dd>
<dt>A start tag whose tag name is "nobr"</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-scope" title="has an
element in scope">has a <code>nobr</code> element in scope</a>,
then this is a <a href="parsing.html#parse-error">parse error</a>; act as if an end tag with
the tag name "nobr" had been seen, then once again
<a href="parsing.html#reconstruct-the-active-formatting-elements">reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. <a href="parsing.html#push-onto-the-list-of-active-formatting-elements">Push
onto the list of active formatting elements</a> that
element.</p>
</dd>
<dt id="adoptionAgency">An end tag whose tag name is one of: "a",
"b", "big", "code", "em", "font", "i", "nobr", "s", "small",
"strike", "strong", "tt", "u"</dt>
<dd>
<p>Run these steps:</p>
<ol><li><p>Let <var title="">outer loop counter</var> be
zero.</p></li>
<li><p><i>Outer loop</i>: If <var title="">outer loop
counter</var> is greater than or equal to eight, then abort these
steps.</p></li>
<li><p>Increment <var title="">outer loop counter</var> by
one.</p></li>
<li>
<p>Let the <var title="">formatting element</var> be the last
element in the <a href="parsing.html#list-of-active-formatting-elements">list of active formatting elements</a>
that:</p>
<ul><li>is between the end of the list and the last scope
marker in the list, if any, or the start of the list
otherwise, and</li>
<li>has the same tag name as the token.</li>
</ul><p>If there is no such node, then abort these steps and instead
act as described in the "any other end tag" entry below.</p>
<p>Otherwise, if there is such a node, but that node is not
in the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>, then this is a
<a href="parsing.html#parse-error">parse error</a>; remove the element from the list,
and abort these steps.</p>
<p>Otherwise, if there is such a node, and that node is also in
the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>, but the element is not
<a href="parsing.html#has-an-element-in-scope" title="has an element in scope">in scope</a>, then this
is a <a href="parsing.html#parse-error">parse error</a>; ignore the token, and abort these
steps.</p>
<p>Otherwise, there is a <var title="">formatting
element</var> and that element is in <a href="parsing.html#stack-of-open-elements" title="stack of
open elements">the stack</a> and is <a href="parsing.html#has-an-element-in-scope" title="has an
element in scope">in scope</a>. If the element is not the
<a href="parsing.html#current-node">current node</a>, this is a <a href="parsing.html#parse-error">parse
error</a>. In any case, proceed with the algorithm as
written in the following steps.</p>
</li>
<li><p>Let the <var title="">furthest block</var> be the topmost
node in the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> that is lower in
the stack than the <var title="">formatting element</var>, and is
an element in the <a href="parsing.html#special">special</a> category. There might not
be one.</p></li>
<li><p>If there is no <var title="">furthest block</var>,
then the UA must skip the subsequent steps and instead just
pop all the nodes from the bottom of the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>, from the <a href="parsing.html#current-node">current node</a> up to and
including the <var title="">formatting element</var>, and
remove the <var title="">formatting element</var> from the
<a href="parsing.html#list-of-active-formatting-elements">list of active formatting elements</a>.</p></li>
<li><p>Let the <var title="">common ancestor</var> be the element
immediately above the <var title="">formatting element</var> in the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p></li>
<li><p>Let a bookmark note the position of the <var title="">formatting element</var> in the <a href="parsing.html#list-of-active-formatting-elements">list of active
formatting elements</a> relative to the elements on either
side of it in the list.</p></li>
<li>
<p>Let <var title="">node</var> and <var title="">last node</var> be the
<var title="">furthest block</var>. Follow these steps:</p>
<ol><li><p>Let <var title="">inner loop counter</var> be
zero.</p></li>
<li><p><i>Inner loop</i>: If <var title="">inner loop
counter</var> is greater than or equal to three, then abort these
steps.</p></li>
<li><p>Increment <var title="">inner loop counter</var> by
one.</p></li>
<li>Let <var title="">node</var> be the element immediately
above <var title="">node</var> in the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>, or if <var title="">node</var> is no longer in
the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> (e.g. because it got
removed by the next step), the element that was immediately
above <var title="">node</var> in the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> before <var title="">node</var> was
removed.</li>
<li>If <var title="">node</var> is not in the <a href="parsing.html#list-of-active-formatting-elements">list of
active formatting elements</a>, then remove <var title="">node</var> from the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> and then go back to the step labeled <i>inner
loop</i>.</li>
<li>Otherwise, if <var title="">node</var> is the <var title="">formatting element</var>, then go to the next step
in the overall algorithm.</li>
<li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
element <var title="">node</var> was created, replace the entry
for <var title="">node</var> in the <a href="parsing.html#list-of-active-formatting-elements">list of active
formatting elements</a> with an entry for the new element,
replace the entry for <var title="">node</var> in the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a> with an entry for the new
element, and let <var title="">node</var> be the new
element.</li>
<li>If <var title="">last node</var> is the <var title="">furthest block</var>, then move the aforementioned
bookmark to be immediately after the new <var title="">node</var> in the <a href="parsing.html#list-of-active-formatting-elements">list of active formatting
elements</a>.</li>
<li>Insert <var title="">last node</var> into <var title="">node</var>, first removing it from its previous
parent node if any.</li>
<li>Let <var title="">last node</var> be <var title="">node</var>.</li>
<li>Return to the step labeled <i>inner loop</i>.</li>
</ol></li>
<li>
<p>If the <var title="">common ancestor</var> node is a
<code><a href="tabular-data.html#the-table-element">table</a></code>, <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>,
<code><a href="tabular-data.html#the-thead-element">thead</a></code>, or <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then,
<a href="#foster-parent">foster parent</a> whatever <var title="">last
node</var> ended up being in the previous step, first removing
it from its previous parent node if any.</p>
<p>Otherwise, append whatever <var title="">last node</var>
ended up being in the previous step to the <var title="">common
ancestor</var> node, first removing it from its previous parent
node if any.</p>
</li>
<li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
<var title="">formatting element</var> was created.</p></li>
<li><p>Take all of the child nodes of the <var title="">furthest
block</var> and append them to the element created in the last
step.</p></li>
<li><p>Append that new element to the <var title="">furthest
block</var>.</p></li>
<li><p>Remove the <var title="">formatting element</var> from the
<a href="parsing.html#list-of-active-formatting-elements">list of active formatting elements</a>, and insert the
new element into the <a href="parsing.html#list-of-active-formatting-elements">list of active formatting
elements</a> at the position of the aforementioned
bookmark.</p></li>
<li><p>Remove the <var title="">formatting element</var> from the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>, and insert the new element
into the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> immediately below
the position of the <var title="">furthest block</var> in that
stack.</p></li>
<li><p>Jump back to the step labeled <i>outer loop</i>.</p></li>
</ol><p class="note">Because of the way this algorithm causes elements
to change parents, it has been dubbed the "adoption agency
algorithm" (in contrast with other possible algorithms for dealing
with misnested content, which included the "incest algorithm", the
"secret affair algorithm", and the "Heisenberg algorithm").</p>
</dd>
<dt>A start tag token whose tag name is one of: "applet",
"marquee", "object"</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Insert a marker at the end of the <a href="parsing.html#list-of-active-formatting-elements">list of active
formatting elements</a>.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
</dd>
<dt>An end tag token whose tag name is one of: "applet",
"marquee", "object"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-scope" title="has an element in scope">have an element in scope</a>
with the same tag name as that of the token, then this is a
<a href="parsing.html#parse-error">parse error</a>; ignore the token.</p>
<p>Otherwise, run these steps:</p>
<ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
<li><p>If the <a href="parsing.html#current-node">current node</a> is not an element with
the same tag name as that of the token, then this is a
<a href="parsing.html#parse-error">parse error</a>.</p></li>
<li><p>Pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>
until an element with the same tag name as the token has been
popped from the stack.</p></li>
<li><a href="parsing.html#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to the
last marker</a>.</li>
</ol></dd>
<dt>A start tag whose tag name is "table"</dt>
<dd>
<p>If the <code><a href="infrastructure.html#document">Document</a></code> is <em>not</em> set to
<a href="dom.html#quirks-mode">quirks mode</a>, and the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has an element in button scope">has a
<code>p</code> element in button scope</a>, then act as if an
end tag with the tag name "p" had been seen.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
</dd>
<dt>A start tag whose tag name is one of: "area", "br", "embed",
"img", "keygen", "wbr"</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p><a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
token's <i>self-closing flag</i></a>, if it is set.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
</dd>
<dt>A start tag whose tag name is "input"</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p><a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
token's <i>self-closing flag</i></a>, if it is set.</p>
<p>If the token does not have an attribute with the name "type",
or if it does, but that attribute's value is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
case-insensitive</a> match for the string "<code title="">hidden</code>", then: set the <a href="parsing.html#frameset-ok-flag">frameset-ok
flag</a> to "not ok".</p>
</dd>
<dt>A start tag whose tag name is one of: "param", "source", "track"</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p><a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
token's <i>self-closing flag</i></a>, if it is set.</p>
</dd>
<dt>A start tag whose tag name is "hr"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has
an element in button scope">has a <code>p</code> element in button
scope</a>, then act as if an end tag with the tag name
"p" had been seen.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p><a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
token's <i>self-closing flag</i></a>, if it is set.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
</dd>
<dt>A start tag whose tag name is "image"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Change the token's tag name
to "img" and reprocess it. (Don't ask.)</p> </dd>
<dt id="isindex">A start tag whose tag name is "isindex"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p>If the <a href="parsing.html#form-element-pointer"><code title="">form</code> element
pointer</a> is not null, then ignore the token.</p>
<p>Otherwise:</p>
<p><a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
token's <i>self-closing flag</i></a>, if it is set.</p>
<p>Act as if a start tag token with the tag name "form" had been seen.</p>
<p>If the token has an attribute called "action", set the
<code title="attr-fs-action"><a href="association-of-controls-and-forms.html#attr-fs-action">action</a></code> attribute on the
resulting <code><a href="forms.html#the-form-element">form</a></code> element to the value of the
"action" attribute of the token.</p>
<p>Act as if a start tag token with the tag name "hr" had been
seen.</p>
<p>Act as if a start tag token with the tag name "label" had been
seen.</p>
<p>Act as if a stream of character tokens had been seen (see below
for what they should say).</p>
<p>Act as if a start tag token with the tag name "input" had been
seen, with all the attributes from the "isindex" token except
"name", "action", and "prompt". Set the <code title="attr-fe-name"><a href="association-of-controls-and-forms.html#attr-fe-name">name</a></code> attribute of the resulting
<code><a href="the-input-element.html#the-input-element">input</a></code> element to the value "<code title="attr-fe-name-isindex"><a href="association-of-controls-and-forms.html#attr-fe-name-isindex">isindex</a></code>".</p>
<p>Act as if a stream of character tokens had been seen (see
below for what they should say).</p>
<p>Act as if an end tag token with the tag name "label" had been
seen.</p>
<p>Act as if a start tag token with the tag name "hr" had been
seen.</p>
<p>Act as if an end tag token with the tag name "form" had been
seen.</p>
<p>If the token has an attribute with the name "prompt", then the
first stream of characters must be the same string as given in
that attribute, and the second stream of characters must be
empty. Otherwise, the two streams of character tokens together
should, together with the <code><a href="the-input-element.html#the-input-element">input</a></code> element, express the
equivalent of "This is a searchable index. Enter search keywords:
(input field)" in the user's preferred language.</p>
</dd>
<dt>A start tag whose tag name is "textarea"</dt>
<dd>
<p>Run these steps:</p>
<ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
token.</p></li>
<li><p>If the next token is a U+000A LINE FEED (LF) character
token, then ignore that token and move on to the next
one. (Newlines at the start of <code><a href="the-button-element.html#the-textarea-element">textarea</a></code> elements are
ignored as an authoring convenience.)</p></li>
<li><p>Switch the tokenizer to the <a href="tokenization.html#rcdata-state">RCDATA
state</a>.</p></li>
<li><p>Let the <a href="parsing.html#original-insertion-mode">original insertion mode</a> be the
current <a href="parsing.html#insertion-mode">insertion mode</a>.</p>
</li><li><p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not
ok".</p></li>
<li><p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: text">text</a>".</p></li>
</ol></dd>
<dt>A start tag whose tag name is "xmp"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has
an element in button scope">has a <code>p</code> element in button
scope</a>, then act as if an end tag with the tag name
"p" had been seen.</p>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
<p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
</dd>
<dt>A start tag whose tag name is "iframe"</dt>
<dd>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
<p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
</dd>
<dt>A start tag whose tag name is "noembed"</dt>
<dt>A start tag whose tag name is "noscript", if the <a href="parsing.html#scripting-flag">scripting flag</a> is enabled</dt>
<dd>
<p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
</dd>
<dt>A start tag whose tag name is "select"</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
<p>If the <a href="parsing.html#insertion-mode">insertion mode</a> is one of "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>", "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>", "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table body</a>",
"<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>", or "<a href="#parsing-main-intd" title="insertion mode: in cell">in cell</a>", then switch the
<a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inselectintable" title="insertion mode: in
select in table">in select in table</a>". Otherwise, switch the
<a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inselect" title="insertion mode: in
select">in select</a>".</p>
</dd>
<dt>A start tag whose tag name is one of: "optgroup", "option"</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is an <code><a href="the-button-element.html#the-option-element">option</a></code>
element, then act as if an end tag with the tag name "option" had
been seen.</p>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
</dd>
<dt>A start tag whose tag name is one of: "rp", "rt"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-scope" title="has an
element in scope">has a <code>ruby</code> element in scope</a>,
then <a href="#generate-implied-end-tags">generate implied end tags</a>. If the <a href="parsing.html#current-node">current
node</a> is not then a <code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element, this is a
<a href="parsing.html#parse-error">parse error</a>; pop all the nodes from the <a href="parsing.html#current-node">current
node</a> up to the node immediately before the bottommost
<code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element on the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
</dd>
<dt>An end tag whose tag name is "br"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Act as if a start tag token with
the tag name "br" had been seen. Ignore the end tag token.</p>
</dd>
<dt>A start tag whose tag name is "math"</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#adjust-mathml-attributes">Adjust MathML attributes</a> for the token. (This
fixes the case of MathML attributes that are not all
lowercase.)</p>
<p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
fixes the use of namespaced attributes, in particular XLink.)</p>
<p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
<a href="namespaces.html#mathml-namespace">MathML namespace</a>.</p>
<p>If the token has its <i>self-closing flag</i> set, pop the
<a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> and <a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing
flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
</dd>
<dt>A start tag whose tag name is "svg"</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#adjust-svg-attributes">Adjust SVG attributes</a> for the token. (This fixes
the case of SVG attributes that are not all lowercase.)</p>
<p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
fixes the use of namespaced attributes, in particular XLink in
SVG.)</p>
<p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
<a href="namespaces.html#svg-namespace">SVG namespace</a>.</p>
<p>If the token has its <i>self-closing flag</i> set, pop the
<a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> and <a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing
flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
</dd>
<dt>A start tag whose tag name is one of: "caption",
"col", "colgroup", "frame", "head", "tbody", "td", "tfoot", "th",
"thead", "tr"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Any other start tag</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p class="note">This element will be an <a href="parsing.html#ordinary">ordinary</a>
element.</p>
</dd>
<dt>Any other end tag</dt>
<dd>
<p>Run these steps:</p>
<ol><li><p>Initialize <var title="">node</var> to be the <a href="parsing.html#current-node">current
node</a> (the bottommost node of the stack).</p></li>
<li><p><i>Loop</i>: If <var title="">node</var> has the same tag
name as the token, then:</p>
<ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
for elements with the same tag name as the token.</p></li>
<li><p>If the tag name of the end tag token does not match
the tag name of the <a href="parsing.html#current-node">current node</a>, this is a
<a href="parsing.html#parse-error">parse error</a>.</p></li>
<li><p>Pop all the nodes from the <a href="parsing.html#current-node">current node</a> up
to <var title="">node</var>, including <var title="">node</var>, then stop these steps.</p></li>
</ol></li>
<li><p>Otherwise, if <var title="">node</var> is in the
<a href="parsing.html#special">special</a> category, then this is a <a href="parsing.html#parse-error">parse
error</a>; ignore the token, and abort these steps.</p></li>
<li><p>Set <var title="">node</var> to the previous entry in the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p></li>
<li><p>Return to the step labeled <i>loop</i>.</p></li>
</ol></dd>
</dl><h6 id="parsing-main-incdata"><span class="secno">8.2.5.4.8 </span>The "<dfn title="insertion mode: text">text</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-incdata" title="insertion mode: text">text</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token</dt>
<dd>
<p><a href="#insert-a-character" title="insert a character">Insert the token's
character</a> into the <a href="parsing.html#current-node">current node</a>.</p>
<p class="note">This can never be a U+0000 NULL character; the
tokenizer converts those to U+FFFD REPLACEMENT CHARACTER
characters.</p>
</dd>
<dt>An end-of-file token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p>If the <a href="parsing.html#current-node">current node</a> is a <code><a href="scripting-1.html#the-script-element">script</a></code>
element, mark the <code><a href="scripting-1.html#the-script-element">script</a></code> element as <a href="scripting-1.html#already-started">"already
started"</a>.</p>
<p>Pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to the <a href="parsing.html#original-insertion-mode">original
insertion mode</a> and reprocess the current token.</p>
</dd>
<dt id="scriptEndTag">An end tag whose tag name is "script"</dt>
<dd>
<p><a href="webappapis.html#provide-a-stable-state">Provide a stable state</a>.</p>
<p>Let <var title="">script</var> be the <a href="parsing.html#current-node">current node</a>
(which will be a <code><a href="scripting-1.html#the-script-element">script</a></code> element).</p>
<p>Pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to the <a href="parsing.html#original-insertion-mode">original
insertion mode</a>.</p>
<p>Let the <var title="">old insertion point</var> have the
same value as the current <a href="parsing.html#insertion-point">insertion point</a>. Let
the <a href="parsing.html#insertion-point">insertion point</a> be just before the <a href="parsing.html#next-input-character">next
input character</a>.</p>
<p>Increment the parser's <a href="parsing.html#script-nesting-level">script nesting level</a> by
one.</p>
<p><a href="scripting-1.html#prepare-a-script" title="prepare a script">Prepare</a> the <var title="">script</var>. This might cause some script to execute,
which might cause <a href="apis-in-html-documents.html#dom-document-write" title="dom-document-write">new characters
to be inserted into the tokenizer</a>, and might cause the
tokenizer to output more tokens, resulting in a <a href="parsing.html#nestedParsing">reentrant invocation of the parser</a>.</p>
<p>Decrement the parser's <a href="parsing.html#script-nesting-level">script nesting level</a> by
one. If the parser's <a href="parsing.html#script-nesting-level">script nesting level</a> is zero,
then set the <a href="parsing.html#parser-pause-flag">parser pause flag</a> to false.</p>
<p>Let the <a href="parsing.html#insertion-point">insertion point</a> have the value of the <var title="">old insertion point</var>. (In other words, restore the
<a href="parsing.html#insertion-point">insertion point</a> to its previous value. This value
might be the "undefined" value.)</p>
<p id="scriptTagParserResumes">At this stage, if there is a
<a href="scripting-1.html#pending-parsing-blocking-script">pending parsing-blocking script</a>, then:</p>
<dl class="switch"><dt>If the <a href="parsing.html#script-nesting-level">script nesting level</a> is not zero:</dt>
<dd>
<p>Set the <a href="parsing.html#parser-pause-flag">parser pause flag</a> to true, and abort the
processing of any nested invocations of the tokenizer, yielding
control back to the caller. (Tokenization will resume when the
caller returns to the "outer" tree construction stage.)</p>
<p class="note">The tree construction stage of this particular
parser is <a href="parsing.html#nestedParsing">being called reentrantly</a>,
say from a call to <code title="dom-document-write"><a href="apis-in-html-documents.html#dom-document-write">document.write()</a></code>.</p>
</dd>
<dt>Otherwise:</dt>
<dd>
<p>Run these steps:</p>
<ol><li><p>Let <var title="">the script</var> be the <a href="scripting-1.html#pending-parsing-blocking-script">pending
parsing-blocking script</a>. There is no longer a <a href="scripting-1.html#pending-parsing-blocking-script">pending
parsing-blocking script</a>.</p></li>
<li><p>Block the <a href="tokenization.html#tokenization" title="tokenization">tokenizer</a>
for this instance of the <a href="parsing.html#html-parser">HTML parser</a>, such that
the <a href="webappapis.html#event-loop">event loop</a> will not run <a href="webappapis.html#concept-task" title="concept-task">tasks</a> that invoke the <a href="tokenization.html#tokenization" title="tokenization">tokenizer</a>.</p></li>
<li><p>If the parser's <code><a href="infrastructure.html#document">Document</a></code> <a href="semantics.html#has-a-style-sheet-that-is-blocking-scripts">has a style
sheet that is blocking scripts</a> or <var title="">the
script</var>'s <a href="scripting-1.html#ready-to-be-parser-executed">"ready to be parser-executed"</a> flag
is not set: <a href="webappapis.html#spin-the-event-loop">spin the event loop</a> until the parser's
<code><a href="infrastructure.html#document">Document</a></code> <a href="semantics.html#has-no-style-sheet-that-is-blocking-scripts">has no style sheet that is blocking
scripts</a> and <var title="">the script</var>'s
<a href="scripting-1.html#ready-to-be-parser-executed">"ready to be parser-executed"</a> flag is
set.</p></li>
<li><p>Unblock the <a href="tokenization.html#tokenization" title="tokenization">tokenizer</a>
for this instance of the <a href="parsing.html#html-parser">HTML parser</a>, such that
<a href="webappapis.html#concept-task" title="concept-task">tasks</a> that invoke the <a href="tokenization.html#tokenization" title="tokenization">tokenizer</a> can again be
run.</p></li>
<li><p>Let the <a href="parsing.html#insertion-point">insertion point</a> be just before the
<a href="parsing.html#next-input-character">next input character</a>.</p></li>
<li><p>Increment the parser's <a href="parsing.html#script-nesting-level">script nesting level</a>
by one (it should be zero before this step, so this sets it to
one).</p></li>
<li><p><a href="scripting-1.html#execute-the-script-block" title="execute the script block">Execute</a>
<var title="">the script</var>.</p></li>
<li><p>Decrement the parser's <a href="parsing.html#script-nesting-level">script nesting level</a>
by one. If the parser's <a href="parsing.html#script-nesting-level">script nesting level</a> is
zero (which it always should be at this point), then set the
<a href="parsing.html#parser-pause-flag">parser pause flag</a> to false.</p>
</li><li><p>Let the <a href="parsing.html#insertion-point">insertion point</a> be undefined
again.</p></li>
<li><p>If there is once again a <a href="scripting-1.html#pending-parsing-blocking-script">pending parsing-blocking
script</a>, then repeat these steps from step 1.</p></li>
</ol></dd>
</dl></dd>
<dt>Any other end tag</dt>
<dd>
<p>Pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to the <a href="parsing.html#original-insertion-mode">original
insertion mode</a>.</p>
</dd>
</dl><h6 id="parsing-main-intable"><span class="secno">8.2.5.4.9 </span>The "<dfn title="insertion mode: in table">in table</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token</dt>
<dd>
<p>Let the <dfn id="pending-table-character-tokens"><var>pending table character tokens</var></dfn>
be an empty list of tokens.</p>
<p>Let the <a href="parsing.html#original-insertion-mode">original insertion mode</a> be the current
<a href="parsing.html#insertion-mode">insertion mode</a>.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table text</a>" and
reprocess the token.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "caption"</dt>
<dd>
<p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
below.)</p>
<p>Insert a marker at the end of the <a href="parsing.html#list-of-active-formatting-elements">list of active
formatting elements</a>.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>".</p>
</dd>
<dt>A start tag whose tag name is "colgroup"</dt>
<dd>
<p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
below.)</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column
group</a>".</p>
</dd>
<dt>A start tag whose tag name is "col"</dt>
<dd>
<p>Act as if a start tag token with the tag name "colgroup"
had been seen, then reprocess the current token.</p>
</dd>
<dt>A start tag whose tag name is one of: "tbody", "tfoot", "thead"</dt>
<dd>
<p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
below.)</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
body</a>".</p>
</dd>
<dt>A start tag whose tag name is one of: "td", "th", "tr"</dt>
<dd>
<p>Act as if a start tag token with the tag name "tbody" had
been seen, then reprocess the current token.</p>
</dd>
<dt>A start tag whose tag name is "table"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Act as if an end tag token with
the tag name "table" had been seen, then, if that token wasn't
ignored, reprocess the current token.</p>
<p class="note">The fake end tag token here can only be
ignored in the <a href="the-end.html#fragment-case">fragment case</a>.</p>
</dd>
<dt>An end tag whose tag name is "table"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
scope</a> with the same tag name as the token, this is a
<a href="parsing.html#parse-error">parse error</a>. Ignore the token. (<a href="the-end.html#fragment-case">fragment
case</a>)</p>
<p>Otherwise:</p>
<p>Pop elements from this stack until a <code><a href="tabular-data.html#the-table-element">table</a></code>
element has been popped from the stack.</p>
<p><a href="parsing.html#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
</dd>
<dt>An end tag whose tag name is one of: "body", "caption",
"col", "colgroup", "html", "tbody", "td", "tfoot", "th",
"thead", "tr"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is one of: "style", "script"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>A start tag whose tag name is "input"</dt>
<dd>
<p>If the token does not have an attribute with the name "type",
or if it does, but that attribute's value is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
case-insensitive</a> match for the string "<code title="">hidden</code>", then: act as described in the "anything
else" entry below.</p>
<p>Otherwise:</p>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Pop that <code><a href="the-input-element.html#the-input-element">input</a></code> element off the <a href="parsing.html#stack-of-open-elements">stack of
open elements</a>.</p>
</dd>
<dt>A start tag whose tag name is "form"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p>If the <a href="parsing.html#form-element-pointer"><code title="form">form</code> element
pointer</a> is not null, ignore the token.</p>
<p>Otherwise:</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, and set the
<a href="parsing.html#form-element-pointer"><code title="form">form</code> element pointer</a> to
point to the element created.</p>
<p>Pop that <code><a href="forms.html#the-form-element">form</a></code> element off the <a href="parsing.html#stack-of-open-elements">stack of
open elements</a>.</p>
</dd>
<dt>An end-of-file token</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is not the root
<code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="parsing.html#parse-error">parse
error</a>.</p>
<p class="note">It can only be the <a href="parsing.html#current-node">current node</a> in
the <a href="the-end.html#fragment-case">fragment case</a>.</p>
<p><a href="the-end.html#stop-parsing">Stop parsing</a>.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Process the token <a href="parsing.html#using-the-rules-for">using the
rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
body</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, except that if the
<a href="parsing.html#current-node">current node</a> is a <code><a href="tabular-data.html#the-table-element">table</a></code>,
<code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, or
<code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then, whenever a node would be inserted
into the <a href="parsing.html#current-node">current node</a>, it must instead be <a href="#foster-parent" title="foster parent">foster parented</a>.</p>
</dd>
</dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-context">clear the stack
back to a table context</dfn>, it means that the UA must, while
the <a href="parsing.html#current-node">current node</a> is not a <code><a href="tabular-data.html#the-table-element">table</a></code>
element or an <code><a href="semantics.html#the-html-element">html</a></code> element, pop elements from the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p>
<p class="note">The <a href="parsing.html#current-node">current node</a> being an
<code><a href="semantics.html#the-html-element">html</a></code> element after this process is a <a href="the-end.html#fragment-case">fragment
case</a>.</p>
<h6 id="parsing-main-intabletext"><span class="secno">8.2.5.4.10 </span>The "<dfn title="insertion mode: in table text">in table text</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table text</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is U+0000 NULL</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Any other character token</dt>
<dd>
<p>Append the character token to the <var><a href="#pending-table-character-tokens">pending table character
tokens</a></var> list.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>If any of the tokens in the <var><a href="#pending-table-character-tokens">pending table character
tokens</a></var> list are character tokens that are not one of U+0009
CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED
(FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE, then reprocess
those character tokens using the rules given in the "anything
else" entry in the <a href="#parsing-main-intable" title="insertion mode: in table">in
table</a>" insertion mode.</p>
<p>Otherwise, <a href="#insert-a-character" title="insert a character">insert the
characters</a> given by the <var><a href="#pending-table-character-tokens">pending table character
tokens</a></var> list into the <a href="parsing.html#current-node">current node</a>.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to the <a href="parsing.html#original-insertion-mode">original
insertion mode</a> and reprocess the token.</p>
</dd>
</dl><h6 id="parsing-main-incaption"><span class="secno">8.2.5.4.11 </span>The "<dfn title="insertion mode: in caption">in caption</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>An end tag whose tag name is "caption"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
scope</a> with the same tag name as the token, this is a
<a href="parsing.html#parse-error">parse error</a>. Ignore the token. (<a href="the-end.html#fragment-case">fragment
case</a>)</p>
<p>Otherwise:</p>
<p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
<p>Now, if the <a href="parsing.html#current-node">current node</a> is not a
<code><a href="tabular-data.html#the-caption-element">caption</a></code> element, then this is a <a href="parsing.html#parse-error">parse
error</a>.</p>
<p>Pop elements from this stack until a <code><a href="tabular-data.html#the-caption-element">caption</a></code>
element has been popped from the stack.</p>
<p><a href="parsing.html#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
the last marker</a>.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
</dd>
<dt>A start tag whose tag name is one of: "caption", "col",
"colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
<dt>An end tag whose tag name is "table"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Act as if an end tag with the tag
name "caption" had been seen, then, if that token wasn't
ignored, reprocess the current token.</p>
<p class="note">The fake end tag token here can only be
ignored in the <a href="the-end.html#fragment-case">fragment case</a>.</p>
</dd>
<dt>An end tag whose tag name is one of: "body", "col",
"colgroup", "html", "tbody", "td", "tfoot", "th", "thead",
"tr"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
</dl><h6 id="parsing-main-incolgroup"><span class="secno">8.2.5.4.12 </span>The "<dfn title="insertion mode: in column group">in column group</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column group</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
the <a href="parsing.html#current-node">current node</a>.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>A start tag whose tag name is "col"</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p><a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
token's <i>self-closing flag</i></a>, if it is set.</p>
</dd>
<dt>An end tag whose tag name is "colgroup"</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is the root
<code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="parsing.html#parse-error">parse
error</a>; ignore the token. (<a href="the-end.html#fragment-case">fragment
case</a>)</p>
<p>Otherwise, pop the <a href="parsing.html#current-node">current node</a> (which will be
a <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element) from the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>. Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to
"<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
</dd>
<dt>An end tag whose tag name is "col"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>An end-of-file token</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is the root <code><a href="semantics.html#the-html-element">html</a></code>
element, then <a href="the-end.html#stop-parsing">stop parsing</a>. (<a href="the-end.html#fragment-case">fragment
case</a>)</p>
<p>Otherwise, act as described in the "anything else" entry
below.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Act as if an end tag with the tag name "colgroup" had been
seen, and then, if that token wasn't ignored, reprocess the
current token.</p>
<p class="note">The fake end tag token here can only be
ignored in the <a href="the-end.html#fragment-case">fragment case</a>.</p>
</dd>
</dl><h6 id="parsing-main-intbody"><span class="secno">8.2.5.4.13 </span>The "<dfn title="insertion mode: in table body">in table body</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table body</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A start tag whose tag name is "tr"</dt>
<dd>
<p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
context</a>. (See below.)</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode:
in row">in row</a>".</p>
</dd>
<dt>A start tag whose tag name is one of: "th", "td"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Act as if a start tag with
the tag name "tr" had been seen, then reprocess the current
token.</p>
</dd>
<dt>An end tag whose tag name is one of: "tbody", "tfoot",
"thead"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
scope</a> with the same tag name as the token, this is a
<a href="parsing.html#parse-error">parse error</a>. Ignore the token.</p>
<p>Otherwise:</p>
<p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
context</a>. (See below.)</p>
<p>Pop the <a href="parsing.html#current-node">current node</a> from the <a href="parsing.html#stack-of-open-elements">stack of
open elements</a>. Switch the <a href="parsing.html#insertion-mode">insertion mode</a>
to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
</dd>
<dt>A start tag whose tag name is one of: "caption", "col",
"colgroup", "tbody", "tfoot", "thead"</dt>
<dt>An end tag whose tag name is "table"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have a
<code>tbody</code>, <code>thead</code>, or <code>tfoot</code>
element in table scope</a>, this is a <a href="parsing.html#parse-error">parse
error</a>. Ignore the token. (<a href="the-end.html#fragment-case">fragment
case</a>)</p>
<p>Otherwise:</p>
<p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
context</a>. (See below.)</p>
<p>Act as if an end tag with the same tag name as the
<a href="parsing.html#current-node">current node</a> ("tbody", "tfoot", or "thead") had
been seen, then reprocess the current token.</p>
</dd>
<dt>An end tag whose tag name is one of: "body", "caption",
"col", "colgroup", "html", "td", "th", "tr"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
</dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-body-context">clear the stack
back to a table body context</dfn>, it means that the UA must,
while the <a href="parsing.html#current-node">current node</a> is not a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
<code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, or <code><a href="semantics.html#the-html-element">html</a></code>
element, pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p class="note">The <a href="parsing.html#current-node">current node</a> being an
<code><a href="semantics.html#the-html-element">html</a></code> element after this process is a <a href="the-end.html#fragment-case">fragment
case</a>.</p>
<h6 id="parsing-main-intr"><span class="secno">8.2.5.4.14 </span>The "<dfn title="insertion mode: in row">in row</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A start tag whose tag name is one of: "th", "td"</dt>
<dd>
<p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
context</a>. (See below.)</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion mode:
in cell">in cell</a>".</p>
<p>Insert a marker at the end of the <a href="parsing.html#list-of-active-formatting-elements">list of active
formatting elements</a>.</p>
</dd>
<dt>An end tag whose tag name is "tr"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
scope</a> with the same tag name as the token, this is a
<a href="parsing.html#parse-error">parse error</a>. Ignore the token. (<a href="the-end.html#fragment-case">fragment
case</a>)</p>
<p>Otherwise:</p>
<p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
context</a>. (See below.)</p>
<p>Pop the <a href="parsing.html#current-node">current node</a> (which will be a
<code><a href="tabular-data.html#the-tr-element">tr</a></code> element) from the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>. Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to
"<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
body</a>".</p>
</dd>
<dt>A start tag whose tag name is one of: "caption", "col",
"colgroup", "tbody", "tfoot", "thead", "tr"</dt>
<dt>An end tag whose tag name is "table"</dt>
<dd>
<p>Act as if an end tag with the tag name "tr" had been seen,
then, if that token wasn't ignored, reprocess the current
token.</p>
<p class="note">The fake end tag token here can only be
ignored in the <a href="the-end.html#fragment-case">fragment case</a>.</p>
</dd>
<dt>An end tag whose tag name is one of: "tbody", "tfoot",
"thead"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
scope</a> with the same tag name as the token, this is a
<a href="parsing.html#parse-error">parse error</a>. Ignore the token.</p>
<p>Otherwise, act as if an end tag with the tag name "tr" had
been seen, then reprocess the current token.</p>
</dd>
<dt>An end tag whose tag name is one of: "body", "caption",
"col", "colgroup", "html", "td", "th"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
</dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-row-context">clear the stack
back to a table row context</dfn>, it means that the UA must,
while the <a href="parsing.html#current-node">current node</a> is not a <code><a href="tabular-data.html#the-tr-element">tr</a></code>
element or an <code><a href="semantics.html#the-html-element">html</a></code> element, pop elements from the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p>
<p class="note">The <a href="parsing.html#current-node">current node</a> being an
<code><a href="semantics.html#the-html-element">html</a></code> element after this process is a <a href="the-end.html#fragment-case">fragment
case</a>.</p>
<h6 id="parsing-main-intd"><span class="secno">8.2.5.4.15 </span>The "<dfn title="insertion mode: in cell">in cell</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-intd" title="insertion mode: in cell">in cell</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>An end tag whose tag name is one of: "td", "th"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
scope</a> with the same tag name as that of the token, then
this is a <a href="parsing.html#parse-error">parse error</a> and the token must be
ignored.</p>
<p>Otherwise:</p>
<p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
<p>Now, if the <a href="parsing.html#current-node">current node</a> is not an element
with the same tag name as the token, then this is a
<a href="parsing.html#parse-error">parse error</a>.</p>
<p>Pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> stack
until an element with the same tag name as the token has been
popped from the stack.</p>
<p><a href="parsing.html#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
the last marker</a>.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>".</p>
</dd>
<dt>A start tag whose tag name is one of: "caption", "col",
"colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does
<em>not</em> <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have
a <code>td</code> or <code>th</code> element in table
scope</a>, then this is a <a href="parsing.html#parse-error">parse error</a>; ignore
the token. (<a href="the-end.html#fragment-case">fragment case</a>)</p>
<p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
reprocess the current token.</p>
</dd>
<dt>An end tag whose tag name is one of: "body", "caption",
"col", "colgroup", "html"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>An end tag whose tag name is one of: "table", "tbody",
"tfoot", "thead", "tr"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
scope</a> with the same tag name as that of the token (which
can only happen for "tbody", "tfoot" and "thead", or in the
<a href="the-end.html#fragment-case">fragment case</a>), then this is a <a href="parsing.html#parse-error">parse
error</a> and the token must be ignored.</p>
<p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
reprocess the current token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
</dl><p>Where the steps above say to <dfn id="close-the-cell">close the cell</dfn>, they
mean to run the following algorithm:</p>
<ol><li><p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">has a <code>td</code>
element in table scope</a>, then act as if an end tag token
with the tag name "td" had been seen.</p></li>
<li><p>Otherwise, the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> will
<a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have a
<code>th</code> element in table scope</a>; act as if an end
tag token with the tag name "th" had been seen.</p></li>
</ol><p class="note">The <a href="parsing.html#stack-of-open-elements">stack of open elements</a> cannot have
both a <code><a href="tabular-data.html#the-td-element">td</a></code> and a <code><a href="tabular-data.html#the-th-element">th</a></code> element <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">in table scope</a> at the
same time, nor can it have neither when the <a href="#close-the-cell">close the
cell</a> algorithm is invoked.</p>
<h6 id="parsing-main-inselect"><span class="secno">8.2.5.4.16 </span>The "<dfn title="insertion mode: in select">in select</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is U+0000 NULL</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Any other character token</dt>
<dd>
<p><a href="#insert-a-character" title="insert a character">Insert the token's
character</a> into the <a href="parsing.html#current-node">current node</a>.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>A start tag whose tag name is "option"</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is an <code><a href="the-button-element.html#the-option-element">option</a></code>
element, act as if an end tag with the tag name "option" had
been seen.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
</dd>
<dt>A start tag whose tag name is "optgroup"</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is an <code><a href="the-button-element.html#the-option-element">option</a></code>
element, act as if an end tag with the tag name "option" had
been seen.</p>
<p>If the <a href="parsing.html#current-node">current node</a> is an
<code><a href="the-button-element.html#the-optgroup-element">optgroup</a></code> element, act as if an end tag with the
tag name "optgroup" had been seen.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
</dd>
<dt>An end tag whose tag name is "optgroup"</dt>
<dd>
<p>First, if the <a href="parsing.html#current-node">current node</a> is an
<code><a href="the-button-element.html#the-option-element">option</a></code> element, and the node immediately before
it in the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> is an
<code><a href="the-button-element.html#the-optgroup-element">optgroup</a></code> element, then act as if an end tag with
the tag name "option" had been seen.</p>
<p>If the <a href="parsing.html#current-node">current node</a> is an
<code><a href="the-button-element.html#the-optgroup-element">optgroup</a></code> element, then pop that node from the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>. Otherwise, this is a
<a href="parsing.html#parse-error">parse error</a>; ignore the token.</p>
</dd>
<dt>An end tag whose tag name is "option"</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is an <code><a href="the-button-element.html#the-option-element">option</a></code>
element, then pop that node from the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>. Otherwise, this is a <a href="parsing.html#parse-error">parse
error</a>; ignore the token.</p>
</dd>
<dt>An end tag whose tag name is "select"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-select-scope" title="has an element in select scope">have an element in select
scope</a> with the same tag name as the token, this is a
<a href="parsing.html#parse-error">parse error</a>. Ignore the token. (<a href="the-end.html#fragment-case">fragment
case</a>)</p>
<p>Otherwise:</p>
<p>Pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>
until a <code><a href="the-button-element.html#the-select-element">select</a></code> element has been popped from the
stack.</p>
<p><a href="parsing.html#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
</dd>
<dt>A start tag whose tag name is "select"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Act as if the token had been
an end tag with the tag name "select" instead.</p>
</dd>
<dt>A start tag whose tag name is one of: "input", "keygen", "textarea"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-select-scope" title="has an element in select scope">have a <code>select</code>
element in select scope</a>, ignore the token. (<a href="the-end.html#fragment-case">fragment
case</a>)</p>
<p>Otherwise, act as if an end tag with the tag name "select" had
been seen, and reprocess the token.</p>
</dd>
<dt>A start tag token whose tag name is "script"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>An end-of-file token</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is not the root
<code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="parsing.html#parse-error">parse
error</a>.</p>
<p class="note">It can only be the <a href="parsing.html#current-node">current node</a> in
the <a href="the-end.html#fragment-case">fragment case</a>.</p>
<p><a href="the-end.html#stop-parsing">Stop parsing</a>.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
</dl><h6 id="parsing-main-inselectintable"><span class="secno">8.2.5.4.17 </span>The "<dfn title="insertion mode: in select in table">in select in table</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-inselectintable" title="insertion mode: in select in table">in select in table</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A start tag whose tag name is one of: "caption", "table",
"tbody", "tfoot", "thead", "tr", "td", "th"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Act as if an end tag with the tag
name "select" had been seen, and reprocess the token.</p>
</dd>
<dt>An end tag whose tag name is one of: "caption", "table",
"tbody", "tfoot", "thead", "tr", "td", "th"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-table-scope">has an
element in table scope</a> with the same tag name as that
of the token, then act as if an end tag with the tag name
"select" had been seen, and reprocess the token. Otherwise,
ignore the token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
</dl><h6 id="parsing-main-afterbody"><span class="secno">8.2.5.4.18 </span>The "<dfn title="insertion mode: after body">after body</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-afterbody" title="insertion mode: after body">after body</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the first element in
the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> (the <code><a href="semantics.html#the-html-element">html</a></code>
element), with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>An end tag whose tag name is "html"</dt>
<dd>
<p>If the parser was originally created as part of the <a href="the-end.html#html-fragment-parsing-algorithm">HTML
fragment parsing algorithm</a>, this is a <a href="parsing.html#parse-error">parse
error</a>; ignore the token. (<a href="the-end.html#fragment-case">fragment case</a>)</p>
<p>Otherwise, switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#the-after-after-body-insertion-mode" title="insertion mode: after after body">after after
body</a>".</p>
</dd>
<dt>An end-of-file token</dt>
<dd>
<p><a href="the-end.html#stop-parsing">Stop parsing</a>.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Switch the <a href="parsing.html#insertion-mode">insertion
mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in
body</a>" and reprocess the token.</p>
</dd>
</dl><h6 id="parsing-main-inframeset"><span class="secno">8.2.5.4.19 </span>The "<dfn title="insertion mode: in frameset">in frameset</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-inframeset" title="insertion mode: in frameset">in frameset</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
the <a href="parsing.html#current-node">current node</a>.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>A start tag whose tag name is "frameset"</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
</dd>
<dt>An end tag whose tag name is "frameset"</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is the root
<code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="parsing.html#parse-error">parse
error</a>; ignore the token. (<a href="the-end.html#fragment-case">fragment
case</a>)</p>
<p>Otherwise, pop the <a href="parsing.html#current-node">current node</a> from the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p>
<p>If the parser was <em>not</em> originally created as part
of the <a href="the-end.html#html-fragment-parsing-algorithm">HTML fragment parsing algorithm</a>
(<a href="the-end.html#fragment-case">fragment case</a>), and the <a href="parsing.html#current-node">current
node</a> is no longer a <code><a href="obsolete.html#frameset">frameset</a></code> element, then
switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterframeset" title="insertion mode: after frameset">after
frameset</a>".</p>
</dd>
<dt>A start tag whose tag name is "frame"</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.
Immediately pop the <a href="parsing.html#current-node">current node</a> off the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p>
<p><a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
token's <i>self-closing flag</i></a>, if it is set.</p>
</dd>
<dt>A start tag whose tag name is "noframes"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>An end-of-file token</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is not the root
<code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="parsing.html#parse-error">parse
error</a>.</p>
<p class="note">It can only be the <a href="parsing.html#current-node">current node</a> in
the <a href="the-end.html#fragment-case">fragment case</a>.</p>
<p><a href="the-end.html#stop-parsing">Stop parsing</a>.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
</dl><h6 id="parsing-main-afterframeset"><span class="secno">8.2.5.4.20 </span>The "<dfn title="insertion mode: after frameset">after frameset</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-afterframeset" title="insertion mode: after frameset">after frameset</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
the <a href="parsing.html#current-node">current node</a>.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>An end tag whose tag name is "html"</dt>
<dd>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after
frameset</a>".</p>
</dd>
<dt>A start tag whose tag name is "noframes"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>An end-of-file token</dt>
<dd>
<p><a href="the-end.html#stop-parsing">Stop parsing</a>.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
</dl><h6 id="the-after-after-body-insertion-mode"><span class="secno">8.2.5.4.21 </span>The "<dfn title="insertion mode: after after body">after after body</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#the-after-after-body-insertion-mode" title="insertion mode: after after body">after after body</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <code><a href="infrastructure.html#document">Document</a></code>
object with the <code title="">data</code> attribute set to the
data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>An end-of-file token</dt>
<dd>
<p><a href="the-end.html#stop-parsing">Stop parsing</a>.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Switch the <a href="parsing.html#insertion-mode">insertion mode</a>
to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and
reprocess the token.</p>
</dd>
</dl><h6 id="the-after-after-frameset-insertion-mode"><span class="secno">8.2.5.4.22 </span>The "<dfn title="insertion mode: after after frameset">after after frameset</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after frameset</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <code><a href="infrastructure.html#document">Document</a></code>
object with the <code title="">data</code> attribute set to the
data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>An end-of-file token</dt>
<dd>
<p><a href="the-end.html#stop-parsing">Stop parsing</a>.</p>
</dd>
<dt>A start tag whose tag name is "noframes"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
</dl><h5 id="parsing-main-inforeign"><span class="secno">8.2.5.5 </span>The rules for parsing tokens <dfn title="insertion mode: in foreign content">in foreign content</dfn></h5>
<p>When the user agent is to apply the rules for parsing tokens in foreign content, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is U+0000 NULL</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. <a href="#insert-a-character" title="insert a
character">Insert a U+FFFD REPLACEMENT CHARACTER character</a>
into the <a href="parsing.html#current-node">current node</a>.</p>
</dd>
<dt>A character token that is one of U+0009 CHARACTER TABULATION,
U+000A LINE FEED (LF), U+000C FORM FEED (FF), U+000D CARRIAGE
RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p><a href="#insert-a-character" title="insert a character">Insert the token's
character</a> into the <a href="parsing.html#current-node">current node</a>.</p>
</dd>
<dt>Any other character token</dt>
<dd>
<p><a href="#insert-a-character" title="insert a character">Insert the token's
character</a> into the <a href="parsing.html#current-node">current node</a>.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is one of: "b", "big",
"blockquote", "body", "br", "center", "code",
"dd", "div", "dl", "dt", "em", "embed", "h1", "h2",
"h3", "h4", "h5", "h6", "head", "hr", "i", "img",
"li", "listing", "menu", "meta", "nobr",
"ol", "p", "pre", "ruby", "s", "small",
"span", "strong", "strike", "sub", "sup",
"table", "tt", "u", "ul", "var"</dt> <dt>A start tag whose tag name is "font", if the token has any
attributes named "color", "face", or "size"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p>Pop an element from the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>,
and then keep popping more elements from the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> until the <a href="parsing.html#current-node">current node</a> is a
<a href="#mathml-text-integration-point">MathML text integration point</a>, an <a href="#html-integration-point">HTML
integration point</a>, or an element in the <a href="namespaces.html#html-namespace-0">HTML
namespace</a>.</p>
<p>Then, reprocess the token.</p>
</dd>
<dt>Any other start tag</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is an element in the
<a href="namespaces.html#mathml-namespace">MathML namespace</a>, <a href="#adjust-mathml-attributes">adjust MathML
attributes</a> for the token. (This fixes the case of MathML
attributes that are not all lowercase.)</p>
<p>If the <a href="parsing.html#current-node">current node</a> is an element in the <a href="namespaces.html#svg-namespace">SVG
namespace</a>, and the token's tag name is one of the ones in
the first column of the following table, change the tag name to
the name given in the corresponding cell in the second
column. (This fixes the case of SVG elements that are not all
lowercase.)</p>
<table><thead><tr><th> Tag name </th><th> Element name
</th></tr></thead><tbody><tr><td> <code title="">altglyph</code> </td><td> <code title="">altGlyph</code>
</td></tr><tr><td> <code title="">altglyphdef</code> </td><td> <code title="">altGlyphDef</code>
</td></tr><tr><td> <code title="">altglyphitem</code> </td><td> <code title="">altGlyphItem</code>
</td></tr><tr><td> <code title="">animatecolor</code> </td><td> <code title="">animateColor</code>
</td></tr><tr><td> <code title="">animatemotion</code> </td><td> <code title="">animateMotion</code>
</td></tr><tr><td> <code title="">animatetransform</code> </td><td> <code title="">animateTransform</code>
</td></tr><tr><td> <code title="">clippath</code> </td><td> <code title="">clipPath</code>
</td></tr><tr><td> <code title="">feblend</code> </td><td> <code title="">feBlend</code>
</td></tr><tr><td> <code title="">fecolormatrix</code> </td><td> <code title="">feColorMatrix</code>
</td></tr><tr><td> <code title="">fecomponenttransfer</code> </td><td> <code title="">feComponentTransfer</code>
</td></tr><tr><td> <code title="">fecomposite</code> </td><td> <code title="">feComposite</code>
</td></tr><tr><td> <code title="">feconvolvematrix</code> </td><td> <code title="">feConvolveMatrix</code>
</td></tr><tr><td> <code title="">fediffuselighting</code> </td><td> <code title="">feDiffuseLighting</code>
</td></tr><tr><td> <code title="">fedisplacementmap</code> </td><td> <code title="">feDisplacementMap</code>
</td></tr><tr><td> <code title="">fedistantlight</code> </td><td> <code title="">feDistantLight</code>
</td></tr><tr><td> <code title="">feflood</code> </td><td> <code title="">feFlood</code>
</td></tr><tr><td> <code title="">fefunca</code> </td><td> <code title="">feFuncA</code>
</td></tr><tr><td> <code title="">fefuncb</code> </td><td> <code title="">feFuncB</code>
</td></tr><tr><td> <code title="">fefuncg</code> </td><td> <code title="">feFuncG</code>
</td></tr><tr><td> <code title="">fefuncr</code> </td><td> <code title="">feFuncR</code>
</td></tr><tr><td> <code title="">fegaussianblur</code> </td><td> <code title="">feGaussianBlur</code>
</td></tr><tr><td> <code title="">feimage</code> </td><td> <code title="">feImage</code>
</td></tr><tr><td> <code title="">femerge</code> </td><td> <code title="">feMerge</code>
</td></tr><tr><td> <code title="">femergenode</code> </td><td> <code title="">feMergeNode</code>
</td></tr><tr><td> <code title="">femorphology</code> </td><td> <code title="">feMorphology</code>
</td></tr><tr><td> <code title="">feoffset</code> </td><td> <code title="">feOffset</code>
</td></tr><tr><td> <code title="">fepointlight</code> </td><td> <code title="">fePointLight</code>
</td></tr><tr><td> <code title="">fespecularlighting</code> </td><td> <code title="">feSpecularLighting</code>
</td></tr><tr><td> <code title="">fespotlight</code> </td><td> <code title="">feSpotLight</code>
</td></tr><tr><td> <code title="">fetile</code> </td><td> <code title="">feTile</code>
</td></tr><tr><td> <code title="">feturbulence</code> </td><td> <code title="">feTurbulence</code>
</td></tr><tr><td> <code title="">foreignobject</code> </td><td> <code title="">foreignObject</code>
</td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
</td></tr><tr><td> <code title="">lineargradient</code> </td><td> <code title="">linearGradient</code>
</td></tr><tr><td> <code title="">radialgradient</code> </td><td> <code title="">radialGradient</code>
</td></tr><tr><td> <code title="">textpath</code> </td><td> <code title="">textPath</code>
</td></tr></tbody></table><p>If the <a href="parsing.html#current-node">current node</a> is an element in the <a href="namespaces.html#svg-namespace">SVG
namespace</a>, <a href="#adjust-svg-attributes">adjust SVG attributes</a> for the
token. (This fixes the case of SVG attributes that are not all
lowercase.)</p>
<p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
fixes the use of namespaced attributes, in particular XLink in
SVG.)</p>
<p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
same namespace as the <a href="parsing.html#current-node">current node</a>.</p>
<p>If the token has its <i>self-closing flag</i> set, pop the
<a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> and <a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing
flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
</dd>
<dt id="scriptForeignEndTag">An end tag whose tag name is "script", if the <a href="parsing.html#current-node">current node</a> is a <code title="">script</code> element in the <a href="namespaces.html#svg-namespace">SVG namespace</a></dt>
<dd>
<p>Pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p>Let the <var title="">old insertion point</var> have the
same value as the current <a href="parsing.html#insertion-point">insertion point</a>. Let
the <a href="parsing.html#insertion-point">insertion point</a> be just before the <a href="parsing.html#next-input-character">next
input character</a>.</p>
<p>Increment the parser's <a href="parsing.html#script-nesting-level">script nesting level</a> by
one. Set the <a href="parsing.html#parser-pause-flag">parser pause flag</a> to true.</p>
<p><a href="http://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing">Process
the <code title="">script</code> element</a> according to the SVG
rules, if the user agent supports SVG. <a href="references.html#refsSVG">[SVG]</a></p>
<p class="note">Even if this causes <a href="apis-in-html-documents.html#dom-document-write" title="dom-document-write">new characters to be inserted into the
tokenizer</a>, the parser will not be executed reentrantly,
since the <a href="parsing.html#parser-pause-flag">parser pause flag</a> is true.</p>
<p>Decrement the parser's <a href="parsing.html#script-nesting-level">script nesting level</a> by
one. If the parser's <a href="parsing.html#script-nesting-level">script nesting level</a> is zero,
then set the <a href="parsing.html#parser-pause-flag">parser pause flag</a> to false.</p>
<p>Let the <a href="parsing.html#insertion-point">insertion point</a> have the value of the <var title="">old insertion point</var>. (In other words, restore the
<a href="parsing.html#insertion-point">insertion point</a> to its previous value. This value
might be the "undefined" value.)</p>
</dd>
<dt>Any other end tag</dt>
<dd>
<p>Run these steps:</p>
<ol><li><p>Initialize <var title="">node</var> to be the <a href="parsing.html#current-node">current
node</a> (the bottommost node of the stack).</p></li>
<li><p>If <var title="">node</var> is not an element with the
same tag name as the token, then this is a <a href="parsing.html#parse-error">parse
error</a>.</p></li>
<li><p><i>Loop</i>: If <var title="">node</var>'s tag name,
<a href="infrastructure.html#converted-to-ascii-lowercase">converted to ASCII lowercase</a>, is the same as the tag
name of the token, pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> until <var title="">node</var> has been popped
from the stack, and then jump to the last step of this list of
steps.</p></li>
<li><p>Set <var title="">node</var> to the previous entry in the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p></li>
<li><p>If <var title="">node</var> is not an element in the
<a href="namespaces.html#html-namespace-0">HTML namespace</a>, return to the step labeled
<i>loop</i>.</p></li>
<li><p>Otherwise, process the token according to the rules given
in the section corresponding to the current <a href="parsing.html#insertion-mode">insertion
mode</a> in HTML content.</p></li>
</ol></dd>
</dl></div></body></html>