smartyfy.mrindigi.com

Web Development Pro | Lesson 002 | A Semantic HTML Document

Web Development Pro · Lesson 02 of 60

Module 1: HTML foundations

In this lesson

Prerequisites and learning outcomes

Complete lesson 1 first. This lesson builds on document skeleton and landmarks. By the end, you can build a valid document with language, title, headings, and main content. Plan 10–15 minutes for the core explanation and additional time for the worked practice.

Give the browser a meaningful document

The repair group now needs a page with a name, introduction, session details, and contact information. You could wrap every line in a generic container and enlarge some words with CSS. It might look plausible, but the document would explain little about itself. Semantic HTML uses elements whose meanings match their contents. A heading is a heading even before you choose a font size; navigation remains navigation on a narrow screen.

Semantics help people scanning visually, navigating with assistive technology, or reading a stripped-down view. They also give future developers a clearer starting point. They are not a promise that the whole page is accessible. Poor link names, missing image alternatives, or inaccessible custom controls can still create barriers inside an otherwise semantic document.

Understand the outer structure

The doctype selects modern standards mode. The html element contains the document and carries the primary language. The head supplies metadata such as character encoding and title. The body holds the page content. Put the charset declaration near the start of the head. Use a descriptive title that distinguishes this page in browser tabs and history, rather than naming every page “Home.”

The title and h1 serve different places. A title such as “Repair Workshop | River Community” identifies the tab. The visible h1 may simply say “Repair Workshop.” They should agree about the page's purpose without needing identical wording. A misleading tab title makes a multi-tab workflow harder even when the visible heading is correct.

Choose landmarks before decoration

A header can introduce a page or a section. A nav identifies a major navigation block. The main element represents the dominant page content; this course uses one visible main per page. A footer can contain information about its nearest section or the page. Do not place a main inside header, nav, or footer. A landmark is about purpose, not a box's position or color.

Use section for a thematic grouping, normally with a heading. Use article for content that can stand independently, such as an individual workshop announcement. Use div when you only need a grouping hook and no more specific meaning fits. Giving every wrapper a section tag does not create useful structure. The reader should understand why a boundary exists.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Repair Workshop | River Community</title>
</head>
<body>
  <header>
    <p>River Community</p>
    <nav aria-label="Main">
      <a href="index.html">Home</a>
      <a href="#sessions">Sessions</a>
    </nav>
  </header>
  <main id="main-content">
    <h1>Repair Workshop</h1>
    <p>Learn practical repair skills with neighbors.</p>
    <section id="sessions">
      <h2>Sessions</h2>
      <h3>Bicycle basics</h3>
      <p>Inspect tires and learn how to patch a tube.</p>
    </section>
  </main>
  <footer><p>Practice website with fictional events.</p></footer>
</body>
</html>

The nav label distinguishes its purpose if the page eventually has several navigation landmarks. Native elements already supply many roles; do not add role="navigation" to nav merely to repeat its built-in meaning. ARIA can supply missing names and states, but it cannot repair a poorly chosen element's keyboard behavior automatically. Learn the native option first.

Make the heading outline tell the story

Use the main page heading at h1, major sections at h2, and subsections at h3. The example's Bicycle basics belongs under Sessions. Do not choose h3 because its default size happens to look better. CSS will control appearance later. A heading sequence should make sense when read without the paragraphs underneath it.

Heading levels are not automatically repaired by placing headings inside section. Write the intended levels explicitly. An h2 followed by h4 can signal a missing organizational level, though the actual usability impact depends on context. For these small pages, a straightforward hierarchy is easier to author and review than a complex outline with unexplained jumps.

Validate your reasoning

Before adding style, read just the title, landmarks, and headings. Can you tell what the page is about, where its main information begins, and how its sections relate? Then inspect the actual DOM, because browsers can silently recover from invalid nesting. Putting a paragraph inside another paragraph, for example, can produce a tree different from the indentation in your file.

Automated parsers can detect structural facts such as duplicate ids or a missing title. They cannot decide whether “Things” is a useful heading for a visitor trying to find a bicycle class. Combine machine checks with a content review. Keep that distinction in your notes so a passed syntax check is never presented as complete accessibility testing.

Worked practice

Worked exercise 1: Choose a container

Task: Group the site logo and main navigation at the top of the page. Worked answer: use a page header containing a nav for the navigation links. A div might group them visually, but header and nav communicate their purposes. The logo's exact alternative text depends on whether nearby text already names the site.

Worked exercise 2: Repair heading order

Task: A page has h1 “Workshops,” h2 “Repair,” and h1 “Bicycle basics.” Worked answer: change Bicycle basics to h3 if it is a subsection of Repair. If it is a peer major section instead, use h2. The correct choice follows the content relationship rather than the desired font size.

Worked exercise 3: Separate metadata from content

Task: The browser tab says “Untitled,” while the page visibly says “Repair Workshop.” Worked answer: add or fix the title element inside head. Changing the h1 alone does not reliably supply the desired tab title. Reopen the page and check both the tab and the visible heading to confirm the two contexts.

Knowledge check

Question 1

What belongs in head? A) The main workshop description. B) A page title and metadata. C) All visible navigation. D) The visible session heading.

Check question 1: answer and explanation

Answer: B. Head describes the document; body contains its displayed content.

Question 2

Which element best identifies dominant page content? A) main. B) header. C) section. D) div.

Check question 2: answer and explanation

Answer: A. Main describes the page's primary content rather than a presentational grouping.

Question 3

Why choose h2 instead of h3? A) Its default font is nicer. B) It gives the text more visual emphasis without affecting hierarchy. C) It is a major section below h1. D) It is the next heading written after any h1, regardless of content.

Check question 3: answer and explanation

Answer: C. Heading levels describe hierarchy, which CSS styling should preserve.

Question 4

When is div appropriate? A) Whenever text should appear as a major heading. B) When no more meaningful grouping element fits. C) Whenever a group contains links, regardless of their purpose. D) Whenever an action control needs a custom appearance.

Check question 4: answer and explanation

Answer: B. Div is a generic container; it does not supply interaction or a content role.

Question 5

Does a successful static parser check prove full accessibility? A) Yes, because a parser checks the same experience as a person. B) Yes, if the document has no duplicate ids. C) Yes, if every page has a descriptive title. D) No.

Check question 5: answer and explanation

Answer: D. Content meaning, keyboard behavior, visual contrast, and assistive-technology experience require additional checks.

Sources and further reading