HTML <div> tag and semantic HTML
dividing up a webpage with "container tags" + other names for <div>
The <div>
tag, as its name implies, can divide an HTML document into more organized sections as such:
However, we will see in the following sections that we can do even better than this!
Semantic HTML
Instead of using <div>
tags to divide an HTML page up, semantic HTML allows us to replace "div
" with more meaningful names such as those in the following table:
Tag
For
<header>
the top of a page
<nav>
...a menu inside a header
<main>
the main content of the page
<section>
...a part of the main content
<article>
...(think of a blog or a news site that show a list of posts!)
<aside>
...related but "optional" content
<figure>
...encapsulating images/charts/diagrams or similar
<footer>
the bottom of a page
Note that we could use any of those tags to contain any kind of content, but other developers and/or screen reader users might not enjoy that!
The aforementioned tags keep HTML organized:
The above should certainly look more readable than the below:
Older tags as semantic HTML
Tags such as <table>
and <form>
have existed for as long as HTML, so we could also see them as a "pre-cursor" to semantic HTML:
their tags say what they are
we could use
<div>
tags and JavaScript to re-create their functionalityobviously, in good practice, we do not!
A note about <figure> and <figcaption>
A <figure>
would contain media (usually an image), while a <figcaption>
to describe that media:
These tag names still confuse me (I have worked with HTML for a long time and I also speak English natively) so have patience with them!
Last updated