📋 Web Development

HTML Tables & Forms

⏱ 2 hr3 topicsInteractive
🎯 By the end: You can build an HTML table, control its spacing, merge cells, and create a basic form with input fields and a button.

Tables arrange data in rows and columns, and forms collect input from visitors. Both are core HTML skills — edit the live examples and press Run to see them.

1Building a table

A table uses four tags: <table> (the table), <tr> (a row), <th> (a header cell), <td> (a data cell). Common attributes:

AttributeControls
borderThe gridline thickness
cellpaddingSpace INSIDE each cell (around the content)
cellspacingSpace BETWEEN cells
align / widthAlignment / overall width

Edit and Run:

Table▶ live preview
index.html
Preview
Key points
  • <table> holds the table; <tr> a row; <th> a header cell; <td> a data cell.
  • border sets gridlines; cellpadding is space inside a cell; cellspacing is space between cells.
  • Cells are written inside rows, left to right.

2Merging cells

To make one cell cover several rows or columns:

  • colspan="n" — stretch across n columns (horizontally).
  • rowspan="n" — stretch down n rows (vertically).

Run this to see a merged title cell:

Merged cells▶ live preview
index.html
Preview
Key points
  • colspan="n" spans a cell across n columns (horizontally).
  • rowspan="n" spans a cell down n rows (vertically).
  • Cells covered by a span are not written again.

3Simple forms

A <form> collects input. Common fields use the <input> tag with a type:

FieldHTML
Text box<input type="text">
Checkbox<input type="checkbox">
Button<input type="submit"> or <button>

Run this small form:

A simple form▶ live preview
index.html
Preview
Key points
  • A form's fields live inside <form> ... </form>.
  • <input type="text"> is a text box; type="checkbox" is a checkbox.
  • A button is <input type="submit"> or <button>.

★ Practical: a results page

Build one HTML page that has:

  1. A table with a header row and at least two data rows.
  2. A title cell that spans all columns using colspan.
  3. A cell that spans two rows using rowspan.
  4. A small form with a text box, two checkboxes and a button.

Ready for the chapter test?

Answer 5 questions. Score 60% or more to mark this chapter complete.

Start the test →

💡 Log in to save your progress and earn the certificate.