Semantic HTML elements clearly describe their meaning to both the browser and the developer. Using semantic markup improves accessibility, SEO, and code maintainability. This guide covers the semantic elements introduced in HTML5 and best practices for using them.
Semantic elements clearly describe their meaning in a human- and machine-readable way. Elements such as <header>
, <footer>
, and <article>
are all considered semantic because they accurately describe the purpose of the element and the type of content that is inside them.
The <div>
and <span>
elements don't have any inherent meaning; they're just containers. Semantic elements, on the other hand, provide information about the content they contain.
HTML5 introduced several semantic elements that define the structure of a web page:
Element | Description |
---|---|
<header> |
Represents introductory content, typically a group of introductory or navigational aids |
<nav> |
Represents a section of a page that contains navigation links |
<main> |
Represents the main content of the document (should be unique to the document) |
<article> |
Represents self-contained content that could be distributed independently |
<section> |
Represents a standalone section of content that is a part of a larger whole |
<aside> |
Represents content tangentially related to the content around it (like a sidebar) |
<footer> |
Represents a footer for its nearest sectioning content or sectioning root element |
<article>
The <article>
element represents a complete, self-contained composition that is independently distributable or reusable.
Examples: Blog post, news story, forum post, comment, product card, interactive widget
<section>
The <section>
element represents a standalone section of content that forms part of a larger whole.
Examples: Chapters, tabbed content areas, grouped content with a heading
<aside>
The <aside>
element represents content that is tangentially related to the content around it, which could be considered separate from that content.
Examples: Sidebars, pull quotes, advertising, footnotes, related article links
<figure> <figcaption>
The <figure>
element represents self-contained content, with an optional caption (<figcaption>
). It is typically referenced as a single unit from the main content.
Examples: Images with captions, charts, diagrams, code snippets, quotes
<article>
is for content that would make sense on its own in a feed reader<section>
is for grouping together thematically-related content<article>
<section>
<header>
The <header>
element represents introductory content, typically a group of introductory or navigational aids. It can be used for the page header or for a section/article header.
<footer>
The <footer>
element represents a footer for its nearest sectioning content or sectioning root element. It typically contains information about the author, copyright data, or related links.
<header>
and <footer>
elements in a single document. They are not only for the top and bottom of the page but can be used within articles, sections, and other content blocks.
<nav>
The <nav>
element represents a section of a page that contains navigation links. Not all links should be inside a <nav>
element—only blocks of links that represent major navigation.
<nav>
element for:
<time>
The <time>
element represents a specific period in time. It may include the datetime
attribute to represent time in a machine-readable format.
<mark>
Here is some text with a highlighted section that needs attention.
Search results for "semantic HTML": Semantic HTML elements clearly describe their meaning...
The <mark>
element represents text which is marked or highlighted for reference or notation purposes.
<details> <summary>
This is the detailed content that is initially hidden but can be expanded by clicking the summary.
The <details>
element creates a disclosure widget in which information is visible only when the widget is toggled into an "open" state. The <summary>
element provides a summary or label for the details.
<address>
The <address>
element represents contact information for its nearest <article>
or <body>
ancestor.
Element | Description | Example |
---|---|---|
<cite> |
Represents the title of a creative work | The Great Gatsby by F. Scott Fitzgerald |
<code> |
Represents computer code | Use getElementById() to get an element by ID |
<dfn> |
Represents a defining instance of a term | A semantic element clearly describes its meaning to both the browser and the developer. |
<kbd> |
Represents user input from keyboard | Press Ctrl + S to save |
<abbr> |
Represents an abbreviation or acronym | HTML |
<main>
The <main>
element represents the main content of the document. The content inside the <main>
element should be unique to the document and should not include content that is repeated across documents such as navigation links, copyright information, site logos, and search forms (unless the document's main function is as a search form).
Note: There should be only one <main>
element in a document, and it should not be a descendant of an <article>
, <aside>
, <footer>
, <header>
, or <nav>
element.
<dialog>
The <dialog>
element represents a dialog box or other interactive component, such as a modal or popup. The open
attribute determines whether the dialog is active and the user can interact with it.
div.header
→ <header>
div.nav
→ <nav>
div.content
→ <main>
div.article
→ <article>
div.article-header
→ <header>
(inside article)div.article-content
→ <section>
div.article-footer
→ <footer>
(inside article)div.sidebar
→ <aside>
div.footer
→ <footer>
Using semantic HTML significantly improves accessibility:
Benefit | Description |
---|---|
Screen Reader Navigation | Screen readers announce semantic elements, allowing users to navigate by headings, landmarks, etc. |
Keyboard Navigation | Semantic elements like <button> have built-in keyboard accessibility |
Landmarks | Elements like <nav> , <main> , and <aside> create ARIA landmarks |
Context | Semantic context helps assistive technologies understand content relationships |
Default Styling | Semantic elements have default styles that help with accessibility |
HTML Element | Implicit ARIA Role |
---|---|
<header> |
banner (when in the <body> context) |
<nav> |
navigation |
<main> |
main |
<aside> |
complementary |
<footer> |
contentinfo (when in the <body> context) |
<section> |
region (when it has an accessible name) |
<article> |
article |
<div>
and <span>
when a semantic alternative exists<h1>
to <h6>
) to create a logical document outline<main>
element per page<article>
for self-contained, independently distributable content<nav>
for major navigation blocks, not for all links<article>
can contain <section>
elements, or vice versa depending on the content structure<time>
with the datetime
attribute for dates and times<address>
for contact information, not for postal addresses in general