The HTML 5 specification allows the omission of some optional start and end tags where the tags’ existence can be inferred.
View the source of this page. It validates despite its terseness. Browsers’ inspectors will show the missing tags.
Summary of the linked spec portion (not exactly correct but with the differences in minor semantics):
<html lang=en>
) can be omitted.
html
start and end tags can be omitted.
head
start and end tags can be omitted.
body
end tag can be omitted, and the start tag can be omitted if the body does not start with elements typically in the head
(meta, link, script, style).
li
end tag can be omitted if it’s followed by another li
or if the list element ends; this implies that an ul
or ol
end tag cannot be omitted.
p
end tag can be omitted if it’s followed by an address, article, aside, blockquote, details, div, dl, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, header, hr, main, nav, ol, p, pre, section, table or ul element or if its parent element ends.
tbody
start tag can be omitted if the first thing inside it is a tr
element. The tbody
end tag can be omitted if the table ends.
tr
end tag can be omitted if it's followed by another tr
.
td
or th
end tag can be omitted if they're followed by another td
or th
, or if the parent element (tr
) ends.
The following is then the smallest valid HTML document with a single paragraph:
<!DOCTYPE html><title>t</title><p>p
A small HTML document with a 3×3 table in it:
<!DOCTYPE html><title>xor</title> <table><tr><th>⊕<th>0<th>1 <tr><th>0<td>0<td>1 <tr><th>1<td>1<td>0</table>
index | 2019-03-23