Language cheatsheet
HTML 5 Cheatsheet
HTML5 page structure, text, links, images, forms, tables and metadata, with accessible patterns.
Page structure
- Basic page — A complete HTML5 document with a language, character set and responsive viewport.
- Link a stylesheet — Load a CSS file from the head.
- Load a script without blocking — defer downloads the script in parallel and runs it after the HTML is parsed.
- Use semantic landmarks — Structure the page with elements that screen readers and search engines understand.
- Write a comment — Leave a note that browsers do not display.
Metadata and SEO
- Add a meta description — Write the summary search engines often show under your title. About 150 characters works well.
- Set the canonical URL — Tell search engines which URL is the preferred version of this page.
- Add Open Graph tags — Control how the page looks when shared on social networks and chat apps.
- Keep a page out of search results — Ask search engines not to index the page.
- Add a favicon — Set the icon shown in browser tabs.
- Add structured data — Describe the page to search engines with JSON-LD.
Text, links and media
- Write headings — Use one h1 per page, then h2 to h6 in order without skipping levels.
- Create a link — Link to a page. target="_blank" with rel="noopener" opens a new tab safely.
- Link to a section of the page — Give an element an id and link to it with a hash.
- Add an image — Always include alt text, and width and height to avoid layout shift. loading="lazy" defers off-screen images.
- Serve images for different screens — Let the browser choose the best size.
- Offer modern image formats — Use WebP or AVIF where supported, with a fallback.
- Make lists — Unordered, ordered and description lists.
- Embed a video — Play a video file with controls and a fallback message.
- Embed another page — Embed content lazily, and restrict what it can do with sandbox.
- Add a collapsible section — Show and hide content with no JavaScript.
- Create a modal dialog — Use the built-in dialog element. Call showModal() to open it and close() to close it.
Forms
- Build a form — Label every control. The for attribute matches the input's id.
- Choose an input type — The right type gives mobile users the right keyboard and built-in validation.
- Validate in the browser — Constrain input with built-in attributes. Always validate on the server too.
- Add a dropdown — Offer a list of choices in a dropdown.
- Add radio buttons and checkboxes — Radio buttons that share a name allow one choice.
- Add a multi-line field — Let users write longer text.
- Group related fields — Group controls with a caption, which screen readers announce.
- Accept a file upload — A form that uploads files needs the multipart encoding.
Tables and accessibility
- Create a table — Use a caption, header cells with scope, and grouped sections.
- Add a skip link — Let keyboard users jump past the navigation to the main content.
- Name an icon button — Give a button with no text an accessible name.
- Store custom data on an element — Attach data that JavaScript can read through dataset.
- Write special characters — Escape characters that HTML treats as markup.
Related cheatsheets
- C++ 23 cheatsheet — Compile and debug C++ with g++ and CMake, and use modern C++ (up to C++23): containers, algorithms, smart pointers, templates and threads.
- C# 14 cheatsheet — Modern C# 14 syntax for strings, nullability, collections, LINQ, records, pattern matching, async code and generics.
- CSS 3 cheatsheet — Layout with flexbox and grid, responsive design, custom properties, animations and modern selectors.
- Go 1 cheatsheet — The go command for modules, building, testing and cross-compiling, plus the code patterns you write every day.
- Java, Maven and Gradle 25 cheatsheet — JDK commands to compile, run and diagnose Java programs, plus the Maven and Gradle commands for builds and tests.
- JavaScript 2025 cheatsheet — Modern JavaScript for arrays, strings, objects, async code, the DOM and modules, in copy-ready snippets.