Skip to content
Tutorials Center
My learning

Topics

Lesson 120 of 122 Β· Practice and Review

HTML Cheat Sheet

A one-page HTML cheat sheet covering the document skeleton, text, links, lists, images, media, tables, forms, interactive elements and the head, with live examples.

This page squeezes the whole HTML course into one place. Use it as a quick reminder while you build, or as a review before an exam or an interview. Every section links to the lesson that explains the topic in depth.

The snippets are short on purpose. Where something is easy to get wrong, there is a live example you can edit. When you have refreshed your memory, test yourself with the HTML Practice Exercises.

The document skeleton

HTML
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Page title – Site name</title>
    <meta name="description" content="One or two sentences for search results.">
    <link rel="icon" href="/favicon.svg" type="image/svg+xml">
    <link rel="stylesheet" href="/css/site.css">
    <script src="/js/app.js" defer></script>
  </head>
  <body>
    <!-- visible content -->
  </body>
</html>
  • <!doctype html> turns on standards mode; lang helps screen readers, translation and hyphenation.
  • charset must appear in the first 1024 bytes; the viewport tag makes mobile layouts work.
  • Lessons: Your First Web Page, The Head Element, Meta Tags.

Syntax rules

Rule Example
Elements nest, never overlap <p><em>yes</em></p>, not <p><em>no</p></em>
Void elements have no end tag <br>, <img>, <input>, <meta>, <link>, <hr>, <source>, <track>, <wbr>
Attributes go in the start tag <a href="/help" title="Help pages">
Boolean attributes: presence = true <input required>, <video muted>
Comments <!-- not shown -->
Reserved characters &lt; &gt; &amp; &quot; &nbsp;

See Elements, Attributes and HTML Entities.

Text

Block text

Element Use
<h1>–<h6> Headings; one clear <h1>, never skip levels to get a smaller font
<p> Paragraph
<blockquote cite="url"> Long quotation
<pre> Preformatted text, whitespace kept
<hr> Thematic break between topics
<address> Contact info for the page or article

Inline text

Element Meaning
<strong> / <b> Importance / stylistic offset without importance
<em> / <i> Stress emphasis / alternate voice, terms, foreign words
<mark> Highlighted, relevant here
<small> Side comments, fine print
<s> / <del> / <ins> No longer accurate / removed / added edits
<code>, <kbd>, <samp>, <var> Code, keyboard input, program output, variable
<abbr title="..."> Abbreviation
<q> and <cite> Inline quote (adds quote marks) and title of a work
<time datetime="2026-03-14"> Machine-readable date or time
<sub>, <sup> Subscript, superscript
<br>, <wbr> Line break inside content, optional break point

Lessons: Headings and Paragraphs, Text Formatting, Quotations, Computer Code, Time and Data.

Text semantics at a glance
HTML
<a href="/pricing">Relative to the site root</a>
<a href="../guide/setup.html">Relative to this file</a>
<a href="https://example.com" target="_blank">Opens a new tab (noopener is implied)</a>
<a href="#faq">Jump to id="faq" on this page</a>
<a href="mailto:[email protected]?subject=Order">Email</a>
<a href="tel:+15550100">Phone</a>
<a href="/report.pdf" download>Download</a>
<a href="/" aria-current="page">Current page in a nav</a>

Write link text that makes sense on its own ("Download the 2026 report", not "click here"). Lessons: Links, File Paths, Link Targets, Special Links, Navigation Menus.

Lists

HTML
<ul> <li>Unordered</li> </ul>
<ol start="5" reversed type="a"> <li>Ordered, with options</li> </ol>
<ol> <li>Step <ul><li>Nested lists go inside an li</li></ul></li> </ol>
<dl> <dt>Term</dt> <dd>Description</dd> </dl>

Lessons: Lists, Ordered Lists, Nested Lists, Description Lists.

Images and media

HTML
<img src="/img/fox.jpg" alt="A red fox in snow" width="800" height="533" loading="lazy">

<img src="small.jpg" alt="Harbor"
     srcset="small.jpg 400w, medium.jpg 800w, large.jpg 1200w"
     sizes="(min-width: 60em) 50vw, 100vw">

<picture>
  <source srcset="photo.avif" type="image/avif">
  <source media="(max-width: 600px)" srcset="photo-tall.jpg">
  <img src="photo.jpg" alt="Harbor at dawn">
</picture>

<figure>
  <img src="chart.svg" alt="Sales rose 40% in May">
  <figcaption>Monthly sales, 2026</figcaption>
</figure>

<video controls width="640" height="360" poster="poster.jpg" preload="metadata">
  <source src="clip.webm" type="video/webm">
  <source src="clip.mp4" type="video/mp4">
  <track kind="captions" src="clip.en.vtt" srclang="en" label="English" default>
</video>

<audio controls src="chime.mp3"></audio>
<iframe src="https://example.com/map" title="Store map" loading="lazy"></iframe>
  • alt="" for purely decorative images; never leave alt out.
  • Always set width and height so the page does not jump while images load.
  • autoplay only works reliably with muted; playsinline keeps video inline on iPhone.

Lessons: Images, Responsive Images, Figures, Video, Audio, Captions and Subtitles, Iframes.

Tables

HTML
<table>
  <caption>Opening hours</caption>
  <thead>
    <tr> <th scope="col">Day</th> <th scope="col">Open</th> </tr>
  </thead>
  <tbody>
    <tr> <th scope="row">Monday</th> <td>9–17</td> </tr>
    <tr> <th scope="row">Saturday</th> <td>10–14</td> </tr>
  </tbody>
  <tfoot>
    <tr> <td colspan="2">Closed on public holidays</td> </tr>
  </tfoot>
</table>

Use tables for data, never for layout. colspan and rowspan merge cells; <colgroup>/<col> style whole columns. Lessons: Tables, Table Headers and Captions, Colspan and Rowspan, Accessible Tables.

A table with merged cells

Page structure

Element Role
<header> Intro or banner for the page or a section
<nav> Major navigation links
<main> The page's main content (one visible per page)
<article> Self-contained content: post, card, comment
<section> Thematic group with its own heading
<aside> Related but secondary content
<footer> Footer for the page or a section
<search> Wraps a search form
<div> / <span> No meaning: block / inline hooks for styling

Lessons: Semantic Elements, Page Layout, Div and Span, Classes, IDs.

The head and SEO

HTML
<meta name="robots" content="noindex">
<link rel="canonical" href="https://example.com/guide">
<meta property="og:title" content="The Guide">
<meta property="og:image" content="https://example.com/og/guide.png">
<meta name="theme-color" content="#0f766e">
<link rel="preload" href="/fonts/inter.woff2" as="font" type="font/woff2" crossorigin>
<script type="application/ld+json">{ "@context": "https://schema.org", "@type": "Article" }</script>

Lessons: Page Titles, Social Sharing, Structured Data, Resource Loading.

Scripts and styles

Code Behavior
<script src="a.js"></script> Blocks parsing while it downloads and runs
<script src="a.js" defer></script> Downloads in parallel, runs in order after parsing
<script src="a.js" async></script> Runs as soon as it arrives, in any order
<script type="module" src="a.js"></script> Deferred by default, supports import
<link rel="stylesheet" href="a.css"> External stylesheet (preferred)
<style>…</style> / style="…" Internal styles / inline styles

Lessons: Adding CSS, Adding JavaScript, The DOM.

Forms

HTML
<form action="/signup" method="post">
  <label for="email">Email</label>
  <input id="email" name="email" type="email" required autocomplete="email">

  <label for="pw">Password</label>
  <input id="pw" name="password" type="password" minlength="8" required>

  <fieldset>
    <legend>Plan</legend>
    <label><input type="radio" name="plan" value="free" checked> Free</label>
    <label><input type="radio" name="plan" value="pro"> Pro</label>
  </fieldset>

  <label for="country">Country</label>
  <select id="country" name="country"> <option value="pt">Portugal</option> </select>

  <label for="note">Note</label>
  <textarea id="note" name="note" rows="3"></textarea>

  <button>Sign up</button>
</form>
Input types Validation attributes Other useful attributes
text, email, password, url, tel, search required name (sent with the form)
number, range min, max, step value, placeholder
date, time, datetime-local, month, week minlength, maxlength autocomplete, inputmode
checkbox, radio pattern disabled, readonly
file, color, hidden novalidate (on the form) multiple, accept, list
  • Every control needs a <label> (for = the control's id, or wrap it).
  • Only controls with a name are submitted. A <button> inside a form submits by default; use type="button" for anything else.
  • <datalist> suggests values; <output>, <meter> and <progress> show results, gauges and progress.

Lessons: Forms, Input Types, Input Attributes, Form Validation, Labels and Fieldsets, Select and Datalist, Output, Meter and Progress.

Built-in validation in action

Interactive elements

HTML
<details name="faq" open>
  <summary>Question</summary>
  <p>Answer. Same name = only one open at a time.</p>
</details>

<dialog id="confirm-delete">
  <form method="dialog"> <button value="ok">OK</button> </form>
</dialog>
<button type="button" id="open-confirm">Open</button>
<!-- script: openButton.addEventListener("click", () => dialog.showModal()) -->

<button popovertarget="tips">Tips</button>
<div id="tips" popover>Light-dismiss popup, no JavaScript needed.</div>

Lessons: Details and Summary, Dialog, Popover.

details, dialog and popover

Global attributes

Attribute Purpose
id, class Unique hook / reusable group name
style, title Inline CSS / advisory tooltip text
lang, dir Language and text direction of the content
hidden Not rendered (until-found lets find-in-page reveal it)
tabindex 0 = focusable in order, -1 = focusable by script only
data-* Your own data, read with element.dataset
contenteditable, draggable, spellcheck Editing, drag-and-drop, spell checking
inert Makes a subtree unclickable and unfocusable
popover, autofocus, translate, accesskey Popover, initial focus, translation, shortcut key

Lessons: Global Attributes, Data Attributes.

Accessibility essentials

  • Use the right element first: <button> for actions, <a href> for navigation, real headings, lists and labels.
  • Every image has alt; every control has a label; every page has lang and a unique <title>.
  • Keep focus visible and reachable by keyboard; don't add a positive tabindex.
  • Use ARIA only to fill gaps: aria-label, aria-expanded, aria-current, aria-live, aria-describedby. No ARIA is better than wrong ARIA.

Lessons: Accessibility Basics, ARIA, Keyboard and Focus.

Check your understanding

Quick check Β· 4 questions

of 4 answered You scored / 4 Β· perfect!

  1. 1. Which script tag downloads in parallel and runs after the document is parsed, in order?

    defer scripts download alongside parsing and run in document order once parsing is done. async scripts run as soon as they arrive.
  2. 2. What is the right alt for a purely decorative swirl image?

    An empty alt tells assistive technology to skip the image. A missing alt makes some screen readers read the file name instead.
  3. 3. Which form control value is NOT sent when the form is submitted?

    Only controls with a name attribute become part of the submitted data.
  4. 4. How do you make several <details> elements behave as an accordion where only one is open?

    Details elements that share a name form a group, and opening one closes the others.

Summary

  • Start every page with the doctype, <html lang>, charset, viewport and a unique <title>.
  • Pick elements for meaning: headings, paragraphs, lists, tables for data, landmarks for structure.
  • Images need alt, width and height; use srcset, sizes and <picture> for responsive images.
  • Forms need labels, name attributes and built-in validation before any JavaScript.
  • <details>, <dialog> and popover give you interactive widgets with little or no script.
  • Keep this page open while you practice, and follow the lesson links whenever a detail is fuzzy.

Next: HTML Practice Exercises β€” put everything on this page to work with graded exercises.