Forms are how the web collects information — sign-ups, searches, checkouts. Tables present real grid data. Both have a reputation for being fiddly, but the rules are simple once you separate the structure (HTML, this chapter) from the styling (CSS, later).
Forms & inputs
A <form> wraps the controls. Its action is where the data is sent and method is how (get puts data in the URL; post sends it in the request body):
<form action="/enquiry" method="post"><label for="name">Full name</label><input type="text" id="name" name="name" required><label for="email">Email</label><input type="email" id="email" name="email" required><button type="submit">Request a call back</button></form>
Each control needs a name — that's the key the server receives. Without a name, the field's value is never sent.
Input types & validation
The type attribute does a lot of work for free: it changes the on-screen keyboard on mobile, and the browser validates the format before submitting.
| type | Use for |
|---|---|
text | Single-line free text |
email | Email addresses (validated + email keyboard) |
tel | Phone numbers (numeric keypad) |
number | Numeric input with min/max/step |
password | Masked input |
date | A native date picker |
checkbox / radio | Multiple choice / single choice |
file | Uploads |
Beyond inputs, use the right control for the job:
<!-- Long text --><textarea name="message" rows="4"></textarea><!-- Pick one from a list --><select name="programme"><option value="">Choose a programme</option><option value="data">Data Analytics</option><option value="fullstack">Full Stack</option></select><!-- Constrained number --><input type="number" name="age" min="16" max="99">
Validation attributes like required, min, max, minlength and pattern catch mistakes before the form is even sent — no JavaScript needed.
Labels & accessibility
Every input needs a <label>. Link them by matching the label's for to the input's id. Now clicking the label focuses the field, and screen readers announce the field's purpose:
<label for="whatsapp">WhatsApp number</label><input type="tel" id="whatsapp" name="whatsapp">
Group related controls (like a set of radio buttons) in a <fieldset> with a <legend> so the group has a name too.
Tables
Tables are for tabular data — rows and columns of related facts — not for page layout (that's CSS Grid's job). The core tags:
<table><thead><tr><th>Programme</th><th>Duration</th><th>Avg. package</th></tr></thead><tbody><tr><td>Data Analytics</td><td>6 months</td><td>₹6.5 LPA</td></tr><tr><td>Full Stack</td><td>9 months</td><td>₹8 LPA</td></tr></tbody></table>
<th>is a header cell (bold, and announced as a header);<td>is a data cell.<thead>/<tbody>group the header and body rows.colspanandrowspanmerge cells across columns or rows.
Practice
Build the "Request a call back" form from this chapter with name, email, WhatsApp, a programme dropdown and a message — every field labelled and validated. Then add a small pricing table comparing two programmes.
Key takeaways
- 01Wrap controls in a <form>; every control needs a name to be submitted.
- 02The input type gives you the right keyboard and free browser validation.
- 03Every input needs a <label for> matching its id — for clicks and for screen readers.
- 04Client-side validation is UX, not security — always re-validate on the server.
- 05Use tables for tabular data with <th>/<td> and thead/tbody — never for layout.
