Thuta Learning
HTML
ExercisesWeb DevelopmentBeginner

Practice: Forms, Tables & Semantic Layout

HTMLLesson 3845 min

What you'll walk away with

  • Arrange header, nav, main, article and footer to match the parts of a page
  • Write a form with labels, names, types and required, and test it with checkValidity()
  • Build a table with a caption, scope="col" and scope="row"
  • Write a JavaScript-free FAQ with details and summary

Explain it simply

Explain it simply

Building a house takes more than knowing bricklaying, plumbing and wiring separately. You must think about how pipes and cables pass through the same walls at the same time.

This lesson works the same way. Landmarks are the room layout, the table is a timetable on the wall, the form is the mailbox by the door, and the FAQ is a cupboard of folded-away answers. You fit all of them onto one page without letting them get in each other's way.

Problem → Why → Solution

The problem: a page tested only on the happy path

Whoever wrote the page below filled in a correct name and email, submitted once, and decided "it works". But the whole page is built from divs, so a screen reader user cannot jump to the main content.

The email field has no name, so the server never receives the email. The table's header row uses td, so a screen reader cannot announce "Time" or "Session" as it moves through the cells. Nobody tried a wrong email or an empty submit.

workshop-draft.html
<div class="header">City Library</div>
<div class="content">
  <table>
    <tr><td>Time</td><td>Session</td></tr>
    <tr><td>10:00</td><td>Light and framing</td></tr>
  </table>
  <form action="/workshops/register">
    Name <input type="text" name="name">
    Email <input type="text">
    <button>Reserve</button>
  </form>
</div>

Why one successful submit proves little

A successful submit only proves that correct data gets sent. Wrong data, missing data, keyboard users and screen reader users remain untested, and real users spend much of their time in exactly those situations.

Core concept: design three layers at once

This page has three layers: landmarks on the outside, content components inside them (table, form, FAQ), and the internal links within each component (label to input, th to td). Settle each layer before you write code.

1. The landmark map

The site name and navigation go in header, this page's unique content goes in main, and copyright and contact details go in footer. A page has exactly one visible main. The workshop itself is a self-contained piece of content you could share on its own, so it sits in an article.

2. The form data contract

First write down the keys the server expects (name, email). Then give each control that name, a fitting type, required, and a label linked by for/id. type="email" checks the basic format; add a pattern attribute only when you need a stricter rule.

3. Table header relationships

The caption is the table's title. Header cells in the first row get scope="col", and the first cell of each row, the time that identifies it, becomes th scope="row". A screen reader can then announce both "11:30" and "Session" when it reaches the "Photo walk" cell.

4. Native disclosure

Clicking the summary inside details toggles the answer. Enter or Space works from the keyboard, and screen readers announce the expanded or collapsed state, all without a single line of JavaScript.

Case to testExpected result
Submit an empty formBrowser stops at the first field with a message
Enter "aye@" as the emailAsks for the part after the @
Use only the Tab keyReaches every link, field, button and summary
Mental model: house, rooms, fittings
  1. Draw the house with landmarks
  2. Place components inside main
  3. Link label/input and th/td
  4. Test wrong, missing, keyboard cases

Each component carries its own internal links, while landmarks tell users where to find the components.

General pattern

html
<header>site name + <nav>...</nav></header>
<main>
  <article>
    <h1>Topic</h1>
    <table><caption>Title</caption> <th scope="col">...</th> ...</table>
    <form action="/endpoint" method="post"> label + named, typed control ... </form>
    <details><summary>Question?</summary><p>Answer.</p></details>
  </article>
</main>
<footer>contact, copyright</footer>

Landmarks form the outer shell, the article holds the table, form and details components, and each component brings its own semantic links: caption and scope, label and name, summary.

Worked answer: a library workshop page

This page answers the exercise's four tasks using a library photography workshop. Task 1 is the landmark layout, Task 2 the registration form, Task 3 the schedule table and Task 4 the FAQ. There is no server code at /workshops/register, so a real submit ends on an error page, which is expected.

workshop.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Intro to Photography Workshop | City Library</title>
</head>
<body>
  <header>
    <p><a href="/">City Library</a></p>
    <nav aria-label="Main">
      <a href="/events">Events</a> | <a href="/visit">Visit us</a>
    </nav>
  </header>

  <main>
    <article>
      <h1>Intro to Photography Workshop</h1>
      <p>A free Saturday workshop for beginners. Bring any phone or camera.</p>

      <table>
        <caption>Saturday schedule</caption>
        <thead>
          <tr><th scope="col">Time</th><th scope="col">Session</th>
              <th scope="col">Room</th></tr>
        </thead>
        <tbody>
          <tr><th scope="row">10:00</th><td>Light and framing</td><td>Hall A</td></tr>
          <tr><th scope="row">11:30</th><td>Photo walk</td><td>Front garden</td></tr>
          <tr><th scope="row">14:00</th><td>Editing on your phone</td><td>Hall A</td></tr>
        </tbody>
      </table>

      <h2>Reserve a seat</h2>
      <form action="/workshops/register" method="post">
        <label for="reg-name">Name</label>
        <input id="reg-name" name="name" type="text" autocomplete="name" required>

        <label for="reg-email">Email</label>
        <input id="reg-email" name="email" type="email" autocomplete="email" required>

        <button type="submit">Reserve my seat</button>
      </form>

      <h2>FAQ</h2>
      <details>
        <summary>Do I need my own camera?</summary>
        <p>No. A phone camera is enough for every session.</p>
      </details>
    </article>
  </main>

  <footer>
    <p>City Library, open daily 9am to 6pm</p>
  </footer>
</body>
</html>

Code breakdown

  1. Labelled navigation<nav aria-label="Main">

    nav is the navigation landmark. Pages often have more than one, so a name like aria-label="Main" lets a screen reader announce "Main navigation" and tell them apart.

  2. Table title<caption>Saturday schedule</caption>

    caption must be the table's first child. Screen readers read it as soon as the user enters the table, and it appears as text above the table.

  3. Row header<tr><th scope="row">11:30</th><td>Photo walk</td><td>Front garden</td></tr>

    11:30 identifies this row, so it is th scope="row" rather than td. On the "Front garden" cell a screen reader can relate it to both headers, "11:30" and "Room".

  4. Form contract<form action="/workshops/register" method="post">

    On submit it POSTs a body of name=...&email=... to /workshops/register. The server reads those two keys, validates them again and records the seat.

  5. Typed, named, required<input id="reg-email" name="email" type="email" autocomplete="email" required>

    id links the label, name is the server key, type="email" checks the format, autocomplete offers the saved address and required forbids an empty value. Each attribute does one separate job.

  6. Native FAQ<summary>Do I need my own camera?</summary>

    summary is details' first child and the clickable question. details starts closed by default; add the open attribute if the answer should be visible on load.

You should see
At the top: a "City Library" link and Events | Visit us links. Below: the large heading "Intro to Photography Workshop", a three-row table captioned "Saturday schedule" (bold Time, Session and Room headers and bold times), Name and Email fields with a "Reserve my seat" button, a collapsed "Do I need my own camera?" FAQ with a triangle marker, and the footer line. Pressing the button with empty fields is blocked by the browser.

Testing your page in five minutes

Once the page is done, do not stop at "it shows up in the browser". You can test all three components from this lesson with nothing but DevTools and the keyboard; no extra tools need installing.

1. Ask the form in the Console

In the DevTools Console, run document.forms[0].checkValidity(). It should return false with empty fields and true only once everything is filled in correctly. Inspecting new FormData(document.forms[0]) shows that only fields with a name are included.

2. Look at the accessibility tree

Select an input and open the Accessibility tab in the Elements panel: its accessible name should be the label text. Select a th and its role should be columnheader or rowheader.

3. Go end to end without a mouse

Fill the fields with Tab, open the FAQ with Space and submit with Enter. The focus ring must stay visible throughout, and focus must never get stuck anywhere.

In real projects

In real projects

Event pages, course sign-up pages and clinic booking pages all combine these four patterns: a schedule table, a registration form, frequently asked questions and the site-wide header and footer. On government and public-service websites accessibility is often a legal requirement, so audits always check table headers and form labels.

Before shipping a form, teams inspect the submission payload in the DevTools Network tab and confirm the keys with the backend developer. Invalid data, server errors and the keyboard-only flow are documented in the ticket with screenshots or notes as evidence.

When content editors update a schedule in a CMS, teams usually fix the th cells and the caption in the template and let editors change only the row data, so the table structure cannot be broken by accident.

Common mistakes

Common mistakes

Writing table headers with td

A bold td looks like a header but is a plain data cell to a screen reader. Hearing "Hall A" in a twenty-row table, the user cannot tell which column it belongs to. Write every header as a th with a scope.

Misplacing landmarks

Several mains, site navigation inside main or a footer inside main all scramble the landmark map. A screen reader user who chooses "jump to main content" lands among navigation links and has to start over.

Thinking type="email" proves the address exists

The browser checks the format only and even accepts "a@b" as valid. To know the address really exists, the server sends a confirmation email and asks the person to click a link.

Mini challenge

Build the repair café page

Write a page for a monthly repair café, an event where volunteers fix broken items for free. It must meet the four original tasks, without copying the workshop example.

  • Task 1: header, main and footer, with an article inside main
  • Task 2: a contact form with name, email (type="email", required) and a message textarea, each with a label
  • Task 3: a table with a caption, scope="col" headers and three data rows
  • Task 4 (bonus): a details/summary FAQ inside the article
repair-cafe.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Practice Layout</title>  <!-- TODO: a title naming the repair café -->
</head>
<body>
  <!-- TODO (Task 1): header with the event name -->
  <!-- TODO (Task 1): main > article with an h1 and an intro paragraph -->
  <!--   TODO (Task 3): table: caption, th scope="col", three data rows -->
  <!--   TODO (Task 2): form action + method="post"; name, email, message -->
  <!--   TODO (Task 4): details/summary FAQ -->
  <!-- TODO (Task 1): footer -->
</body>
</html>

Expected: You see a header, an article in main (h1, captioned table, form and FAQ) and a footer. An empty form is blocked by the browser, and checkValidity() returns true only after a valid name, email and message are filled in.

Show hint

For the table, think of three columns such as item type, volunteer and table number. A textarea is labelled exactly like an input, with for and id.

Show solution
repair-cafe.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Riverside Repair Café | First Sunday of every month</title>
</head>
<body>
  <header>
    <p>Riverside Repair Café</p>
  </header>

  <main>
    <article>
      <h1>Bring it broken, take it home fixed</h1>
      <p>Volunteers repair small items for free, 1pm to 5pm on the first Sunday.</p>

      <table>
        <caption>Repair tables</caption>
        <tr>
          <th scope="col">Item type</th>
          <th scope="col">Volunteer</th>
          <th scope="col">Table</th>
        </tr>
        <tr><td>Lamps and radios</td><td>Ko Zaw</td><td>1</td></tr>
        <tr><td>Clothes and bags</td><td>Daw Hla</td><td>2</td></tr>
        <tr><td>Bicycles</td><td>Mg Thant</td><td>3</td></tr>
      </table>

      <h2>Ask the organisers</h2>
      <form action="/repair-cafe/contact" method="post">
        <p>
          <label for="rc-name">Your name</label>
          <input id="rc-name" name="name" type="text" autocomplete="name" required>
        </p>
        <p>
          <label for="rc-email">Email</label>
          <input id="rc-email" name="email" type="email" autocomplete="email" required>
        </p>
        <p>
          <label for="rc-message">What needs fixing?</label>
          <textarea id="rc-message" name="message" rows="4" required></textarea>
        </p>
        <button type="submit">Send question</button>
      </form>

      <h2>FAQ</h2>
      <details>
        <summary>Does a repair cost anything?</summary>
        <p>No. Donations for spare parts are welcome but never required.</p>
      </details>
    </article>
  </main>

  <footer>
    <p>Riverside Community Hall, 4 Mill Lane</p>
  </footer>
</body>
</html>

Quick quiz 1 / 3

In the workshop example, you type "a@b" into the email field and fill the rest correctly. What does form.checkValidity() return?

Quick quiz 2 / 3

How should the "10:00" cell of the schedule table be written?

Quick quiz 3 / 3

If the FAQ were built from a div plus a JavaScript click handler instead of details/summary, what is likely lost?

What to remember

  • header, a single main and footer form the house; article holds self-contained content
  • Every form control needs a label, name and type; test both the empty and the invalid case
  • Tables need a caption, scope="col" for column headers and scope="row" for row headers
  • details/summary is an FAQ with keyboard and screen reader support built in

HTML Living Standard — Forms — WHATWG

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

Practice: Forms, Tables & Semantic Layout | Thuta Learning