HTML Semantics
HTML Semantics
<header></header>
<section>
<article>
<figure>
<img>
<figcaption></figcaption>
</figure>
</article>
</section>
<footer></footer>
Whilst this second block of code uses non-semantic elements:
<div id="header"></div>
<div class="section">
<div class="article">
<div class="figure">
<img>
<div class="figcaption"></div>
</div>
</div>
</div>
<div id="footer"></div>
First, it is much easier to read. This is probably the first
thing you will notice when looking at the first block of code using
semantic elements. This is a small example, but as a
programmer you can be reading through hundreds or
thousands of lines of code. The easier it is to read and
understand that code, the easier it makes your job.
It has greater accessibility. You are not the only one that
finds semantic elements easier to understand. Search engines
and assistive technologies (like screen readers for users with a
sight impairment) are also able to better understand the context
and content of your website, meaning a better experience for
your users.
Overall, semantic elements also lead to more consistent
code. When creating a header using non-semantic elements,
different programmers might write this as <div
class="header">, <div id="header">, <div class="head">, or
simply <div>. There are so many ways that you can create a
header element, and they all depend on the personal
preference of the programmer. By creating a standard semantic
element, it makes it easier for everyone.
Since October 2014, HTML4 got upgraded to HTML5, along
with some new “semantic” elements. To this day, some of us
might still be confused as to why so many different elements
that doesn’t seem to show any major changes.