← Back

A note on semantics

Semantics in the HTML world, is the meaning behind the tags you use. Not the way it looks once rendered in the browser, but what it means when reading the code.

Let's take a simple example:

<p>Groceries list</p>
<div>
	<p>Pasta</p>
	<p>Olive oil</p>
	<p>Garlic</p>
</div>

In this non-semantic example, the only reason you understand this is a list is because of the text, not the code.

But in this version:

<h1>Groceries list</h1>
<ul>
	<li>Pasta</li>
	<li>Olive oil</li>
	<li>Garlic</li>
</ul>

You can understand that this is a list of some sort without even looking at the text. That's thanks to the use of semantic tags like ul and li.

But as useful as semantic tags are, they can also sometimes cause more harm than good. To understand this, we need to do a tiny bit of history.

Semantic tags have always been around. Tags like <p> or <h1> are some of the fundamental building blocks of HTML.

As the web grew and CSS matured, we started seeing devs use some common class names like .nav, .section or .article.

This was especially prevalent in the HTML4 era of the web.

Soon discussions started to arise about the next version of HTML. It was decided that HTML would become more semantic, and that these common classes that were found everywhere would become actual tags.

The ideas behind this change were twofold.

More sematic tags meant crawlers of all sorts could more easily understand webpages, and in the 2.0 social era of the web, this was becoming very necessary.

The other aspect of this change was accessbility. More semantic tags also meant more tools for assistive tech to use to allow users to find their way accross a webpage.

Based on that description, you could think that all is well in a happy world. But as is often the case, accessibility wasn't the part that weighed heavier in the balance.

That's why despite most tags turning out good for accessibility—for example the <main> tag ❤️—others would end up making things worse—looking at you <article>.

It also meant more responsibily on developers to wield these tools correctly, and we would see many examples of tags being missused all over the web; making users more confused than helped.

Because of that, in these pages, I'm not always going to respect the rules of semantic HTML5 to a tee. I will make sure to always explain why and show that sometimes, it's worth breaking the rules a little to make the web a better place.