News for hackers. Stuff that matters.
Re:The appeal of using plain HTML pages (2019) by enriquto on Monday May 02, 2022 @02:45PM (#31239148)
Because it's unnecessary in html5, just like closing li, td, tr tags. When you use implicit tags (body, header, etc) and auto-closing tags (li, p, tr, td,...) then html becomes refreshingly lean and human-editable.

EDIT: for a nice summary, look at google's html style guide. Section 3.1.7 is particularly neat [0].

[0] https://google.github.io/styleguide/htmlcssguide.html#Option...

Re:The appeal of using plain HTML pages (2019) by niconii on Monday May 02, 2022 @03:00PM (#31239347)
Just to clarify, HTML5 didn't introduce this, it's been the case since at least 1993.

https://www.w3.org/MarkUp/HTMLPlus/htmlplus_1.html

Re:The appeal of using plain HTML pages (2019) by jefftk on Monday May 02, 2022 @03:03PM (#31239374)
Before HTML5 it was common to hear things like "technically you don't need it, but it's not to spec so don't do it".
Re:The appeal of using plain HTML pages (2019) by niconii on Monday May 02, 2022 @03:16PM (#31239534)
Well, then they were wrong, because it's always been part of every HTML spec.

Perhaps they were thinking of XHTML, which did require all tags because it was based on XML.

Re:The appeal of using plain HTML pages (2019) by nicoburns on Monday May 02, 2022 @04:20PM (#31240369)
I believe before html5 they weren't required, but what the parsed DOM tree looked like wasn't clearly defined if they weren't, and in practice different browsers did it differently meaning you could very easily end up with it rendering differently in different browsers. html5 fixed that.
Re:The appeal of using plain HTML pages (2019) by anjbe on Tuesday May 03, 2022 @01:16AM (#31244916)
This is not correct. What you’re describing sounds like how HTML5 standardized parsing of invalid HTML, but that is not the same thing as implicit closing tags, which have have always been valid, correct HTML producing an unambiguous, clearly defined result.
Re:The appeal of using plain HTML pages (2019) by niconii on Monday May 02, 2022 @04:35PM (#31240567)
Oh, for sure, actually parsing HTML was awful before HTML5. The spec sometimes diverged from how browsers actually interpreted HTML, and error correction basically boiled down to browsers trying to reverse-engineer each other to figure out how they handled broken HTML. HTML5 was a godsend for actually standardizing all of that.
Re:The appeal of using plain HTML pages (2019) by zerocrates on Monday May 02, 2022 @03:12PM (#31239482)
Probably mostly a casualty of that window when people were trying to make XHTML happen, so all the SGML-isms like omitted close tags became verboten.
Re:The appeal of using plain HTML pages (2019) by vmception on Monday May 02, 2022 @05:30PM (#31241205)
Browsers literally would not render with one tiny syntax error/spec-deviation in your HTML

No different than having a JSX syntax error in React today

Re:The appeal of using plain HTML pages (2019) by Macha on Monday May 02, 2022 @05:52PM (#31241442)
In XHTML strict mode, which basically nobody used.

In XHTML transitional, and HTML1-4, what you'd get is browsers with divergent understandings of your DOM tree structure such that content that worked fine in one would be a horribly mangled mess (often breaking layout in difficult to read ways) in another browser.

Re:The appeal of using plain HTML pages (2019) by wwweston on Monday May 02, 2022 @07:39PM (#31242544)
Some of us tried XHTML. A little bit of extra consistency in syntax and closed tags was rewarded with being able to use tooling built around XML expectations. I dug that.

And then I found out there were some browsers that wouldn't handle it right unless content-type headers were set up right on the server, and of course that made it an extra pain, especially on commodity hosting where you might not have that remotely under your control.

The "strict warnings"/"rendering problems crash the page" setting was also... mixed. Certainly prompted you to pinpoint the issue and fix it but that level of nag often felt unnecessarily militant after what everyone was used to.

Re:The appeal of using plain HTML pages (2019) by irrational on Monday May 02, 2022 @03:14PM (#31239507)
I don’t understand how they are optional.

<p>Qed.

<img src=“some_image.jpg”>

And

<p>Qed.</p>

<img src=“some_image.jpg”>

Are going to give me different results.

Re:The appeal of using plain HTML pages (2019) by niconii on Monday May 02, 2022 @03:24PM (#31239632)
Yes, that is a case where it's not legal to omit `</p>` if you don't want the image to be inside the paragraph. Take a look at the spec[1], which outlines exactly when it is valid to omit tags.

The `p` element in particular has pretty scary rules, but it basically boils down to "if it doesn't make sense for this to be inside a paragraph (usually because it's a block element of some kind), it ends the paragraph."

[1] https://html.spec.whatwg.org/multipage/syntax.html#optional-...

Re:The appeal of using plain HTML pages (2019) by jefftk on Monday May 02, 2022 @03:23PM (#31239621)
It's are "optional" in the sense that the spec says it's optional and defines what that means: "A p element's end tag may be omitted if the p element is immediately followed by an address, article, aside, blockquote, details, div, dl, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, header, hgroup, hr, main, menu, nav, ol, p, pre, section, table, or ul element, or if there is no more content in the parent element and the parent element is an HTML element that is not an a, audio, del, ins, map, noscript, or video element, or an autonomous custom element."
Re:The appeal of using plain HTML pages (2019) by irrational on Monday May 02, 2022 @03:43PM (#31239893)
LOL. So I can memorize or check that list every time I'm using a p tag (and, of course, I'm relying on someone not doing something like changing the display property of a block element to inline), or... I can just use a closing p tag. I know which one is infinitely easier for me.
Re:The appeal of using plain HTML pages (2019) by niconii on Monday May 02, 2022 @03:53PM (#31240031)
I mentioned "block elements" in my other comment, but to be clear, CSS has no effect on how HTML is parsed, so the display property isn't relevant here.

Furthermore, you need to know about this rule even if you do write `</p>`. If you write this:

    <p>
        <div>hello</div>
    </p>
it is invalid HTML. This is because the paragraph is auto-closed, and then your code is equivalent to this:

    <p>
        </p><div>hello</div>
    </p>
resulting in an error because of the extra `</p>` after the `</div>`.
Re:The appeal of using plain HTML pages (2019) by legalcorrection on Monday May 02, 2022 @04:25PM (#31240429)
Do browsers actually do that?
Re:The appeal of using plain HTML pages (2019) by jraph on Monday May 02, 2022 @04:31PM (#31240514)
They can't produce imbalanced tags because it's impossible to represent in a DOM tree.

They will indeed auto close the (first) paragraph, and also auto open a new <p> element because of the extra closing </p> tag.

Try it out by typing this in your address bar and open the inspector:

    data:text/html;charset=utf-8,<!DOCTYPE html><p><div>hello</div></p>
The generated HTML (document.body.parentNode.innerHTML):

    <head></head><body><p></p><div>hello</div><p></p></body>
Browsers will go out of their way to produce a (valid) DOM from pretty much any string (as per the HTML5 spec). (Almost?) nothing is a syntax error. You won't get a HTML5-compliant browser to show a parse error to the user in HTML (of course, this is not the case in XHTML).

edit: sorry niconii, I edited my comment under your feet.

Re:The appeal of using plain HTML pages (2019) by niconii on Monday May 02, 2022 @04:46PM (#31240710)
Just to add to this, HTML parsers will attempt to make sense of any random line noise you give it and turn it into a DOM. When I say something is "invalid" HTML, what I mean is that it's not allowed by the spec and will result in an error if you run it through a validator (which you should do!)

For example, try running the following document through the W3C's HTML validator[1]:

  <!DOCTYPE html>
  <html lang=en>
  <title>Test Document</title>

  <p>
    <div></div>
  </p>
The HTML spec contains a list of all possible parse errors[2].

[1] https://validator.w3.org/nu/#textarea

[2] https://html.spec.whatwg.org/multipage/parsing.html#parse-er...

Re:The appeal of using plain HTML pages (2019) by jraph on Monday May 02, 2022 @04:54PM (#31240801)
It is allowed by the spec afaik (the spec precisely tells browsers how to interpret this, so everything is perfectly specified in the spec boundaries - and so it's not "out of spec").

Of course, that screams "MISTAKE" that a validator should warn you about. Like a linter that would spot missing extra parentheses for an assignment in a if condition in C-like language. It is allowed to not put the parentheses, but it is recommended to put them.

And of course, that makes "Valid HTML" (almost?) redundant (There are probably "vocabulary" errors that are possible, like a missing src attribute for an img or a missing title tag in head - don't take my words on this though).

div in p is not invalid, it's outright impossible to obtain from HTML parsing.

You can obtain this by doing this in JavaScript:

    document.body.appendChild(document.createElement("p"));
    document.body.firstChild.appendChild(document.createElement("div")))
Or by parsing as XHTML:

    data:application/xhtml+xml;charset=utf-8,<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Hello</title></head><body><p><div></div></p></body></html>

You get:

    document.body.innerHTML

    <p xmlns="http://www.w3.org/1999/xhtml"><div/></p>
Which I realize is actually a bit scary, I go out of my way to write XHTML in the hope any error will be caught, but parsing as text/html actually produces a valid dom where parsing as XHTML won't necessarily.
Re:The appeal of using plain HTML pages (2019) by niconii on Monday May 02, 2022 @05:16PM (#31241025)
This is not quite right. The HTML spec specifies not only what browsers/user agents are allowed to do, but also what document authors are allowed to do.

While the HTML parser does handle errors, to conform to the spec, document authors must not make these errors.

Here is an excerpt from the spec[1]:

> As described in the conformance requirements section below, this specification describes conformance criteria for a variety of conformance classes. In particular, there are conformance requirements that apply to producers, for example authors and the documents they create, and there are conformance requirements that apply to consumers, for example web browsers. They can be distinguished by what they are requiring: a requirement on a producer states what is allowed, while a requirement on a consumer states how software is to act.

Furthermore, a user agent is not required to correct errors, and can simply halt at the first error[2]:

> The error handling for parse errors is well-defined (that's the processing rules described throughout this specification), but user agents, while parsing an HTML document, may abort the parser at the first parse error that they encounter for which they do not wish to apply the rules described in this specification.

[1] https://html.spec.whatwg.org/multipage/introduction.html#how...

[2] https://html.spec.whatwg.org/multipage/parsing.html#parse-er...

Re:The appeal of using plain HTML pages (2019) by jraph on Monday May 02, 2022 @05:17PM (#31241043)
I stand corrected! Thank you. I should have read the spec before posting.
Re:The appeal of using plain HTML pages (2019) by tannhaeuser on Tuesday May 03, 2022 @02:23AM (#31245320)
The way tag inference is expressed in the HTML 5 spec is the problem here. What the HTML spec says is just a verbose description of SGML tag inference, by explicitly listing all elements that can't appear in a paragraph.

Citing from [1]:

Earlier [SGML] HTML DTDs included the following definition for flow capturing this in a rather straightforward way:

    <!ENTITY % flow "%block; | %inline;">
While HTML5 lacks it, a definition for "block content" rises again by subtracting those elements from the "flow content" category that aren't also in the "phrasing content" (inline) category.

Nesting of phrasing into flow elements is about the most basic property of the HTML grammar. In SGML, the flow/phrasing hierarchy is expressed by declaring the content model of flow elements as allowing %phrasing;, where %phrasing;, like in earlier HTML DTDs, is substituted into a string such as a|abbr|... containing all phrasing elements as a name group.

For example, the element declaration for the p element is as follows:

    <!ELEMENT p - O 
      (#PCDATA|%phrasing;)*
      -(%flow_only;)>
meaning that

- the content of p elements can be any sequence of text content (#PCDATA) and phrasing elements, and

- flow content isn't just forbidden in direct child content of p (via admitting %phrasing; elements only), but also isn't admitted anywhere in descendant content of p, as expressed by the -(%flow_only;) SGML exclusion exception, and

- the end-element, but not the start-element tag of p can be omitted, as declared in ps tag omission indicator - O

where the flow_only parameter entity contains block-level elements as described above, ie. flow elements that aren't also phrasing elements.

[1]: http://sgmljs.net/docs/html5.html

Re:The appeal of using plain HTML pages (2019) by jefftk on Monday May 02, 2022 @03:49PM (#31239977)
You can memorize the list, but it's easier than that: things that can go in a paragraph (which includes images) let the <p> continue, while things that can't (which is the long list there) close the <p>. In practice you get used to it very quickly.
Re:The appeal of using plain HTML pages (2019) by trey-jones on Monday May 02, 2022 @04:47PM (#31240714)
I can't believe the committee approved this spec without consulting me. I can see that I'm not the only one that feels this degree of agency in syntax is a bridge too far. Clearly this part of the spec was written by a Ruby developer.
Re:The appeal of using plain HTML pages (2019) by jefftk on Monday May 02, 2022 @05:11PM (#31240959)
The specification is just codifying what browsers already did in practice.

There was a time when people thought we might be able to change web development practice and browsers to something more consistent, but (a) what they chose was XHTML and (b) the benefit of switching was not there.

Re:The appeal of using plain HTML pages (2019) by jefftk on Monday May 02, 2022 @02:53PM (#31239256)
Re:The appeal of using plain HTML pages (2019) by niconii on Monday May 02, 2022 @06:11PM (#31241666)
Okay, I've gotten a bit carried away with HTML spec minutia elsewhere in these comments, mainly because this stuff really isn't common knowledge among web developers and it's hard to resist talking about it.

However, I also want to add to the other point here; namely, "why do this in the first place?"

Google mentions "file size optimization" in the style guide linked above, and it led to criticism on HN and elsewhere along the lines of "sure, maybe shaving off a few bytes adds up for Google, but you're not Google." However, this really isn't why I do it, and I think maybe it's poisoned the discussion a bit.

For me, it's mostly about reducing visual noise. It's not necessarily less typing if you're using an editor that auto-inserts closing tags, but I think it's harder to read with the end tags, particularly when it comes to tables. For instance, consider this table (which, if you're curious, is about Super Nintendo audio samples):

  <table>
    <tr><th>sample rate</th> <th>data rate</th>    <th>max length</th></tr>
    <tr><td>32000 Hz</td>    <td>18000 byte/s</td> <td> ~3.641 s</td></tr>
    <tr><td>16000 Hz</td>    <td> 9000 byte/s</td> <td> ~7.282 s</td></tr>
    <tr><td> 8000 Hz</td>    <td> 4500 byte/s</td> <td>~14.564 s</td></tr>
  </table>
And now, take a look at it without the optional end tags:

  <table>
    <tr><th>sample rate <th>data rate    <th>max length
    <tr><td>32000 Hz    <td>18000 byte/s <td> ~3.641 s
    <tr><td>16000 Hz    <td> 9000 byte/s <td> ~7.282 s
    <tr><td> 8000 Hz    <td> 4500 byte/s <td>~14.564 s
  </table>
Personally, this is much easier for me to read and maintain. There's also much less chance of me accidentally mismatching opening and closing tags, since I've eliminated almost all of the closing tags besides </table>.

On top of that, let's be honest, <html><head></head><body></body></html> is just useless boilerplate. We all know what goes in the head and what goes in the body, and I think we can all figure out where the HTML starts and ends. The browser knows all of this too, which is why all of those tags are completely optional. Not only does getting rid of that make the code less noisy, it solves the age-old problem of "should I indent the head and body or not?" (Though, in practice, I still keep <html lang=en> so that I can specify the language for people who use screen readers. </html> is just silly, though.)

Re:The appeal of using plain HTML pages (2019) by rchaud on Tuesday May 03, 2022 @09:23AM (#31247967)
How likely is it that a dev would be reading an HTML table with hardcoded data in the code editor in this day and age?

Today, data tables are mostly dynamically generated, probably via accessing an API endpoint of some sort. The dev would at most write a function that would output the data inside a <table> element. But the table data itself would only be visible in the browser, it wouldn't be hardcoded into the HTML markup.

Re:The appeal of using plain HTML pages (2019) by jefftk on Tuesday May 03, 2022 @11:39AM (#31249629)
If you're following the advice of the post, and using HTML as your authoring format, this is pretty common. I do it a lot on my blog.

It's similar to how often you see tables in Markdown.

Re:The appeal of using plain HTML pages (2019) by rchaud on Tuesday May 03, 2022 @12:25PM (#31250190)
Even the official Markdown guide suggests using a table generator because the markup is a hassle:

https://www.markdownguide.org/extended-syntax/

HTML tables are similarly cumbersome, with or without closing tags. If you have a table of static information to fill in, copy/pasting from Excel into a HTML table generator and pasting the output is signficantly faster.

Re:The appeal of using plain HTML pages (2019) by jefftk on Tuesday May 03, 2022 @02:25PM (#31251692)
Markdown is suggesting using a generator for writing, but you were saying it was unlikely that someone would be reading a table in source.

I'd also much rather write an HTML table by hand than a markdown one.

Re:The appeal of using plain HTML pages (2019) by enriquto on Tuesday May 03, 2022 @10:26AM (#31248726)
What is your point? Even if it is a rare occurrence, from time to time you might want to output an html table using "print", and it will be slightly more comfortable that way. I sometimes find myself editing html by hand. Thanks to the optional and auto-closing tags it is just as easy as markdown, and you don't need an extra conversion step.

The verbose format has no advantage whatsoever, unless you are doing weird xml stuff.