1. How the Web Works & Semantic HTML5
HTML Forms, Data Tables & Web Accessibility
Build usable, accessible forms with proper labels, input types, radio/checkbox groups, built-in HTML validation, semantic tables, and ARIA best practices.
- Connect <label> and <input> properly using for/id pairs for mobile usability and screen readers
- Choose the right input types, radio groups, selects, and native HTML5 validation attributes
- Build accessible data tables and keyboard-friendly interfaces
Static text pages let visitors read. Forms let visitors talk back: logging in, searching products, filtering flights, posting comments, and submitting checkout orders all depend on semantic <form> markup.
Pairing <label> and <input> Correctly
One of the most common HTML mistakes is dropping a bare <input placeholder="Email" /> on a page without a <label>. Placeholders disappear the instant someone starts typing, leaving users confused—and screen readers often skip placeholders altogether.
Always connect a <label> to its <input> by matching for and id:
<form action="/subscribe" method="POST">
<div>
<label for="full-name">Full Name</label>
<input
id="full-name"
name="fullName"
type="text"
required
autocomplete="name"
placeholder="Alex Rivera"
/>
</div>
<div>
<label for="email">Email Address</label>
<input
id="email"
name="email"
type="email"
required
autocomplete="email"
placeholder="alex@example.com"
/>
</div>
<button type="submit">Join Free Track</button>
</form>Watch what every attribute accomplishes here:
id+for: Clicking or tapping anywhere on the words"Email Address"automatically focuses the input box (a massive usability win on phones!).name: Sets the key name sent when the form submits (withoutname, the browser ignores that input's value completely!).type="email": Displays the@shortcut right on mobile keyboards and checks basic email formatting before submission.type="submit": Every<button>inside a<form>submits by default—explicitly writingtype="submit"(ortype="button"for non-submit buttons) prevents accidental form reloads.
Essential Input Controls Compared
| Control | HTML Markup | Best Used For |
|---|---|---|
| Short text / password | <input type="text">, <input type="password"> | Usernames, searches, hidden passwords |
| Email / URL / Number | type="email", type="url", type="number" | Structured values with mobile-friendly keyboards |
| Multi-line text | <textarea rows="4"> | Bio descriptions, support messages, reviews |
| Dropdown menu | <select><option value="..."> | Choosing 1 option out of 5+ choices (country, category) |
| Checkboxes | <input type="checkbox"> | Independent Yes/No toggles or multi-select preferences |
| Radio buttons | <input type="radio" name="plan" value="free"> | Choosing exactly 1 mutually exclusive choice (all radios in the group must share the exact same name!) |
When grouping related radio buttons or checkboxes, wrap them in <fieldset> with a <legend> caption so assistive technology announces the question before listing the options.
Free Built-In Browser Validation
Before writing custom JavaScript validation rules, HTML5 handles common guardrails automatically:
required: Refuses empty submissions and focuses the missing field.minlength="8"/maxlength="60": Enforces minimum/maximum character length.min="1" max="100": Restricts allowed numeric or date ranges.pattern="[A-Za-z0-9]+": Validates text against a regular expression if needed.
If two inputs accidentally share the same id, clicking the second <label> jumps the cursor to the first input! Meanwhile, radio buttons work in reverse: every choice in a single question must share the same name (like name="tier") so selecting one unselects the others.
Structured Data Tables (Not Page Layout!)
Never use <table> to arrange columns of cards—we have CSS Flexbox and Grid for layout. Reserve <table> strictly for true two-dimensional data like schedules, invoices, or comparison matrices:
<table>
<caption>2026 Course Tracks Comparison</caption>
<thead>
<tr>
<th scope="col">Course</th>
<th scope="col">Level</th>
<th scope="col">Modules</th>
<th scope="col">Price</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Web Development Foundations</th>
<td>Beginner</td>
<td>5 Modules</td>
<td>Free</td>
</tr>
<tr>
<th scope="row">Python Fundamentals</th>
<td>Beginner</td>
<td>7 Modules</td>
<td>Free</td>
</tr>
</tbody>
</table>Notice scope="col" on column headers and scope="row" on row labels—that tiny detail lets screen readers announce "Python Fundamentals, Price: Free" as someone moves across cells.
Practical Web Accessibility (a11y) Habits
Writing accessible websites means everyone—including people navigating strictly by keyboard (Tab, Enter, Space) or using screen readers—can use everything you build:
- Maintain Visible Focus Outlines: Never write
outline: none;without replacing it with an equally clear:focus-visiblering. - Use Native Interactive Controls: Prefer
<button>and<a>over clickable<div>tags. - Label Icon-Only Buttons with
aria-label: When a search button renders only a magnifying glass icon with no text inside, addaria-label="Search courses".
Try It Live: Interactive Signup Form
Try changing the required attributes, adding a textarea comment box, and submitting the form below to watch built-in browser validation in action:
Quick Checkpoints
Why should <label for='email'> match <input id='email'>?
What ensures three radio buttons only allow choosing ONE option at a time?