⚡0 XP🔥0

Lists, Tables and Forms

Lesson 3 of 6 ⏱ 3 min read ❓ 5-question quiz ▶ Runs HTML

Ordered and unordered lists, data tables with headers, and forms with inputs, labels, dropdowns, radio buttons, checkboxes and built-in validation.

Lists#

▶ Try it YourselfHTML
Ctrl + Enter to run
Tip

Website menus are usually a <ul> of links inside <nav>. CSS then turns the list into a horizontal menu bar.

Tables#

Use tables for tabular data - marks, prices, timetables. (Never use tables for page layout; that's CSS's job.)

▶ Try it YourselfHTML
Ctrl + Enter to run
Element Meaning
<table> the whole table
<caption> the table's title
<thead>, <tbody>, <tfoot> header rows, body rows, footer rows
<tr> a table row
<th> a header cell
<td> a data cell
colspan="2" / rowspan="2" a cell that spans 2 columns / 2 rows
हिंदी में समझें

Table में हर <tr> एक लाइन (row) है, और उस row के अंदर हर <td> एक खाना (cell) है। Heading वाले खानों के लिए <th> लिखते हैं। अगर कोई खाना दो columns जितना चौड़ा चाहिए तो colspan="2" लिखें।

Forms#

Forms collect information from visitors - admission enquiries, login, search, feedback.

▶ Try it YourselfHTML
Ctrl + Enter to run

Press Send enquiry with an empty name, or a wrong email - the browser stops you. That is HTML5 validation, with no JavaScript at all.

Common input types#

type= Shows
text, password one-line text; password hides characters
email, tel, url text with format checking (and the right phone keyboard)
number number with up/down arrows; use min, max, step
date, time date / time picker
checkbox tick on/off (many can be ticked)
radio choose one of a group (same name)
file upload a file
range, color slider, colour picker

Useful attributes#

  • required - must be filled
  • placeholder - grey hint text (not a replacement for a label!)
  • min, max, minlength, maxlength, pattern - validation rules
  • name - the key used when the form data is sent to the server
  • action="/enquiry" and method="post" on <form> - where and how the data is sent
Common Mistake

HTML validation helps the user, but it is not security. Anyone can bypass it. A real server (Python Flask, Node.js...) must check the data again before saving it.

Summary#

  • <ul>, <ol> and <dl> for lists; <li> for each item.
  • Tables use <table>, <tr>, <th>, <td>, with <thead>/<tbody> and colspan/rowspan.
  • Every form control needs a <label>; radio buttons in one group share a name.
  • Built-in validation: required, type="email", pattern, min/max.

Quick Quiz

Q1.

Which list should you use for steps that must be done in order?

Q2.

Which element is a table header cell?

Q3.

Why connect a <label> to an input with for and id?

Q4.

Radio buttons in the same group must share the same...

Q5.

What does <input type="email" required> do?