This morning, as I was writing some html and haml, it occurred to me that the way divs are used is ridiculous. Why are divs not implied? Imagine if this:
<div class="hero-img">
<img src="http://whatever.com/this.jpg">
</div>
was this:
<hero-img>
<img src="http://whatever.com/this.jpg">
</hero-img>
If the "div class" portion of the element was assumed, HTML would be more semantic, and infinitely more readable with the matching closing tags!
This is similar to HAML, where we have:
.content Hello, World!
Which becomes:
<div class='content'>Hello, World!</div>
It seems to me the only thing that would have to happen for this to work in browsers is that the browsers could start interpreting every element without an existing html element definition as implying <div class="<element name>">
.
This could be completely backward compatible; for CSS and jQuery selectors etc, "div.hero-img" could still work, and be the required syntax to select the elements.
I know about the new web components specification, but that is significantly more complicated than what is suggested here. Can you imagine how pleasant it would be to look at a website's source and see html that looked like that?!
So why do we have to use divs?
If you look at Mozilla's html5 element list, every element has a semantic meaning, and then we get to <div>
and it says:
"Represents a generic container with no special meaning."
..and then they list the arbitrary elements they are adding to html5 like <details>
.
Of course, if this concept of implied divs was added to the html spec, it would take ten years to become standard, which is a million years in web time.
So I figure there must be a good reason this hasn't happened yet. Please, explain it to me!