Container tags
HTML provides us with some tags we can use to group other tags together.
Suppose you want to group together a <p></p>
and an <img />
.
You can use <div></div>
.
This is probably the most used tag.
div
is the generic container element:
Itβs the one we use when we donβt have another dedicated container tag like article
.
You often add a class
or id
attribute to this element, to allow it to be styled using CSS.
Other container tags exist.
We have section
, article
, header
, aside
, main
, footer
, nav
.
Those are called semantic elements.
They do not have any special style applied, they all work like div
but their name has a specific meaning attached.
Imagine you have a page with a heading part with the article title, the content of the article, and finally a footer.
You could write the HTML like this:
Or you can give those sections more meaning in this way, without using class attributes:
There is nothing inherently wrong about using <div>
. Nothing changes from the visual point of view. But those tags have more meaning, and tools like screen readers can infer information from this meaning.
Letβs see when to use them.
article
article
The article tag identifies a thing that can be independent from other things in a page.
For example a list of blog posts in the homepage of a blog.
An article can also be the main element in a page.
section
section
Represents a section of a long article. Each section has a heading tag (h1
-h6
), then the section content.
Example:
This tag is useful to break a long article into different sections.
nav
nav
This tag is used to create the markup that defines the page navigation. Into this we typically add an ul
or ol
list:
aside
aside
The aside
tag is used to add a piece of content that is related to the main content.
A box where to add a quote, for example. Or a sidebar.
Example:
Using aside
is a signal that the things it contains are not part of the regular flow of the section it lives into.
header
header
The header
tag represents a part of the page that is the introduction. It can for example contain one or more heading tag (h1
-h6
), the tagline for the article, an image.
main
main
The main
tag represents the main part of a page:
footer
footer
The footer
tag is used to determine the footer of an article, or the footer of the page:
Last updated
Was this helpful?