Popular Searches
Popular Course Categories
Popular Courses

Semantic tags

31 mins HTML5 & Semantic Markup

Semantic tags in React JS

Course: React JS Training

Topic: Semantic tags

Course Link: React JS Training

Demo Link: Register for a Course Demo


1. Why Semantic Tags Matter

Every web page you have ever opened is built out of HTML tags. For many years, developers assembled whole layouts with one generic container, the <div>, and told the pieces apart only through class names such as class="header" or class="footer". The browser could not tell a genuine page header from a random box, because to the browser every <div> was exactly the same kind of container.

HTML5 solved this by introducing a family of tags whose names describe the content they hold. These are called semantic tags. A page built with them is easier to read, easier to maintain, easier for search engines to understand, and much friendlier to people who browse with assistive technology such as screen readers.

This matters directly for your future work with React. Every React component you write eventually renders into HTML in the browser. If your components output semantic tags, accessibility and search benefits come for free; if they output a pile of <div> elements, you spend extra effort repairing those problems later.

  • Readability: a teammate can scan <header>, <main> and <footer> and instantly know what each block is.
  • Accessibility: screen readers announce semantic regions and let users jump straight to navigation or main content.
  • Search visibility: crawlers can separate the main content from repeated page furniture such as menus and footers.
  • Maintainability: meaning lives in the markup itself, not only in CSS class names that can drift out of date.

2. Semantic Tags in Simple Words

A semantic tag is a tag whose name tells you, and the browser, what kind of content is inside it. The word "semantic" relates to meaning. So a semantic tag does not primarily change how the page looks; it declares what the content is.

Think of moving house. If every carton is an identical unlabelled box, unpacking is slow and confusing. If each carton is labelled "kitchen", "books" or "winter clothes", anyone can handle the boxes correctly without opening them. Semantic tags are those labels for page regions: <header> means introductory content, <nav> means a block of navigation links, <article> means a self-contained piece of content.

Two tags are deliberately not semantic: <div> is a generic block container and <span> is a generic inline container. They are the unlabelled cartons. They remain useful when no meaning fits, but they should be the fallback, not the default choice.


3. Key Terms You Should Know

Before looking at the tags themselves, learn these words. They appear again in the accessibility and SEO pages later in this module.

TermPlain meaning
SemanticsThe study of meaning; in HTML, tags that carry meaning about their content.
ElementOne complete tag unit: the opening tag, its content, and the closing tag.
LandmarkA page region that assistive technology recognises and can jump to, such as navigation or main content.
Document outlineThe tree of headings and sections that describes how a page is organised.
Sectioning contentTags such as <article> and <section> that carve the page into meaningful chunks.
Screen readerSoftware that reads the page aloud or presents it in braille for blind and low-vision users.
WrapperA container whose only job is grouping or styling; usually a <div>.

4. Semantic Tags Versus Generic Tags

The clearest way to feel the difference is to compare the two styles side by side. Here is the old "div soup" pattern:

<div class="top">
  <div class="menu">
    <a href="/">Home</a>
    <a href="/courses">Courses</a>
  </div>
</div>
<div class="content">
  <div class="post">
    <h2>Why structure matters</h2>
    <p>Readers and browsers both benefit from clear structure.</p>
  </div>
</div>
<div class="bottom">
  <p>Contact: [email protected]</p>
</div>

Now the same page written semantically:

<header>
  <nav>
    <a href="/">Home</a>
    <a href="/courses">Courses</a>
  </nav>
</header>
<main>
  <article>
    <h2>Why structure matters</h2>
    <p>Readers and browsers both benefit from clear structure.</p>
  </article>
</main>
<footer>
  <p>Contact: [email protected]</p>
</footer>

The second version renders the same visually before any CSS is applied, yet it says something the first version cannot: this is the header, this is navigation, this is the main content, this is the footer.

Generic tagWhat it tells the browserSemantic replacements
<div>"A block of something, unspecified."<header>, <nav>, <main>, <footer>, <section>, <article>, <aside>
<span>"Some inline text, unspecified."<time>, <mark>, <address>, <strong>, <em>

5. The Standard Semantic Page Skeleton

Almost every well-structured HTML page follows the same skeleton. Learn this shape first; the remaining tags fill the gaps inside it.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Semantic page skeleton</title>
</head>
<body>
  <header>
    <h1>Site name</h1>
  </header>

  <nav>
    <a href="/">Home</a>
    <a href="/about">About</a>
  </nav>

  <main>
    <article>
      <h2>Article title</h2>
      <p>The unique content of this page lives here.</p>
    </article>

    <aside>
      <h3>Related links</h3>
      <p>Supporting content that is not part of the article.</p>
    </aside>
  </main>

  <footer>
    <p>Contact and copyright information.</p>
  </footer>
</body>
</html>
  • <header> and <footer> sit at the top level of <body>, so they describe the whole page.
  • <main> holds everything that is unique to this page.
  • <article> holds a complete, self-contained piece of content.
  • <aside> holds related but non-essential content, often shown as a sidebar.

6. Structural Landmark Tags

These four tags define the big regions of a page and become recognised landmarks for assistive technology.

The header tag

<header> wraps introductory content: the site name, a logo, a tagline, or the title block of an article. When it sits directly inside <body>, it represents the whole page's banner. When it sits inside an <article> or <section>, it is only the header of that smaller block.

The nav tag

<nav> wraps a block of major navigation links. Not every group of links belongs in it; links inside the flow of an article do not need it. Use it for the menus users expect to reach quickly: main menu, category menu, table-of-contents links. A page can have more than one <nav>, for example a main menu and a footer menu.

The main tag

<main> wraps the content that is unique to this page. Three rules keep it correct:

  • A page should show only one visible <main> element at a time.
  • <main> must not be nested inside <header>, <nav>, <aside>, <article>, <section> or <footer>.
  • Content repeated across pages, such as menus and footers, stays outside it.

The footer tag

<footer> wraps closing information: contact details, copyright, related links. At the top level it acts as the page footer; inside an <article> it acts only as that article's footer, for example holding the author line and tags.


7. Grouping Content: section, article and aside

These three tags are the ones learners confuse most, because all three are block containers. The difference is the relationship between the content and the rest of the page.

TagMeaningTypical useCan it repeat?
<article>A self-contained piece that would still make sense on its own.Blog post, news story, product card, user comment.
<section>A thematic grouping of related content, almost always with its own heading.A "Syllabus" block, a "Reviews" block, a chapter of a longer page.
<aside>Content tangentially related to the surrounding content.Sidebar, tips box, pull quote, related links.

A quick test helps you choose. Ask: would this content make complete sense if I moved it to another page or syndicated it alone? If yes, it is an <article>. If it is just a themed chunk of the current page, it is a <section>. If it could be removed without breaking the main content, it is an <aside>. If none of those fit and you only need a hook for styling, that is what <div> is for.

<article>
  <h2>Learning CSS Grid</h2>
  <p>Grid layout lets you design two-dimensional layouts.</p>

  <section>
    <h3>Core concepts</h3>
    <p>Tracks, lines and areas are the three ideas to learn first.</p>
  </section>

  <aside>
    <p>Tip: practise Grid on a small card layout before
       trying a full dashboard.</p>
  </aside>
</article>

8. Smaller Semantic Tags for Specific Content

Besides the structural regions, HTML5 offers precise tags for specific kinds of content. Using them replaces generic markup with meaning.

figure and figcaption

<figure> wraps self-contained content referenced as a single unit: an image, a chart, a code listing or a diagram. <figcaption> holds its caption. The caption travels with the content, so if the figure moves, the caption moves too.

<figure>
  <img src="box-model.png" alt="Diagram of the CSS box model showing margin, border, padding and content" width="600" height="300">
  <figcaption>Figure 1: the four layers of the CSS box model.</figcaption>
</figure>

time

<time> marks a date or time in a machine-readable form through its datetime attribute, while the visible text stays human-friendly.

<p>The batch starts on <time datetime="2026-03-14">14 March</time>.</p>

mark

<mark> highlights text that is relevant in the current context, like the yellow highlight on search results. It means "pay attention to this, right here", not "make this yellow".

<p>Search results highlight the matching words with <mark>mark</mark>.</p>

details and summary

<details> creates a disclosure widget the user can open and close, and <summary> supplies the visible label. This behaviour is native to the browser: it works with no JavaScript and is keyboard accessible by default.

<details>
  <summary>Do I need prior JavaScript experience?</summary>
  <p>Basic JavaScript is covered in the foundations module
     before React begins.</p>
</details>

address

<address> holds contact information for the nearest <article> or for the whole page. It is for contact details, not for any postal-looking text.

<address>
  Questions? Write to <a href="mailto:[email protected]">[email protected]</a>
</address>

Note also that <strong> and <em>, which you may already use for bold and italic text, are semantic too: <strong> marks importance and <em> marks emphasis, which screen readers can convey through tone.


9. How a Browser Processes Semantic Tags, Step by Step

  1. The browser downloads the HTML file and parses it from top to bottom, building the DOM tree, where every tag becomes a node.
  2. Each semantic element is recognised with a built-in role: a top-level <header> is treated as the banner, <nav> as navigation, <main> as the main region and a top-level <footer> as the page's closing region.
  3. The browser derives the document outline from your headings and sectioning elements, so the page has a logical map: one <h1>, then <h2> and <h3> levels nested logically.
  4. The browser builds the accessibility tree from these roles, names and text; this is the version of the page that assistive technology reads.
  5. Default styles are applied. Semantic tags are block-level by default, so they behave visually like <div> elements until you style them; the meaning is in the markup, not the appearance.
  6. A screen reader user can now open a list of landmarks and jump directly to navigation or main content, skipping repeated menus.
  7. A search engine crawler parses the same structure to work out which text is the page's main content and which is repeated furniture.

The important insight from these steps is that semantic tags do their work before any CSS or JavaScript runs. You get the benefits by writing the markup correctly, not by styling it.


10. Worked Example: A Simple Blog Page

This complete page can be saved as an .html file and opened in any browser. It uses the skeleton plus a few of the smaller tags.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>My Learning Blog</title>
</head>
<body>
  <header>
    <h1>My Learning Blog</h1>
    <p>Notes from a web development journey</p>
  </header>

  <nav aria-label="Main navigation">
    <ul>
      <li><a href="#html">HTML</a></li>
      <li><a href="#css">CSS</a></li>
      <li><a href="#js">JavaScript</a></li>
    </ul>
  </nav>

  <main>
    <article>
      <header>
        <h2>Getting Comfortable with Semantic Tags</h2>
        <p>Posted on <time datetime="2026-03-14">14 March</time></p>
      </header>

      <p>Semantic tags describe what content means, not how it looks.</p>

      <section>
        <h3>Why structure matters</h3>
        <p>A clear structure helps readers, browsers and
           screen readers alike.</p>
      </section>

      <footer>
        <p>Filed under: <a href="#html">HTML</a></p>
      </footer>
    </article>
  </main>

  <aside>
    <h3>About this blog</h3>
    <p>Short lessons on web fundamentals, one topic at a time.</p>
  </aside>

  <footer>
    <address>
      Contact: <a href="mailto:[email protected]">[email protected]</a>
    </address>
  </footer>
</body>
</html>
  • The page has two footers, and both are correct: the inner one belongs to the article only, the outer one belongs to the page.
  • Same logic for the two headers: the article's <header> holds its title and date, while no page-level conflict arises.
  • The <time> tag keeps the human-friendly date visible while exposing a machine-readable value.
  • The <aside> is outside <main> because it is not unique page content.

11. Worked Example: A Realistic Course Page

Here is a fuller, realistic page combining most of the tags from this lesson, in the kind of layout you will later rebuild as React components.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>React JS Training - Course Overview</title>
</head>
<body>
  <header>
    <h1>React JS Training</h1>
    <nav aria-label="Course sections">
      <a href="#syllabus">Syllabus</a>
      <a href="#instructor">Instructor</a>
      <a href="#faq">FAQ</a>
    </nav>
  </header>

  <main>
    <article>
      <h2>Course Overview</h2>
      <p>This course takes you from web foundations to
         building interfaces with React.</p>

      <figure>
        <img src="roadmap.png" alt="Roadmap diagram: HTML, CSS, JavaScript, then React" width="600" height="300">
        <figcaption>The learning path from web foundations to React.</figcaption>
      </figure>

      <section id="syllabus">
        <h3>Syllabus</h3>
        <ol>
          <li>HTML5 and semantic markup</li>
          <li>CSS3 and responsive design</li>
          <li>JavaScript fundamentals and ES6</li>
          <li>Components, state and hooks in React</li>
        </ol>
      </section>

      <section id="instructor">
        <h3>Your Instructor</h3>
        <address>
          Questions? Write to
          <a href="mailto:[email protected]">[email protected]</a>
        </address>
      </section>

      <section id="faq">
        <h3>FAQ</h3>
        <details>
          <summary>Do I need prior JavaScript experience?</summary>
          <p>JavaScript fundamentals are covered before React begins.</p>
        </details>
      </section>
    </article>

    <aside>
      <h3>Quick facts</h3>
      <ul>
        <li>Format: online sessions</li>
        <li>Level: beginner friendly</li>
      </ul>
    </aside>
  </main>

  <footer>
    <p><small>Web Foundations: HTML, CSS &amp; JavaScript</small></p>
  </footer>
</body>
</html>
  • The top-level <header> contains the site title and the section menu, so the page has a banner and a navigation landmark.
  • Each syllabus part is a <section> with its own <h3>, which keeps the document outline clean.
  • The <figure> bundles the roadmap image with its caption, and the alt text describes the image for users who cannot see it.
  • The FAQ uses <details> and <summary>, giving an interactive accordion with zero JavaScript.
  • The <aside> holds supporting facts, separate from the article's own flow.

12. Common Mistakes to Avoid

  • Using <section> as a styling wrapper. A <section> should represent a thematic block, and it usually needs a heading. If you only need a hook for CSS, use <div>.
  • Adding more than one visible <main>. If you need to show parts of several pages, keep one visible <main> and manage the rest with the hidden attribute or JavaScript.
  • Wrapping every small item in <article>. A paragraph inside a post is not an article. Reserve <article> for content that stands on its own.
  • Expecting nested headers and footers to act as page landmarks. A <header> or <footer> inside an <article> describes only that article, not the page.
  • Nesting <main> inside other structural tags. Keep <main> as a direct child of <body> in a normal page layout.
  • Choosing semantic tags for their default styles. The tags are unstyled block containers until CSS is applied; their value is meaning, not appearance.
  • Skipping headings inside sections. An unlabelled <section> loses most of its value, since the heading is what announces what the group is about.

A compact wrong-versus-right pair for the most common case:

<!-- Wrong: a styled box pretending to be meaningful content -->
<section class="sidebar-box">
  <p>Quick facts about the course.</p>
</section>

<!-- Right: no fake meaning; a wrapper is honestly a wrapper -->
<div class="sidebar-box">
  <p>Quick facts about the course.</p>
</div>

13. How Semantic Tags Support Accessibility and SEO

Two audiences reward semantic markup immediately. The first is people using assistive technology. Because each landmark tag maps to a recognised role, a screen reader can list the page's regions and let the user jump: "navigation, main, contentinfo". A visitor who hears the same menu read out on every page can skip it, because your markup told the software where the main content begins. Interactive tags such as <details> are focusable and operable from the keyboard without any extra code.

The second audience is search engines. Crawlers read raw HTML, and semantic structure lets them distinguish the unique main content from navigation bars and footers that repeat on every page. Headings inside <section> and <article> elements feed the document outline, which helps a crawler understand what each block of text is about.

Keep the practical habit simple: when a meaning fits, use the semantic tag; when no meaning fits, use <div> or <span> without guilt. The later pages of this module, on accessibility basics and SEO-friendly markup, build directly on the structure you have learned here.

14. Choosing the Right Tag: A Decision Workflow

Part 1 gave you the vocabulary; this part is about using it confidently in real projects. The most common question in practice is "which tag do I use here?" Rather than memorising a list, walk through a short decision chain every time you are about to type <div>:

  1. Ask what the content means, not how it should look.
  2. If it is the unique content of this page, it belongs inside <main>.
  3. If it would still make sense on its own, moved to another page or site, use <article>.
  4. If it is a themed group within this page and has its own heading, use <section>.
  5. If it is related but removable, use <aside>.
  6. If it is a major block of navigation links, use <nav>.
  7. If a smaller tag matches exactly (<time>, <figure>, <address>, <mark>, <details>), use it.
  8. Only when no meaning fits, reach for <div> or <span>.
SituationTag to reach for
Unique main content of the page<main>
Page banner: logo, site title, tagline<header>
Major block of navigation links<nav>
Self-contained story, card or comment<article>
Themed group with its own heading<section>
Tangential supporting content<aside>
Contact information<address>
Image, chart or code listing with a caption<figure> with <figcaption>
A date or time in the text<time>
Pure grouping for styling or scripting<div> or <span>

The workflow takes seconds once it becomes a habit, and it removes the guesswork that makes beginners fall back into "div soup".


15. Advanced Usage: Nested Articles, Multiple Landmarks and Rich Captions

Real pages need the same tags more than once, and HTML5 is designed for that. Three patterns cover most real-world needs.

Nested articles for comments

A comment on a blog post is itself a self-contained piece of content, so each comment can be its own <article> nested inside the post's <article>. The nesting itself expresses the relationship: these articles belong to that article.

<article>
  <h2>Understanding Flexbox</h2>
  <p>A flex container lays out its children along one axis.</p>

  <section>
    <h3>Comments</h3>

    <article>
      <header>
        <h4>Comment by Priya</h4>
        <p><time datetime="2026-03-15">15 March</time></p>
      </header>
      <p>The main-axis and cross-axis explanation finally
         made flexbox click for me.</p>
    </article>

    <article>
      <header>
        <h4>Comment by Arjun</h4>
        <p><time datetime="2026-03-16">16 March</time></p>
      </header>
      <p>The axis diagram cleared up my doubt too.</p>
    </article>
  </section>
</article>

Multiple nav elements with labels

A large page often has a main menu, a breadcrumb trail and pagination. Each is a genuine navigation block, so each can be a <nav>. Give each one an aria-label so assistive technology can announce which is which; otherwise users hear three identical "navigation" landmarks.

<nav aria-label="Main">
  <a href="/">Home</a>
  <a href="/courses">Courses</a>
</nav>

<nav aria-label="Breadcrumb">
  <a href="/">Home</a> &gt;
  <a href="/html">HTML</a> &gt;
  <a href="/html/semantic-tags">Semantic tags</a>
</nav>

<nav aria-label="Pagination">
  <a href="?page=1">1</a>
  <a href="?page=2">2</a>
  <a href="?page=3">3</a>
</nav>

Figures around code listings and charts

A <figure> is not only for images. Any self-contained unit that is referenced from the surrounding text qualifies, including a code listing with its caption:

<p>Centering with Flexbox needs only three declarations,
   as shown in the listing below.</p>

<figure>
  <figcaption>Listing: one-line centring with Flexbox</figcaption>
  <pre><code>.parent {
  display: flex;
  justify-content: center;
  align-items: center;
}
</code></pre>
</figure>

If the figure moves to another part of the page, the caption and the code travel with it as one unit, which is exactly what the <figure> wrapper guarantees.


16. Testing Your Semantic Structure

Because semantic tags work before CSS and JavaScript run, you can verify them with simple checks on any page you build:

  • Check the landmark list. Browser developer tools include an accessibility inspector that shows the role of each element and the page's landmarks. You should see exactly one main region, plus navigation and the banner and contentinfo regions at page level.
  • Check the heading outline. Read only the <h1> to <h6> tags in order. They should read like a table of contents for the page, with no skipped levels.
  • Test with the keyboard. Press <kbd>Tab</kbd> and walk through the page. Links, and the disclosure control created by <details>, should take focus in a sensible order.
  • Remove the CSS. Temporarily disable styles. If the page still reads in a logical order, your markup carries the structure and not just the stylesheet.
  • Validate the HTML. Free validators such as the W3C Markup Validation Service report structural errors, such as a <main> nested in the wrong place, before they reach users.

These five checks take a few minutes and catch almost every structural mistake a beginner makes.


17. Semantic Tags Inside React Components

This course leads to React, and semantic tags follow you there. A React component is a function that returns markup; when it renders, that markup becomes real HTML in the browser's DOM. If the component returns semantic tags, every instance it renders carries the same meaning as a hand-written HTML page.

JSX, the syntax React uses, looks like HTML with two differences you will meet properly later: the class attribute is written className, and camelCase is used for attributes such as datetime, which becomes dateTime.

function SiteHeader() {
  return (
    <header className="site-header">
      <h1>JustAcademy Notes</h1>
      <nav aria-label="Main">
        <a href="/">Home</a>
        <a href="/notes">Notes</a>
      </nav>
    </header>
  );
}

function ArticleCard({ title, excerpt, postedOn }) {
  return (
    <article className="card">
      <header>
        <h2>{title}</h2>
        <time dateTime={postedOn}>{postedOn}</time>
      </header>
      <p>{excerpt}</p>
    </article>
  );
}

Two things are worth noticing now. First, a component named SiteHeader is not the same as the <header> tag it returns: the component is your reusable React unit, while the tag is what actually reaches the browser. Second, when ArticleCard renders once per item in a list, each card becomes its own <article>, so the semantic structure scales automatically with your data. This is exactly the kind of small, single-purpose component that modern React best practices encourage.


18. Common Mistakes and the Correct Way

Each mistake below shows the broken pattern and the correction. These are different from the ones listed in the first half of this page, so together they form a fuller checklist.

Putting minor link lists inside nav

<nav> is for major navigation blocks. A footer list of social media links is usually not major navigation, and marking it as such adds a noisy extra landmark that dilutes the useful ones.

<!-- Wrong: an extra landmark nobody needs -->
<footer>
  <nav>
    <a href="/twitter">Twitter</a>
    <a href="/github">GitHub</a>
  </nav>
</footer>

<!-- Right: a simple list inside the footer -->
<footer>
  <ul>
    <li><a href="/twitter">Twitter</a></li>
    <li><a href="/github">GitHub</a></li>
  </ul>
</footer>

Wrapping unrelated content in one article

A dashboard that shows weather and currency rates side by side does not contain one "story". An <article> here misleads both screen readers and crawlers into treating the group as one self-contained work.

<!-- Wrong: two unrelated topics forced into one article -->
<main>
  <article>
    <h2>Today's weather</h2>
    <p>Cloudy with light rain expected.</p>
    <h2>Currency rates</h2>
    <p>Check the latest exchange rates here.</p>
  </article>
</main>

<!-- Right: one section per theme, each with a heading -->
<main>
  <section>
    <h2>Today's weather</h2>
    <p>Cloudy with light rain expected.</p>
  </section>
  <section>
    <h2>Currency rates</h2>
    <p>Check the latest exchange rates here.</p>
  </section>
</main>

Using time without the datetime attribute

Without datetime, a <time> element is just text; the machine-readable value is what makes the tag worth using.

<!-- Wrong: no machine-readable value -->
<p>The batch starts on <time>14 March 2026</time>.</p>

<!-- Right: human text plus a machine-readable date -->
<p>The batch starts on <time datetime="2026-03-14">14 March 2026</time>.</p>

Hiding essential content inside details

<details> hides its content until the user opens it. Content that every visitor must see, such as pricing or the main instructions of a form, must not start hidden.

<!-- Wrong: critical information hidden behind a click -->
<details>
  <summary>Course fee details</summary>
  <p>The full fee structure and schedule.</p>
</details>

<!-- Right: essential content visible; details only for extras -->
<section>
  <h3>Course fee details</h3>
  <p>The full fee structure and schedule.</p>
</section>

<details>
  <summary>What should I bring to the first session?</summary>
  <p>A laptop with a modern browser installed.</p>
</details>

Styling semantic tags with bare selectors everywhere

<header> can appear at page level and inside every article. A bare header { } rule in CSS hits all of them, so the markup becomes hostage to the stylesheet.

<!-- Markup that is hard to style safely -->
<header>
  <h1>Site name</h1>
</header>

<article>
  <header>
    <h2>Post title</h2>
  </header>
</article>
/* Wrong: styles every header on the page */
header {
  background: #123;
  color: white;
}

/* Right: style the role, not the tag */
.site-header {
  background: #123;
  color: white;
}
<header class="site-header">
  <h1>Site name</h1>
</header>

The tag still carries meaning; the class carries the appearance. Meaning and styling stay independent, which is the whole point of semantics.


19. Best Practices for Semantic Markup

  • Write the structure first, the styling later. Choose tags by meaning during drafting, then attach CSS. Retrofitting semantics onto styled markup is slow and error-prone.
  • Keep one visible <main> and one top-level <h1> per page. They anchor both the landmark map and the heading outline.
  • Label repeated landmarks. When a page has several <nav> elements, give each an aria-label that says what it navigates.
  • Give every meaningful image an alt attribute, and put visible captions in <figcaption> so the caption is structurally tied to the image.
  • Prefer native behaviour. <details> and <summary> replace small JavaScript accordions with markup that works before any script loads.
  • Do not over-semantise. Forcing <article> or <section> onto content with no such meaning is as unhelpful as using only <div>. An honest wrapper is better than a fake meaning.
  • Pair <time> with datetime whenever the value is a real date or time.
  • Keep headings inside their sections. Every <section> should introduce itself with a heading, and heading levels should not skip.
  • Co-locate related markup. A component's header, body and footer markup should live together, whether in one HTML file or one React component, so the structure is readable at a glance.

20. Practical Project: A Semantic Portfolio Page

Build a one-page personal portfolio using only the tags from this module. It is small enough to finish in one sitting and realistic enough to keep as the first page of your portfolio site.

Step 1: Create the file and skeleton

Create a folder named portfolio, and inside it a file named index.html. Start with the standard skeleton from Part 1: DOCTYPE, <html lang="en">, a <head> with charset and title, and an empty <body>.

Step 2: Add the page header and main navigation

Inside <body>, add a top-level <header> with your name as the <h1>, and a <nav aria-label="Main"> whose links point to the section id values you will create in step 3.

Step 3: Add the main content in three sections

Add <main> containing three <section> elements, each with an id and an <h2>: about (with a <figure> portrait and <figcaption>), projects (with one <article> per project, each having its own <footer> line), and contact (with an <address> holding an email link).

Step 4: Add the aside

After <main>, add an <aside> with a short "Quick facts" list. It sits outside <main> because it is supporting content, not unique page content.

Step 5: Add the page footer

Close with a top-level <footer> containing a copyright line in a <small> tag.

Step 6: Verify the structure

Open the file in a browser, then run the checks from the "Testing Your Semantic Structure" section: inspect landmarks, read the heading outline, and press <kbd>Tab</kbd> to confirm the navigation links and email link receive focus.

Complete code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Asha Verma - Web Developer Portfolio</title>
</head>
<body>
  <header class="site-header">
    <h1>Asha Verma</h1>
    <p>Web developer in training</p>
    <nav aria-label="Main">
      <a href="#about">About</a>
      <a href="#projects">Projects</a>
      <a href="#contact">Contact</a>
    </nav>
  </header>

  <main>
    <section id="about">
      <h2>About Me</h2>
      <figure>
        <img src="asha.png" alt="Portrait of Asha Verma"
             width="240" height="240">
        <figcaption>Learning web foundations, one module at a time.</figcaption>
      </figure>
      <p>I am learning HTML, CSS and JavaScript, and building
         small projects to practise each concept.</p>
    </section>

    <section id="projects">
      <h2>Projects</h2>

      <article>
        <h3>Recipe Finder Page</h3>
        <p>A static page listing recipes, built with semantic
           structure and a working search form.</p>
        <footer>
          <p>Built with: HTML and CSS</p>
        </footer>
      </article>

      <article>
        <h3>Study Timer</h3>
        <p>A small JavaScript app that counts focus sessions.</p>
        <footer>
          <p>Built with: HTML, CSS and JavaScript</p>
        </footer>
      </article>
    </section>

    <section id="contact">
      <h2>Contact</h2>
      <address>
        Email: <a href="mailto:[email protected]">[email protected]</a>
      </address>
    </section>
  </main>

  <aside>
    <h2>Quick Facts</h2>
    <ul>
      <li>Focus: front-end foundations</li>
      <li>Currently learning: React</li>
    </ul>
  </aside>

  <footer>
    <p><small>Copyright Asha Verma. Built with semantic HTML.</small></p>
  </footer>
</body>
</html>

Save the file and open it in any browser; no server is needed. Every landmark from this module appears exactly where it should, and the page is a clean base to style in the CSS3 module.


21. Practice Exercises

  1. Take any "div soup" snippet you wrote earlier and rewrite it using the decision workflow from the start of this part. Note which <div> elements you kept, and why no meaning fitted them.
  2. Write a blog post page with three nested comment <article> elements, each containing a <time> with a datetime attribute.
  3. Build a documentation page with one <nav> linking to three <section> blocks, and include a <figure> that wraps a code listing with a <figcaption>.
  4. Create a FAQ section using three <details> and <summary> pairs, then confirm with the keyboard alone that each can be opened and closed.
  5. Build a page with a main menu and a pagination block as two separate <nav> elements, labelled with distinct aria-label values.
  6. Audit one page from a previous module: list every <div> in it, replace the ones where a meaning fits, and write down what stayed a <div> and why.

22. Interview Questions and Answers

What are semantic tags and why do they matter?

Semantic tags are HTML tags whose names describe their content, such as <article>, <nav> and <footer>. They matter because the meaning is machine-readable: screen readers can offer landmark navigation, search engines can separate main content from repeated page furniture, and developers can read and maintain the structure without relying on class names.

What is the difference between section and article?

An <article> is self-contained content that would make sense on its own, such as a blog post, a product card or a comment. A <section> is a thematic grouping that belongs to its page and usually needs its own heading. The quick test: if the content could be syndicated or moved elsewhere and still make sense, it is an <article>.

When should you still use a div or a span?

When no semantic meaning fits and you only need a hook for styling or scripting. A <div> groups block content and a <span> groups inline content, with no meaning attached. Using them honestly is better than faking meaning with the wrong semantic tag.

What is the difference between header and head?

<head> is the invisible metadata container of the document, holding the title, charset and links; nothing inside it renders on the page. <header> is visible introductory content, and it may appear multiple times, including inside articles and sections.

Can a page have more than one nav or header element?

Yes. Only <main> is limited to one visible instance. Multiple <nav> elements should be distinguished with aria-label values, and a <header> or <footer> nested inside an article or section scopes to that block rather than to the whole page.

What are the rules for the main element?

<main> contains content unique to the page. There should be only one visible <main> at a time, it must not be nested inside other landmark tags such as <header>, <nav>, <aside>, <article>, <section> or <footer>, and content repeated across pages, like menus and footers, stays outside it.

What are landmarks in accessibility?

Landmarks are recognised page regions that assistive technology lists and can jump between, such as navigation, main and complementary. Semantic tags map to these roles automatically, so a screen reader user can skip repeated menus and reach the main content directly.

Why use figure and figcaption instead of a plain img?

<figure> bundles a self-contained unit, such as an image, chart or code listing, with its caption in <figcaption>. The caption is structurally tied to the content, so the pair moves and is announced together, instead of relying on a nearby paragraph that could drift away.

What does the datetime attribute on the time tag do?

It stores a machine-readable date or time, such as 2026-03-14, while the visible text stays human-friendly, such as "14 March 2026". Browsers, crawlers and scripts can process the attribute's value reliably without parsing the displayed text.

What do details and summary provide without JavaScript?

A native disclosure widget: <summary> is the visible label and the rest of the <details> content is shown when the user opens it. It is keyboard accessible out of the box, which is why it should replace small script-built accordions for supplementary content.

How do semantic tags help SEO?

Crawlers read raw HTML and use semantic structure to tell unique main content apart from navigation and footers that repeat on every page. Headings inside sections and articles feed the document outline, helping the crawler understand what each block of text is about, which supports better relevance matching.

How do strong and em differ from b and i?

<strong> marks importance and <em> marks emphasis, so they carry meaning that assistive technology can convey. <b> and <i> draw attention or offset text visually without adding meaning. When the bold or italic exists for a reason, use the semantic pair; use <b> or <i> only for purely visual convention.


23. Quick Revision Checklist

  • I can define "semantic" in one sentence: the tag name describes the meaning of its content.
  • I know the landmark tags <header>, <nav>, <main>, <aside> and <footer>, and what each role does.
  • I can choose between <article>, <section> and <aside> using the "does it stand alone?" test.
  • I use <time> with datetime, <figure> with <figcaption>, <mark>, <address>, <details> and <summary> where they fit.
  • My pages have one visible <main> and one top-level <h1>.
  • I know that nested <header> and <footer> elements scope to their article or section.
  • I label multiple <nav> elements with aria-label.
  • I keep minor link lists out of <nav> and never fake meaning with <section> or <article>.
  • I never hide essential content inside <details>.
  • I style through classes, not bare semantic tag selectors.
  • I can render semantic tags from a React component using className and dateTime.
  • I can verify structure with developer tools, the keyboard and by removing CSS.

24. Official Documentation and Further Reading

For HTML semantics, the references used across the industry are the MDN Web Docs HTML elements reference and the WHATWG HTML Living Standard; search for them by name whenever you need the exact rules for a tag. The reading list below comes from your course resources and connects the structure you have learned here to the React training it prepares you for:


Conclusion

Semantic tags are a habit of naming things correctly. Once you have the decision chain in mind, writing <main>, <article> and <nav> costs no more effort than writing <div>, but it pays out continuously: clearer code for your team, landmark navigation for screen reader users, cleaner content for crawlers, and a head start when that same structure reappears inside your React components. Keep the workflow, the mistake list and the revision checklist from this page close at hand, because the next two pages of this module, on accessibility basics and SEO-friendly markup, build directly on the structure you can now write without thinking about it.

Learn more in the React JS Training course, or register for a course demo.

Previous Next
whatsapp