# HTML5 Cheatsheet

A quick reference for the most-used HTML5 elements and patterns in this course.

## Document skeleton

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Page title</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <!-- content -->
  <script src="app.js" defer></script>
</body>
</html>
```

## Semantic structure

| Element       | Use for                                              |
|---------------|------------------------------------------------------|
| `<header>`    | Top of page or section (logo, nav, intro)            |
| `<nav>`       | Primary navigation links                             |
| `<main>`      | Main page content (one per page)                     |
| `<section>`   | Thematic grouping with a heading                     |
| `<article>`   | Self-contained content (post, card, comment)         |
| `<aside>`     | Side content (sidebar, callouts)                     |
| `<footer>`    | Bottom of page or section                            |
| `<figure>`    | Image + `<figcaption>` caption                       |

## Text & inline

```html
<h1>–<h6>           Headings (one h1 per page)
<p>                 Paragraph
<strong>            Important text (bold)
<em>                Emphasised text (italic)
<a href="url">      Link
<br>                Line break
<hr>                Thematic break
<code>              Inline code
<pre>               Preformatted text (preserves whitespace)
<abbr title="...">  Abbreviation with tooltip
<time datetime="">  Machine-readable date/time
```

## Lists

```html
<ul>                Unordered list
<ol>                Ordered list
<li>                List item
<dl><dt><dd>        Description list (term + description)
```

## Forms

```html
<form action="/submit" method="post">
  <label for="name">Name</label>
  <input type="text" id="name" name="name" required>

  <label for="email">Email</label>
  <input type="email" id="email" name="email" required>

  <label for="msg">Message</label>
  <textarea id="msg" name="message" rows="4"></textarea>

  <button type="submit">Send</button>
</form>
```

### Input types

`text` `email` `password` `number` `tel` `url` `search` `date` `time`
`checkbox` `radio` `file` `range` `color` `hidden`

### Useful attributes

`required` `placeholder` `pattern` `min` `max` `step` `minlength` `maxlength` `autocomplete` `readonly` `disabled`

## Media

```html
<img src="cat.jpg" alt="A sleeping cat" width="400" height="300">
<picture>
  <source srcset="hero.webp" type="image/webp">
  <img src="hero.jpg" alt="Hero">
</picture>
<video src="clip.mp4" controls></video>
<audio src="song.mp3" controls></audio>
```

Always provide meaningful `alt` text for images. Empty `alt=""` for purely decorative images.

## Tables

```html
<table>
  <caption>Quarterly results</caption>
  <thead>
    <tr><th>Quarter</th><th>Revenue</th></tr>
  </thead>
  <tbody>
    <tr><td>Q1</td><td>1,200</td></tr>
  </tbody>
</table>
```

## Accessibility quick wins

- One `<h1>` per page; don't skip heading levels.
- Every `<img>` needs `alt`.
- Every form control needs an associated `<label>`.
- Use semantic elements over `<div>` whenever possible.
- Keyboard-test your page: can you tab through all interactive elements?
- Use `aria-label` only when no visible label exists.

## Validate your HTML

- W3C Validator: <https://validator.w3.org/>
- HTML5 outline: <https://gsnedders.html5.org/outliner/>
