Skip to main content
Albero Academy

Forms & Tables

Collect user input with accessible forms and the right input types, and present real tabular data with proper table markup.

Chapter 4HTML15 min readBeginner friendly
  • #HTML
  • #Forms
  • #Tables

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):

a basic form
<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.

typeUse for
textSingle-line free text
emailEmail addresses (validated + email keyboard)
telPhone numbers (numeric keypad)
numberNumeric input with min/max/step
passwordMasked input
dateA native date picker
checkbox / radioMultiple choice / single choice
fileUploads

Beyond inputs, use the right control for the job:

more controls
<!-- 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 ↔ input
<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:

a data table
<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.
  • colspan and rowspan merge 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

  1. 01Wrap controls in a <form>; every control needs a name to be submitted.
  2. 02The input type gives you the right keyboard and free browser validation.
  3. 03Every input needs a <label for> matching its id — for clicks and for screen readers.
  4. 04Client-side validation is UX, not security — always re-validate on the server.
  5. 05Use tables for tabular data with <th>/<td> and thead/tbody — never for layout.