ARISE AFRICA NETWORK VOCATIONAL COURSE (AAN)

Module 3 — HTML Structure: Lists, Tables & Forms

Learning Objectives

Key Terms & Definitions

List
Ordered (<ol>) or unordered (<ul>) collections of items (<li>).
Definition List
<dl> with <dt> (term) and <dd> (definition) pairs.
Table
Used for tabular data; semantic structure: <table>, <thead>, <tbody>, <tr>, <td>, <th>.
Caption
A short description for a table, added with <caption>.
Scope
Attribute on <th> (row/col) that improves accessibility.
Form
<form> element that groups input controls for submission.
Input
Form field elements: <input>, <textarea>, <select>.
Label
<label> associates text with form controls using for and input id.
Placeholder
Temporary hint inside inputs (placeholder="..."), not a substitute for labels.
Required
Attribute (required) that indicates a field must be filled before submission.
Pattern
Input attribute for regex-based client-side validation (pattern="...").
Type
type attribute on input (text, email, number, tel, date, etc.).
Value
The current content of a form control (input.value in JS).
Disabled
Attribute that makes a control un-editable and excluded from submission.
Fieldset & Legend
<fieldset> groups related controls; <legend> labels the group.
Autocomplete
Helps browsers suggest previous values (autocomplete="on").
Form action
action attribute on <form> specifying URL to submit to (can be blank for JS handling).
Method
method="get" or method="post" describing how to send data.
Validation
Client-side HTML5 validation and custom JS validation to ensure correct input.
ARIA
Accessible Rich Internet Applications attributes to improve assistive technology support.
Tab order
Order in which elements receive focus when using Tab; ensure logical flow.
Server-side processing
What happens to form data on a server after submission (not covered in depth here).
CSV
Comma-separated values, common export for tabular data.
Responsive tables
Techniques to make tables usable on small screens (stacking, scrolling).
Semantic grouping
Choosing correct elements that represent meaning, not just appearance.

Detailed Theory — Lists, Tables & Forms (conceptual, examples, and best practices)

3.1 When to use lists vs tables

Use lists for sequences or collections of items (navigation menus, bullet points). Use tables only for true tabular data — information that belongs in rows and columns (financial data, schedules).

3.2 Ordered and unordered lists

Ordered lists (<ol>) are used for sequences where order matters (instructions). Unordered lists (<ul>) are for collections without implicit order. For definitions, use <dl>.

<ol>
  <li>Install software</li>
  <li>Create project folder</li>
</ol>

<ul>
  <li>Apples</li>
  <li>Oranges</li>
</ul>

3.3 Lists accessibility tips

Keep list items concise. Avoid using lists for layout-only purposes. Screen readers announce lists and item counts, which helps navigation.

3.4 Tables — structure and semantics

A well-formed table includes a <caption>, a header row (<thead> with <th>), and a body (<tbody> with <td> cells). Provide scope="col" or scope="row" on headers when helpful.

<table>
  <caption>Monthly Sales</caption>
  <thead><tr><th scope="col">Item</th><th scope="col">Qty</th></tr></thead>
  <tbody>
    <tr><td>Apples</td><td>120</td></tr>
  </tbody>
</table>

3.5 Tables: when not to use them

Avoid using tables for page layout. Tables can be hard to read on mobile if not made responsive. For layout use CSS grid or flexbox instead.

3.6 Forms — anatomy and input types

Forms are composed of controls with labels. Use the correct input type to leverage built-in validation and mobile keyboards:

TypeUse
textGeneric single-line text
emailValidated email format
telTelephone numbers
numberNumeric input with optional min/max
dateDate picker on supporting devices
checkbox / radioSelections and exclusive choices

3.7 Labels, ids and accessibility

Always label inputs. Use <label for="id"> to explicitly connect text with a control. This increases click targets and helps screen readers.

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

3.8 Client-side validation and patterns

HTML5 provides simple validation via attributes like required, min, max, and pattern. Custom validation can be added with JavaScript for better UX.

<input type="text" pattern="[A-Za-z ]+" title="Letters and spaces only" />

3.9 Handling form submission offline

For this course we will handle forms with JavaScript: prevent the default submission, serialize values, and show a success message or store locally (localStorage).

Interactive Playground — Forms & Table Demo

Edit the HTML on the left to change the form or table. Press Run to preview and test validation.

Practical Labs — Step-by-step

Lab 1 — Create an accessible contact form

  1. Create contact.html with a form that collects name, email, phone and a short message.
  2. Use label for attributes and add required where necessary.
  3. Add a fieldset grouping for contact preferences with a legend.
  4. Implement simple JS to prevent default form submission and append values to a table below the form (simulate storage).

Lab 2 — Build a product table with sorting

  1. Create products.html and add a table with columns: Product, Category, Price.
  2. Use <thead> and <tbody>, and add a caption describing the table.
  3. Add simple JavaScript to sort rows by price (ascending/descending) when clicking the Price header.

Lab 3 — Form validation & UX

  1. Enhance the contact form to show inline validation messages (e.g., "Please enter a valid email").
  2. Use input.setCustomValidity() to present custom messages, and clear them when corrected.

Exercises (for mastery)

  1. Create a multi-step form (two pages) that saves the first step in localStorage and completes submission on the second.
  2. Design a responsive table: on narrow screens collapse rows into card-style displays using CSS and visually-hidden headers for accessibility.
  3. Research and implement ARIA attributes for form error descriptions (aria-describedby).
Faith Corner

"Whatever you do, work heartily, as for the Lord and not for men." — Colossians 3:23. Bring integrity and excellence to your code — clarity matters.

Knowledge Check — 5 Questions

Q1. Which tag is used for a table header cell?


Q2. Which element pairs with <dt> in a definition list?


Q3. How do you associate a label with an input?


Q4. Which input type will bring up a numeric keyboard on mobile?


Q5. Which attribute improves table accessibility by describing header scope?