HTML
HTML is the markup language that describes document structure and semantics
to the browser. This skill covers plain HTML itself — a framework-specific
skill (React, Vue, Nunjucks, …) covers component syntax on top of it.
Document structure
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Page title</title>
</head>
<body>
<header>…</header>
<main>…</main>
<footer>…</footer>
</body>
</html>
<!doctype html> triggers standards mode; omitting it triggers quirks mode
in most browsers, which changes box-model and CSS behavior unpredictably.
lang on <html> matters for screen readers (correct pronunciation) and
translation tools — set it to the actual page language, not always en.
- The viewport
<meta> is required for correct rendering on mobile; without
it, mobile browsers assume a desktop-width layout and zoom out.
Semantic elements over generic <div>
Instead of a bare <div> for… |
Use |
| Page banner / site header |
<header> |
| Primary navigation |
<nav> |
| The page's main unique content (one per page) |
<main> |
| A self-contained piece of content |
<article> |
| A thematic grouping with a heading |
<section> |
| Tangential content |
<aside> |
| Page/section footer |
<footer> |
Semantic elements give assistive technology and search engines structure for
free; a <div> conveys nothing. Reach for a <div>/<span> only when no
semantic element fits and you need a hook purely for styling/scripting.
Forms
<form method="post" action="/submit">
<label for="email">Email</label>
<input id="email" name="email" type="email" required autocomplete="email">
<fieldset>
<legend>Plan</legend>
<label><input type="radio" name="plan" value="free"> Free</label>
<label><input type="radio" name="plan" value="pro"> Pro</label>
</fieldset>
<button type="submit">Submit</button>
</form>
<label for="id"> (or wrapping the input) is what makes a form field
operable via assistive tech and click-to-focus — an unlabeled input is an
accessibility bug, not a style choice.
- Use the specific
type (email, tel, number, date, …) rather than
always text — it gets you built-in validation and the right mobile
keyboard for free.
required, pattern, minlength/maxlength are native HTML validation;
reach for them before reimplementing validation in JavaScript.
Accessibility basics
- Every
<img> needs alt — descriptive text for a meaningful image,
alt="" (empty, not omitted) for a purely decorative one.
- Don't skip heading levels (
<h1> → <h3> with no <h2>) — assistive tech
users navigate by heading outline.
- Interactive elements need a real element (
<button>, <a href>) rather
than a <div onclick> — a <div> gets no keyboard focus, no Enter/Space
activation, and no accessible role for free.
- ARIA attributes (
aria-label, role, …) are a supplement for cases native
HTML can't express — the first rule of ARIA is to use a native element
instead when one exists.
Common pitfalls
- Unclosed or mismatched tags the browser silently repairs — this hides
bugs during development that then break in a stricter parser (an XML
pipeline, a linter, a different browser's error-recovery heuristics).
<a href="#"> or a bare <div> used as a button — breaks keyboard
navigation and screen readers; use <button> for actions, <a href="...">
only for actual navigation.
- Block elements nested inside inline elements (a
<div> inside a <p>)
— invalid and triggers browser auto-correction that can split the DOM in
surprising places.
- Relying on
<br> for spacing instead of CSS margins — conflates
presentation with structure and breaks if the layout changes.
- Missing
alt, not empty alt="", on decorative images — screen readers
then read the filename aloud.
Learn more
1---2name: html3description: Use when asked to write, explain, or debug plain HTML — document structure, semantic elements, forms, accessibility attributes, or how the browser parses and renders markup — independent of any specific framework or templating language.4metadata:5 source: https://skillmd.com/skills/skills-on-ai/html6---78# HTML910HTML is the markup language that describes document structure and semantics11to the browser. This skill covers plain HTML itself — a framework-specific12skill (React, Vue, Nunjucks, …) covers component syntax on top of it.1314## Document structure1516```html17<!doctype html>18<html lang="en">19<head>20 <meta charset="utf-8">21 <meta name="viewport" content="width=device-width, initial-scale=1">22 <title>Page title</title>23</head>24<body>25 <header>…</header>26 <main>…</main>27 <footer>…</footer>28</body>29</html>30```3132- `<!doctype html>` triggers standards mode; omitting it triggers quirks mode33 in most browsers, which changes box-model and CSS behavior unpredictably.34- `lang` on `<html>` matters for screen readers (correct pronunciation) and35 translation tools — set it to the actual page language, not always `en`.36- The viewport `<meta>` is required for correct rendering on mobile; without37 it, mobile browsers assume a desktop-width layout and zoom out.3839## Semantic elements over generic `<div>`4041| Instead of a bare `<div>` for… | Use |42| --- | --- |43| Page banner / site header | `<header>` |44| Primary navigation | `<nav>` |45| The page's main unique content (one per page) | `<main>` |46| A self-contained piece of content | `<article>` |47| A thematic grouping with a heading | `<section>` |48| Tangential content | `<aside>` |49| Page/section footer | `<footer>` |5051Semantic elements give assistive technology and search engines structure for52free; a `<div>` conveys nothing. Reach for a `<div>`/`<span>` only when no53semantic element fits and you need a hook purely for styling/scripting.5455## Forms5657```html58<form method="post" action="/submit">59 <label for="email">Email</label>60 <input id="email" name="email" type="email" required autocomplete="email">6162 <fieldset>63 <legend>Plan</legend>64 <label><input type="radio" name="plan" value="free"> Free</label>65 <label><input type="radio" name="plan" value="pro"> Pro</label>66 </fieldset>6768 <button type="submit">Submit</button>69</form>70```7172- `<label for="id">` (or wrapping the input) is what makes a form field73 operable via assistive tech and click-to-focus — an unlabeled input is an74 accessibility bug, not a style choice.75- Use the specific `type` (`email`, `tel`, `number`, `date`, …) rather than76 always `text` — it gets you built-in validation and the right mobile77 keyboard for free.78- `required`, `pattern`, `minlength`/`maxlength` are native HTML validation;79 reach for them before reimplementing validation in JavaScript.8081## Accessibility basics8283- Every `<img>` needs `alt` — descriptive text for a meaningful image,84 `alt=""` (empty, not omitted) for a purely decorative one.85- Don't skip heading levels (`<h1>` → `<h3>` with no `<h2>`) — assistive tech86 users navigate by heading outline.87- Interactive elements need a real element (`<button>`, `<a href>`) rather88 than a `<div onclick>` — a `<div>` gets no keyboard focus, no `Enter`/`Space`89 activation, and no accessible role for free.90- ARIA attributes (`aria-label`, `role`, …) are a supplement for cases native91 HTML can't express — the first rule of ARIA is to use a native element92 instead when one exists.9394## Common pitfalls9596- **Unclosed or mismatched tags** the browser silently repairs — this hides97 bugs during development that then break in a stricter parser (an XML98 pipeline, a linter, a different browser's error-recovery heuristics).99- **`<a href="#">` or a bare `<div>` used as a button** — breaks keyboard100 navigation and screen readers; use `<button>` for actions, `<a href="...">`101 only for actual navigation.102- **Block elements nested inside inline elements** (a `<div>` inside a `<p>`)103 — invalid and triggers browser auto-correction that can split the DOM in104 surprising places.105- **Relying on `<br>` for spacing** instead of CSS margins — conflates106 presentation with structure and breaks if the layout changes.107- **Missing `alt`, not empty `alt=""`, on decorative images** — screen readers108 then read the filename aloud.109110## Learn more111112- [MDN: HTML](https://developer.mozilla.org/en-US/docs/Web/HTML) — element113 and attribute reference.114- [WHATWG HTML Living Standard](https://html.spec.whatwg.org/) — the spec115 itself.116- [W3C Nu HTML Checker](https://validator.w3.org/nu/) — validate markup.117- [WebAIM](https://webaim.org/) — accessibility-focused guidance.