Learning Objectives
- Use lists (ordered/unordered), definition lists and nested lists correctly for content structure.
- Build accessible and semantic tables for tabular data (thead, tbody, caption, scope).
- Create HTML forms with appropriate input types, labels, validation attributes and accessible practices.
- Handle form data in the browser (prevent default, read values) and simulate submissions offline.
- Understand when to use lists, tables and forms, and common anti-patterns.
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 usingforand inputid.- 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
typeattribute on input (text,email,number,tel,date, etc.).- Value
- The current content of a form control (
input.valuein 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
actionattribute on<form>specifying URL to submit to (can be blank for JS handling).- Method
method="get"ormethod="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:
| Type | Use |
|---|---|
| text | Generic single-line text |
| Validated email format | |
| tel | Telephone numbers |
| number | Numeric input with optional min/max |
| date | Date picker on supporting devices |
| checkbox / radio | Selections 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
- Create
contact.htmlwith a form that collects name, email, phone and a short message. - Use
label forattributes and addrequiredwhere necessary. - Add a
fieldsetgrouping for contact preferences with a legend. - 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
- Create
products.htmland add a table with columns: Product, Category, Price. - Use
<thead>and<tbody>, and add a caption describing the table. - Add simple JavaScript to sort rows by price (ascending/descending) when clicking the Price header.
Lab 3 — Form validation & UX
- Enhance the contact form to show inline validation messages (e.g., "Please enter a valid email").
- Use
input.setCustomValidity()to present custom messages, and clear them when corrected.
Exercises (for mastery)
- Create a multi-step form (two pages) that saves the first step in
localStorageand completes submission on the second. - Design a responsive table: on narrow screens collapse rows into card-style displays using CSS and visually-hidden headers for accessibility.
- Research and implement ARIA attributes for form error descriptions (
aria-describedby).
"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.