HTML is Weird

by Stephen Fluin

2016-10-07

HTML is Weird
I've been struck a few times in the past few months by how truly weird HTML is. Perhaps most developers already know this, but coming from an era where HTML used to the wild west, some of this was surprising to me.

Forget Close Tags##

You probably know you don't need to (and shouldn't) close tags like img or input. Did you know that you don't have to close div tags, as long as it's semantically unambiguous? That's right, that wall of divs at the end of your page are completely unnecessary.
</div>
    </div>
  </div>
</div>

I would still recommend you close all of your tags, even if it is valid standards-compliant HTML. Otherwise it can be very hard to figure out what's going on.

Forget Tags Entirely##

There are a few tags that can be omitted completely. In certain circumstances, even the most standard tags such as html, head, and body.
Check out the W3C spec on optional tags for more.

Finite Possibilities##

I'm showing my age through these memories, but gone are the days where constantly there were new HTML tags providing new capabilities. There's now a standard list of HTML elements that all of the browsers agree on. Anything not on this list ends up extending HTMLUnknownElement. Each of these tags has a predefined allowable attributes. All of the browsers agree and we don't often see new elements. All of the HTML element innovation has moved into projects like Angular and Custom Elements HTML standards.