4 ms·
All of the examples provided are valid HTML5, and all HTML5-compliant user agents are required to implement the HTML5 parsing algorithm, which constructs a DOM
by kiwidrew 6y ago
All of the examples provided are valid HTML5, and all HTML5-compliant user agents are required to implement the HTML5 parsing algorithm, which constructs a DOM tree in a deterministic manner for any given input.
HTML5 specifically permits tag omission in many cases [1], including but not limited to both the opening and closing <html>, <head>, and <body> tags. The parsing algorithm provided in the standard generates a DOM tree that includes the omitted tags in the correct place(s).
For example, the following document is valid HTML5:
<!DOCTYPE html>
<title>Hello</title>
<p>Welcome to this example.
[1] https://www.w3.org/TR/html52/syntax.html#optional-tags https://www.w3.org/TR/html52/syntax.html#optional-tags
- deleted 6y ago[deleted]
- SahAssar 6y agoThe original post specifically mentions dropping the doctype which is not valid. It also implies that you can drop all (or at least many) closing tags without saying that some are optional and some are not.
- johncmouser 6y agowould you need the doctype if the user-agent said it was html5 compliant?
- SahAssar 6y agoThe doctype is required for it to be a valid html5 document.
- recursive 6y agoYes. Especially then. Without a doctype, it's not html5.
- pzmarzly 6y agoWithout doctype, browsers will render your page in quirks mode, leaving you scratching your head because of margins being set out of nowhere. https://developer.mozilla.org/en-US/docs/Mozilla/Mozilla_quirks_mode_behavior https://developer.mozilla.org/en-US/docs/Mozilla/Mozilla_qui...