Write (Hugo) HTML, the HTML Way (Not the XHTML Way)

CSS-tricks.com have written an interesting post Write HTML, the HTML Way (Not the XHTML Way).

I have looked at it, and there is one thing that I want to raise, where Hugo shall (?) improve by default unless there is good reason to leave it as it is?

Where Hugo is using <br> and not <br />, following examples, there is still




For discussion.

Also, when Hugo is rendering parts of template wher you use <li> without closing it, it automatically adding </li> as I see.

I don’t get it. What has <br> to do with <li> in this specific sample?

Long story short:

  • HTML 5 depends on having actually the HTML doctype as the start of the document.
  • Internal templates could be ANYWHERE in ANY doctype. So tags should always be closing themselves.

An opinion piece is always nice, but it never fits the “one for all” solution.

Internal templates need to work even if we are in some weird XHTML content type.

Hugo’s job is to create output. Not to support the only true website content type. One day it will. But then… Nobody will care about that :wink: because what’s right is right.

For now Hugo might even run on some weird form of old html style stuff. like <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN".

1 Like

Even though end tags are often not necessary, I personally find it clearer when they are used.

1 Like

I think often they make things more understandable in longer “constructs”. Better than having comments all over the place when a section or website-part ends. I think of it more as “can be omitted” than “are unnecessary”.

Being omittable doesn’t mean they MUST be left out :slight_smile:

@idarek The optimizations described in the article can be applied when using the --minify option with the following in site configuration:

keepDefaultAttrVals = false  # default true
keepDocumentTags = false     # default true
keepEndTags = false          # default true


Hugo does not add closing tags, but your browser’s dev tools does. If you use your browser’s “view source” option you will see that the tag is not closed.