Semantic HTML
Semantic HTML introduces meaning to the code we write. Before Semantic HTML the elements didn’t have any meaning as to what it does or what content goes in it. An element such as <div> was used as a general‐purpose element to create things from headers to footers to articles. With Semantic HTML we were introduced to elements that tell developers and browsers exactly what it does and what content should go in it.
Semantic HTML refers to the idea that all your HTML markup should convey the underlying meaning of your content (not its appearance). Sectioning elements are a set of elements designed for the sole purpose of adding more meaning to the overall layout of a web page, and they look something like in figure 1.
Element Placement
Semantic HTML introduces elements that can tell developers exactly what the
element does or where it’s placed based on the name of that element. Some of
these elements are <header>
, <nav>
,
<main>
, and <footer>
.
<header>
describes the content at the top of the page
<body>
. It may include a logo, navigational links or a
search bar. <nav>
encapsulates the page’s navigational
links. It is often placed inside the <header>
or
<footer>
. <main>
encapsulates the
main content of a page between the header/navigation and the footer areas.
<footer>
includes the page’s footer content at the bottom
of the <body>
.
Sectioning Elements
Element | Placement | Purpose | Content |
---|---|---|---|
<header> |
At the beginning | Denotes introductory content for a section, article, or entire web page. |
|
<footer> |
At the end | Denotes concluding content for a section, article, or entire web page. |
|
<aside> |
At the side | Used to mark additional information that can enhance another element but isn’t required in order to understand the main content. |
|
<nav> |
Inside header, footer or aside element | Lets you mark up the various navigation sections of your website. |
|
<article> |
At the body or inside other element | Represents an independent article in a web page. Wraps content that can be plucked and distributed in a different context. |
|
<section> |
At the body or inside other element | Defines elements in a document with the same theme. It doesn’t need to make sense outside the context of the document. |
|
Other Semantic Elements
Element | Purpose | Attributes | Content |
---|---|---|---|
<figure> |
Represents a self-contained "figure" used to encapsulate media. |
|
|
<figcaption> |
Used to describe the media within the <figure> element.
|
|
|
<video> |
Used to embed video content into a document. Uses the src
attribute or the element <source> to embed.
|
controls autoplay loop
|
|
<audio> |
Used to embed audio content into a document. Uses the src
attribute or the element <source> to embed.
|
controls autoplay loop
|
|
<embeded> |
Can embed any media content from an external source. *Note that it is a deprecated tag |
|
|
<time> |
Represents either a time of day or a calendar date. It makes it possible for browsers to link it to users’ calendars and helps search engines identify dates. |
datetime
|
|
<address> |
It defines contact information for the author of the article or
web page in question. It should not be used for arbitrary physical addresses. |
|