4 ms·
Note that you don't actually need the head or body tags in your page. The browser already knows what is allowed in the head. It looks weird at first, but you ca
by MatthewPhillips 9y ago
Note that you don't actually need the head or body tags in your page. The browser already knows what is allowed in the head. It looks weird at first, but you can write your html like so:
<!doctype html>
<html lang="en">
<title>My Title</title>
<div id="main"></div>
Also note that the html tag can also be omitted, unless you need to set the language. Don't worry about closing it either.
- Deimorz 9y agoEdit: my original comment (retained below) is wrong about this being malformed, and it's completely valid. Some more info here: https://html.spec.whatwg.org/multipage/syntax.html#optional-tags https://html.spec.whatwg.org/multipage/syntax.html#optional-... --- Original comment: The fact that browsers are able to handle malformed HTML doesn't mean that you should do it that way. There's no meaningful benefit that I can think of, and the potential to break a ton of things that aren't as lenient.
- Pxtl 9y agoThe new craziness is basically that HTML is no longer structured as a tree, no more closing tags that don't semantically hold data, etc.
- irrational 9y agoMy understanding is that it is not malformed, but actually a part of the spec. Maybe someone else has a link to the appropriate part of the spec, but following someone else's link to the spec and reading it for myself is how I learned that it is not malformed.
- SippinLean 9y ago>Tag omission in text/html: >An html element's start tag can be omitted if the first thing inside the html element is not a comment. >An html element's end tag can be omitted if the html element is not immediately followed by a comment. https://www.w3.org/TR/html5/semantics.html#the-html-element https://www.w3.org/TR/html5/semantics.html#the-html-element
- Yaggo 9y agoIt's not malformed in the traditional meaning, the HTML5 spec actually says that HTML, HEAD, BODY, etc. unambiguous tags can be omitted.
- rimliu 9y agoThis is not malformed HTML. In fact, optional tags were in older HTML specs and are perfectly legal. Even in HTML 4.01 Strict. See: http://rimantas.com/bits/minimal_html.html http://rimantas.com/bits/minimal_html.html
- c_shu 9y agoRemoving optional tags is recommended here: https://google.github.io/styleguide/htmlcssguide.html https://google.github.io/styleguide/htmlcssguide.html