HTMLPrintable

HTML Cheat Sheet

Every HTML tag and attribute you'll use day to day, grouped by job. Click a lesson link to learn any tag properly.

Back to the HTML tutorial

Page structure

SyntaxWhat it doesLesson
<!DOCTYPE html>Tells the browser this is a modern HTML pageStructure
<html lang="en">Wraps the whole page; lang sets the languageStructure
<head>Invisible info: title, meta tags, CSS linksHead & meta
<title>Text shown in the browser tab and search resultsHead & meta
<body>Everything visible on the pageStructure
<!-- note -->A comment the browser ignoresComments

Text

SyntaxWhat it doesLesson
<h1> … <h6>Headings, from most to least importantHeadings
<p>ParagraphParagraphs
<br>Line break (no closing tag)Paragraphs
<hr>Thematic break / divider lineParagraphs
<strong>Important text (bold)Formatting
<em>Emphasised text (italic)Formatting
<mark>Highlighted textFormatting
<code>Inline codeFormatting
<sub> / <sup>Subscript H₂O / superscript x²Formatting
<blockquote>A long quotationFormatting

Links & images

SyntaxWhat it doesLesson
<a href="url">Link to another pageLinks
target="_blank"Open link in a new tabLinks
href="#id"Jump to an element on the same pageLinks
href="mailto:x@y.com"Open an email appLinks
<img src="" alt="">Image with a text alternativeImages
width / heightImage size in pixels (prevents layout jumps)Images
loading="lazy"Load image only when it's near the screenImages
<picture> / srcsetDifferent images for different screensResponsive images

Lists

SyntaxWhat it doesLesson
<ul>Bulleted (unordered) listLists
<ol>Numbered (ordered) listLists
<li>One list itemLists
<ol start="5">Start numbering at 5Lists
<dl> <dt> <dd>Description list (term + definition)Lists

Tables

SyntaxWhat it doesLesson
<table>A table of dataTables
<caption>Table titleTables
<thead> <tbody> <tfoot>Table sectionsTables
<tr>Table rowTables
<th>Header cellTables
<td>Data cellTables
colspan="2" / rowspan="2"Cell spans several columns / rowsTables

Forms

SyntaxWhat it doesLesson
<form action="" method="post">A form that sends dataForms
<label for="id">Text label linked to an inputForms
<input type="text">Single-line text boxInput types
type="email" "password" "number"Specialised inputs with built-in checksInput types
type="checkbox" / "radio"Tick boxes / pick one optionInput types
<textarea>Multi-line text boxForms
<select> + <option>Drop-down listForms
<button type="submit">Button that sends the formForms
required placeholder nameCommon input attributesForms

Layout & semantics

SyntaxWhat it doesLesson
<div>Generic block containerDiv & span
<span>Generic inline containerDiv & span
class="x" / id="y"Reusable label / unique nameClasses & IDs
<header> <footer>Top / bottom of a page or sectionSemantic
<nav>Main navigation linksSemantic
<main>The main content (once per page)Semantic
<article> <section> <aside>Self-contained post / themed group / side contentSemantic
<details> + <summary>Click-to-expand contentInteractive
<dialog>Pop-up dialog boxInteractive

Media & embeds

SyntaxWhat it doesLesson
<video src="" controls>Video playerAudio & video
<audio src="" controls>Audio playerAudio & video
<source>Alternative media file formatsAudio & video
<iframe src="">Embed another web pageIframes
&lt; &gt; &amp; &copy;Entities for special charactersEntities

Head & SEO

SyntaxWhat it doesLesson
<meta charset="UTF-8">Character encoding (always include)Head & meta
<meta name="viewport" …>Makes the page work on phonesHead & meta
<meta name="description">Summary shown in search resultsHead & meta
<link rel="stylesheet" href="">Load a CSS fileHead & meta
<link rel="icon" href="">Favicon for the browser tabHead & meta
<script src="" defer>Load JavaScript after the HTML is readHead & meta

Text, quotes & code

SyntaxWhat it doesLesson
<blockquote cite=""> <q>Long and short quotationsQuotes & citations
<cite> <abbr title=""> <address>Work titles, abbreviations, contact detailsQuotes & citations
<pre><code>Multi-line code blockCode elements
<kbd> <samp> <var>Keys, program output, variablesCode elements
style="color: navy;"Inline colour and stylesColors & styles
<figure> + <figcaption>Captioned image, chart or codeFigure & time
<time datetime="2026-03-14"> <mark>Machine-readable date, highlighted textFigure & time
<progress value="" max=""> <meter>Task progress, measurement gaugeFigure & time

Paths, buttons & forms

SyntaxWhat it doesLesson
href="../index.html" href="/about"Relative and root-relative pathsFile paths
<button type="button">Button that runs JavaScriptButtons
<select> <option> <textarea>Dropdowns and multi-line textForm controls
<fieldset> + <legend>Group related controlsForm controls
<input list="id"> + <datalist>Typing suggestionsForm controls
required minlength pattern min maxBuilt-in validationForm validation
data-id="7" + el.dataset.idCustom data for CSS and JavaScriptData attributes

Graphics, scripts & APIs

SyntaxWhat it doesLesson
<canvas> + getContext('2d')Draw with JavaScriptCanvas
<svg viewBox="0 0 24 24">Scalable vector graphicsSVG
<script src="" defer> type="module"Load scripts without blockingScripts
youtube-nocookie.com/embed/IDPrivacy-friendly video embedEmbedding
popover + popovertargetPop-ups without JavaScriptHTML5 APIs
draggable="true" contenteditableDrag and drop, editable textHTML5 APIs

SEO, speed & responsive

SyntaxWhat it doesLesson
<link rel="canonical" href="">Main URL for search enginesSEO meta
<meta property="og:image">Social sharing previewSEO meta
<script type="application/ld+json">Structured dataSEO meta
loading="lazy" fetchpriority="high"Lazy-load or prioritise imagesPage speed
<link rel="preload"> rel="preconnect"Resource hintsPage speed
width=device-width, initial-scale=1Viewport for phonesResponsive design
<div style="overflow-x: auto">Scrollable wide tablesResponsive design

The HTML lessons behind this cheat sheet