Skip to content

HTML Cheat Sheet

Site build October 2026 — calculations run locally

HTML Cheatsheet

Search code, tasks or categories in English or Spanish. Copy a snippet and adapt it to the stated context.

Showing 71 of 71 elements

HTML patterns belong in the relevant part of a document. Adapt sample URLs, text and attributes; standalone tags and alternatives are syntax references, not complete documents. Form controls need labels and a real endpoint or JavaScript to process submissions.

HTML5 document type declaration

Structure · Pattern / syntax
<!DOCTYPE html>

Root element; set the document language

Structure · Pattern / syntax
<html lang="en">

Use the language tag that matches the document content, such as en or es.

Document metadata container

Structure · Pattern / syntax
<head>

Document body (visible content)

Structure · Pattern / syntax
<body>

Generic block container

Structure · Pattern / syntax
<div>

Generic inline container

Structure · Pattern / syntax
<span>

Link external stylesheet

Structure · Pattern / syntax
<link rel="stylesheet" href="style.css">

Link external script (deferred)

Structure · Pattern / syntax
<script src="app.js" defer></script>

Reusable HTML template (not rendered)

Structure · Pattern / syntax
<template>

Six semantic heading levels

Text · Pattern / syntax
<h1> to <h6>

h1 is the highest level and h6 the lowest; use CSS for visual size.

Paragraph

Text · Pattern / syntax
<p>

Hyperlink

Text · Pattern / syntax
<a href="url">

Link opening in new tab (secure)

Text · Pattern / syntax
<a href="url" target="_blank" rel="noopener">

Strong importance / stylistic attention

Text · Pattern / syntax
<strong> / <b>

strong marks importance; b draws attention without adding importance. Choose by meaning, not bold appearance.

Emphasis / alternate voice or term

Text · Pattern / syntax
<em> / <i>

em marks stress emphasis; i marks text set apart without that emphasis. Choose by meaning, not italic appearance.

Line break

Text · Pattern / syntax
<br>

Horizontal rule / thematic break

Text · Pattern / syntax
<hr>

Unordered list

Text · Pattern / syntax
<ul>
  <li>Item</li>
</ul>

Ordered list

Text · Pattern / syntax
<ol>
  <li>Item</li>
</ol>

Block quotation

Text · Pattern / syntax
<blockquote>

Inline code / preformatted text

Text · Pattern / syntax
<code> / <pre>

Highlighted text

Text · Pattern / syntax
<mark>

Abbreviation with tooltip

Text · Pattern / syntax
<abbr title="Full Text">FT</abbr>

Form element

Forms · Pattern / syntax
<form action="/submit" method="POST">

Text input

Forms · Pattern / syntax
<input type="text" name="q" placeholder="Search">

Email input with validation

Forms · Pattern / syntax
<input type="email" required>

Password input (masked)

Forms · Pattern / syntax
<input type="password">

Number input with range

Forms · Pattern / syntax
<input type="number" min="0" max="100" step="1">

Checkbox input

Forms · Pattern / syntax
<input type="checkbox" checked>

Radio button (grouped by name)

Forms · Pattern / syntax
<input type="radio" name="group" value="a">

Select multiple image files

Forms · Pattern / syntax
<input type="file" accept="image/*" multiple>

accept is a file-picker hint, not validation. This control selects files; a form submission or JavaScript is needed to upload or process them.

Accessible contact form document

Forms · Complete example
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Contact</title>
</head>
<body>
  <main>
    <h1>Contact us</h1>
    <form action="/contact" method="post">
      <label for="email">Email</label>
      <input id="email" name="email" type="email" autocomplete="email" required>
      <button type="submit">Send</button>
    </form>
  </main>
</body>
</html>

Replace /contact with a real endpoint. This example does not receive or store submissions.

Slider input

Forms · Pattern / syntax
<input type="range" min="0" max="100">

Date picker input

Forms · Pattern / syntax
<input type="date">

Color picker input

Forms · Pattern / syntax
<input type="color">

Multi-line text input

Forms · Pattern / syntax
<textarea rows="4" cols="50"></textarea>

Dropdown select

Forms · Pattern / syntax
<select>
  <option value="a">A</option>
</select>

Label linked to input by id

Forms · Pattern / syntax
<label for="email">Email</label>

Submit button

Forms · Pattern / syntax
<button type="submit">Send</button>

Group form elements

Forms · Pattern / syntax
<fieldset>
  <legend>Title</legend>
</fieldset>

Autocomplete suggestions

Forms · Pattern / syntax
<datalist id="opts">
  <option value="A">
</datalist>

Image with lazy loading

Media · Pattern / syntax
<img src="img.jpg" alt="Description" loading="lazy">

Responsive image with formats

Media · Pattern / syntax
<picture>
  <source srcset="img.webp" type="image/webp">
  <img src="img.jpg" alt="">
</picture>

Video with controls

Media · Pattern / syntax
<video src="vid.mp4" controls autoplay muted></video>

Audio player

Media · Pattern / syntax
<audio src="audio.mp3" controls></audio>

Embedded frame (video, maps)

Media · Pattern / syntax
<iframe src="url" title="Embed"></iframe>

Drawing surface for JS

Media · Pattern / syntax
<canvas id="c" width="300" height="150"></canvas>

Scalable vector graphics container

Media · Pattern / syntax
<svg viewBox="0 0 100 100">

Complete table structure

Tables · Pattern / syntax
<table>
  <thead>
    <tr><th>Name</th></tr>
  </thead>
  <tbody>
    <tr><td>John</td></tr>
  </tbody>
</table>

Header spanning 2 columns

Tables · Pattern / syntax
<th colspan="2">

Cell spanning 3 rows

Tables · Pattern / syntax
<td rowspan="3">

Table caption (accessibility)

Tables · Pattern / syntax
<caption>Table Title</caption>

Page or section header

Semantic · Pattern / syntax
<header>

Navigation links

Semantic · Pattern / syntax
<nav>

Main content (one per page)

Semantic · Pattern / syntax
<main>

Self-contained content

Semantic · Pattern / syntax
<article>

Thematic grouping of content

Semantic · Pattern / syntax
<section>

Sidebar / tangential content

Semantic · Pattern / syntax
<aside>

Page or section footer

Semantic · Pattern / syntax
<footer>

Figure with caption

Semantic · Pattern / syntax
<figure>
  <img src="" alt="">
  <figcaption>Caption</figcaption>
</figure>

Collapsible details

Semantic · Pattern / syntax
<details>
  <summary>Click to expand</summary>
  Hidden content
</details>

Dialog open without modality

Semantic · Pattern / syntax
<dialog open>Non-modal content</dialog>

The open attribute displays a non-modal dialog. Use showModal() in JavaScript when a modal dialog is intended.

Machine-readable date/time

Semantic · Pattern / syntax
<time datetime="2025-01-15">Jan 15</time>

Character encoding

Meta · Pattern / syntax
<meta charset="UTF-8">

Responsive viewport

Meta · Pattern / syntax
<meta name="viewport" content="width=device-width, initial-scale=1.0">

SEO description

Meta · Pattern / syntax
<meta name="description" content="Page description">

Open Graph title (social)

Meta · Pattern / syntax
<meta property="og:title" content="Title">

Search engine directives

Meta · Pattern / syntax
<meta name="robots" content="index, follow">

Favicon

Meta · Pattern / syntax
<link rel="icon" href="favicon.ico">

Canonical URL (avoid duplicates)

Meta · Pattern / syntax
<link rel="canonical" href="url">

Document title (shown in tab)

Meta · Pattern / syntax
<title>Page Title</title>

HTML Cheat Sheet — Tags, Forms, Semantic Elements and Attributes

Find HTML patterns by task or category, then copy and adapt them. Most entries show syntax to place inside an existing document; the complete form example includes document structure, a language declaration, labels and a submit button. Its action URL is a placeholder: you need an endpoint or JavaScript to process submissions. The file input selects files; it does not upload them on its own.

Using HTML with accessible names and clear semantics

Set lang to match the document content so assistive technology can select appropriate pronunciation. Connect each form label to its control with matching for and id values. Give informative images an alternative that conveys their purpose; use alt="" for purely decorative images. Missing alt can cause a screen reader to announce a filename or other fallback. Use heading levels for structure and CSS for appearance. Set a button type explicitly: type="button" for a separate action or type="submit" to submit a form. An open dialog is non-modal; JavaScript showModal() opens it as a modal.

  • Tags and copyable patterns grouped by task
  • 7 categories from structure to metadata
  • Common form controls with a labelled example
  • Semantic elements and language attributes
  • Keyboard-accessible filters and copy controls
  • Copy feedback and contextual documentation

Free. No signup. Your inputs stay in your browser. Ads via Google AdSense (consent required).

By ·