By the end of this lesson you will be able to
- Build a small table with a header row and data cells.
- Create a form with labelled text, email, choice and submit controls.
- Choose semantic elements such as header, nav, main and footer instead of generic boxes.
- Apply basic accessibility habits: labels, alt text, heading order and clear link text.
Most real pages contain more than headings and paragraphs. They show timetables and prices in tables, and collect names and messages with forms. They also have to work for people who use a screen reader, a keyboard instead of a mouse, or a small phone screen. This lesson shows the HTML for tables and forms, and the semantic elements that give a page meaning for browsers, search engines and assistive tools.
Tables for data
A table shows data in rows and columns, such as a timetable or a price list. Use tables for data only, never to arrange the look of a page. The <table> element holds rows (<tr>, table row). A header cell is <th> and an ordinary data cell is <td>. A <caption> gives the table a title. Every row should contain the same number of cells.
<table>
<caption>Garden club sessions</caption>
<thead>
<tr><th scope="col">Day</th><th scope="col">Time</th><th scope="col">Activity</th></tr>
</thead>
<tbody>
<tr><td>Saturday</td><td>09:00</td><td>Digging</td></tr>
<tr><td>Wednesday</td><td>17:30</td><td>Watering</td></tr>
</tbody>
</table><thead> and <tbody> separate the header from the body. The scope="col" attribute tells assistive tools that each header describes the column beneath it. A screen reader can then say "Time: 09:00" instead of reading a bare number with no context.
Garden club sessions
Day | Time | Activity
Saturday | 09:00 | Digging
Wednesday | 17:30 | Watering
- Marker 1: caption: the table title
- Marker 2: th cells: column headers
- Marker 3: td cells: the data
Read this figure as text
A simulated browser window showing a three-column table with a header row and two data rows.
A browser window with the address example.org/sessions. The body shows the caption Garden club sessions, then a header row with Day, Time and Activity, then two data rows: Saturday, 09:00, Digging and Wednesday, 17:30, Watering. Marker 1 points to the caption, marker 2 to the header row and marker 3 to the data rows.
Forms and labels
A form collects information from the reader. The <form> element wraps the controls. The <input> element makes a field; its type attribute chooses the kind: text, email, checkbox, radio and so on. A <textarea> gives space for a longer message, <select> with <option> makes a drop-down list and <button type="submit"> sends the form. The name attribute names the data when the form is sent.
Every control needs a label. A <label> is a caption linked to its input: the label's for attribute must match the input's id. A linked label is read aloud by screen readers, and clicking it puts the cursor in the field, which gives a bigger target for fingers and mouse clicks. Hint text shown inside an empty field is not a replacement for a label because it vanishes as soon as you type.
<form action="/join" method="post">
<p>
<label for="name">Your name</label>
<input id="name" name="name" type="text" required>
</p>
<p>
<label for="email">Email address</label>
<input id="email" name="email" type="email" required>
</p>
<p>
<label for="day">Preferred day</label>
<select id="day" name="day">
<option>Saturday</option>
<option>Wednesday</option>
</select>
</p>
<p>
<label for="note">Message</label>
<textarea id="note" name="note" rows="3"></textarea>
</p>
<button type="submit">Join the club</button>
</form>The required attribute makes the browser refuse to send the form if that field is empty, and type="email" makes it check that the text looks like an email address. This is a convenience for the reader. It is not real security: a server must always check the data again. Making the form actually deliver the information to somebody needs a server, which is beyond this lesson.
Join the club
Your name: [ Amina Hassan ]
Email address: [ amina@example.com ]
Preferred day: [ Saturday v ]
- Marker 1: Heading for the form
- Marker 2: Label linked to its field
- Marker 3: Submit button
Read this figure as text
A simulated browser window showing a form with name, email, day and message controls and a submit button.
A browser window with the address example.org/join. The page has a heading Join the club, then rows for Your name, Email address, Preferred day and Message, and a button Join the club. Marker 1 points to the heading, marker 2 to the label rows (each label is linked to its field) and marker 3 to the submit button.
Semantic structure
Semantic elements describe the role of a part of the page, not just its look. Instead of putting everything in anonymous boxes, you use <header> for the top of the page, <nav> for the main navigation links, <main> for the unique content, <section> and <article> for self-contained parts, <aside> for side notes and <footer> for the bottom. A page should have only one <main>.
Why bother? Screen reader users can jump straight to the navigation or the main content. Search engines understand the page better. Your own code is easier to read. The generic containers <div> and <span> still exist for grouping when no semantic element fits, but use them last.
<body>
<header>
<h1>Garden club</h1>
<nav>
<a href="index.html">Home</a>
<a href="sessions.html">Sessions</a>
</nav>
</header>
<main>
<h2>Next session</h2>
<p>Saturday at nine o'clock.</p>
</main>
<footer>
<p>Contact: club@example.org</p>
</footer>
</body>- div (top)
- div (links)
- div (content)
- div (bottom)
- No role is announced
Works, but says nothing
- header
- nav
- main
- footer
- Roles are announced
Meaning built in
Read this figure as text
Two columns comparing a page built from div boxes with a page built from semantic elements.
Left column, Generic boxes: div, div, div, div. Nothing says what each box is for, so assistive tools cannot offer shortcuts. Right column, Semantic elements: header, nav, main and footer. Each name says its role, so screen reader users can jump to the navigation or the main content, and search engines understand the page.
Accessibility basics
Accessibility means that people with different abilities and devices can use your page. That includes people who are blind, have low vision, cannot use a mouse, find small targets hard to press or are in bright sunlight. Good HTML gives you most of it for free. The habits below cost almost nothing.
- Give every informative image meaningful
alttext. If an image is purely decoration, use an emptyalt=""so screen readers skip it. - Use headings in order (h1, then h2, then h3) and never skip levels to get a size.
- Write link text that makes sense alone. Use "Read the seed guide", not "Click here".
- Label every form field with a linked
<label>. - Do not rely on colour alone to carry meaning, such as red text only for errors. Add words or symbols too.
- Check that you can reach every link and button by pressing the Tab key, and that you can see where you are.
Common mistakes
✖ Instead of: Using a table to position things on the page.
✔ Do this: Tables are for data. Use headings, sections and CSS for layout.
✖ Instead of: Using
<br>tags or empty paragraphs to make space.✔ Do this: Use CSS margins for spacing and separate paragraphs for separate ideas.
✖ Instead of: Skipping from
<h1>to<h4>because h4 looks nicer.✔ Do this: Keep heading levels in order and style the size with CSS.
✖ Instead of: Making a button out of a plain
<div>with a click handler.✔ Do this: Use
<button>or<a>. They work with the keyboard and screen readers automatically.
If something goes wrong
- My table looks like plain text with no lines.
- Browsers draw tables without borders by default. The table is correct. Borders are added later with CSS.
- Pressing submit reloads the page and nothing seems to happen.
- A form with no real server address cannot store anything. For practice that is normal; check that the controls look correct and carry on.
- The browser will not let me submit my form.
- A
requiredfield is probably empty, or an email field does not look like an address. Fill in every required field with fictional data. - My table has cells in the wrong columns.
- Count the
<td>or<th>elements in each row. Every row must have the same number, and each must be closed.
Key terms
- Form label
- The visible caption of a form field, linked to the field so that screen readers and clicks connect the two.
- Semantic HTML
- HTML elements whose names say what a part of the page is for, such as header, nav, main and footer.
- Accessibility
- Making devices, documents and websites usable by people with different abilities, such as poor sight, hearing or movement.
Practise it for real
Reading is not the same as being able to do it. Complete these on your own computer, then tick only what you have actually done. These ticks are your own honest record: nothing checks them for you.
Write a timetable
In the live editor from the previous lesson, build a table of a fictional weekly timetable with a caption, a header row of th cells with scope="col" and at least three data rows. Check that each row has the same number of cells.
Create a labelled form
Write a contact form with a name field, an email field and a message box, each with a label linked by for and id, and a submit button. Click each label in the preview to prove it is linked: the cursor should jump into its field.
Challenge: make a page semantic and accessible
Take a page built only from <div> elements (invent one with a title, three links, a paragraph and a footer line) and rewrite it using header, nav, main and footer. Add alt text to one image and change one "click here" link into clear link text. Explain in two sentences who benefits.
Knowledge check
6 questions. You need 80% to pass. Mistakes here are part of learning, and you can retry as often as you like.
Summary
- Tables are for data: table, tr, th, td, caption, with thead and tbody.
- A form uses form, input (with type), textarea, select, button and a linked label for every field.
- Semantic elements (header, nav, main, footer) describe roles, not looks.
- Alt text, ordered headings, clear link text and keyboard access make pages usable by more people.
Checklist: can you do these?
Marking a lesson as read does not prove you can do it. Skills count as demonstrated when you pass the quiz (not yet) and complete the practical tasks (not yet).
Related lessons
References and further reading
Official sources for details that can change between versions.
- HTML table basics (MDN Web Docs)
- Your first form (MDN Web Docs)
- Accessibility fundamentals (W3C Web Accessibility Initiative)