HTML5 tags can be omitted, which can save the size of the web page without affecting the page layout. Reduce the amount of code.
Some tags can be omitted.
Omitting the start tag of a tag does not mean that the tag is not present, it is implicit, but it is still present. An HTML file always has a root tag HTML, even if the string <html> does not appear anywhere in the page markup.
The opening tag of an HTML tag can be omitted if the first tag within the HTML tag is not a comment.
The closing tag of an HTML tag may be omitted if the HTML tag is not immediately followed by a comment.
The opening tag of the head tag may be omitted if the tag is empty or if the tag within the head is first a tag rather than a comment.
The closing tag of the head tag may be omitted if the head tag is not immediately followed by a space character or comment.
The opening tag of a body tag may be omitted if that tag is empty, or if the first tag in the body tag is not a space character or comment, but if the first tag within the body tag is a script or style tag , the body tag cannot be omitted.
The closing tag of a body tag may be omitted if the body tag is not immediately followed by a comment.
The closing tag of a li tag can be omitted if the li tag follows another li tag or has more content without a parent tag.
The end tag of a DT tag may be omitted if the dt tag is immediately followed by another dt tag or after a dd tag.
The closing tag of a dd tag may be omitted if the dd is immediately followed by another dd tag or a dt tag, or if no further content of the parent tag follows.
The closing tag of the p tag can be omitted if the p tag is followed by an address, article, aside, blockquote, dir, div, dl, fieldset, footer, form, h1, h2, h3, h4, h5, h6, header, hgroup , hr, menu, nav, ol, p, pre, section, table, ul, tag, or if there is no more content of the parent tag and the parent tag is not a tag.
The closing tag of an RT tag may be omitted if the rt tag immediately follows an RT or RP tag, or is more content without a parent tag.
The closing tag of an rp tag may be omitted if the rp tag immediately follows an RT or RP tag, or if there is more content without a parent tag.
The closing tag of an optgroup tag may be omitted if the optgroup tag immediately follows another optgroup tag, or if there is no parent tag with more content.
The closing tag of an option tag may be omitted if the option tag follows another option tag, or an optgroup tag, or if there is no further content from the parent tag.
The opening tag of a COLGROUP tag may be omitted if the first tag within the COLGROUP tag is a col tag, or if the tag is not followed by another COLGROUP tag and its closing tag has been omitted. (COLGROUP cannot be ignored if the tag is empty.)
The closing tag in the COLGROUP tag may be omitted if the COLGROUP tag is not immediately followed by a space character or comment.
The closing tag of the thead tag can be omitted if the thead tag is immediately followed by a tbody or tfoot tag.
The start tag of the tbody tag can be omitted if the tbody tag inside is first a TR tag, and if there are no tbody, thead, and tfoot tags that have been omitted as the end tag after the tag. (It cannot be ignored if the tag is empty.)
The closing tag of the tbody tag may be omitted if the tbody tag immediately follows a tbody or TFOOT tag, or if there is no parent tag followed by more content.
The closing tag of a TFOOT tag may be omitted if the TFOOT tag is immediately followed by a tbody tag, or if there is no parent tag followed by more content.
The closing tag of a TR tag may be omitted if the TR tag immediately follows another TR tag, or if there is no parent tag followed by more content.
The closing tag of a TD tag may be omitted if the TD tag immediately follows the td,th tag, or if there is no parent tag followed by more content.
The closing tag of a th tag may be omitted if the th tag immediately follows a td, th tag, or if there is no parent tag followed by more content.
However, if the start tag has any one or more attributes, it cannot be omitted.
English original: http://www.w3.org/TR/2010/WD-html5-20100624/syntax.html#optional-tags
Source: http://www.netroby.com/ Translated from w3c's work case, Xin Zi Xiao Yao pays attention to the cutting-edge technical standards of WEB development and goes deep into WEB enterprise application development.
Thanks to W3C for your contribution