HTML5 APIs Cheat Sheet
This lesson explains HTML5 APIs Cheat Sheet with clear examples, use cases, and best practices so you can use HTML5 APIs confidently in real web applications.
HTML5 Cheatsheet by Category
This HTML5 cheatsheet is a detailed quick reference for modern HTML5
elements, attributes, semantic tags, forms, media, graphics, browser APIs,
accessibility, SEO, and performance. It is useful for beginners,
frontend developers, full-stack developers, interview preparation, and
real-world web development.
HTML5 is more than page markup. It provides semantic structure, native
multimedia, advanced form validation, client-side storage, graphics,
offline support, and powerful browser APIs for building modern web
applications.
1. HTML5 Document Structure
| Feature | Syntax | Purpose |
| Doctype | <!DOCTYPE html> | Enables standards mode in modern browsers. |
| HTML Root | <html lang="en"> | Defines the document root and page language. |
| Head | <head>...</head> | Contains metadata, title, styles, and scripts. |
| Body | <body>...</body> | Contains visible page content. |
| Charset | <meta charset="UTF-8"> | Defines character encoding. |
| Viewport | <meta name="viewport" content="width=device-width, initial-scale=1.0"> | Enables responsive layouts on mobile devices. |
| Page Title | <title>HTML5 Cheatsheet</title> | Defines browser tab title and SEO page title. |
| Description | <meta name="description" content="HTML5 guide"> | Provides SEO-friendly page summary. |
2. Semantic HTML5 Elements
| Element | Syntax | Use Case |
| Header | <header></header> | Introductory content for a page or section. |
| Navigation | <nav></nav> | Main navigation or important link groups. |
| Main | <main></main> | Main unique content of the page. |
| Section | <section></section> | Thematic group of related content. |
| Article | <article></article> | Independent reusable content such as a blog post. |
| Aside | <aside></aside> | Sidebar, note, ad, or related content. |
| Footer | <footer></footer> | Footer content for a page or section. |
| Figure | <figure><figcaption>Caption</figcaption></figure> | Media content with a caption. |
3. Text & Content Elements
| Element | Syntax | Purpose |
| Heading | <h1>Title</h1> | Creates page and section headings. |
| Paragraph | <p>Text</p> | Defines paragraph content. |
| Strong | <strong>Important</strong> | Marks important text semantically. |
| Emphasis | <em>Emphasized</em> | Marks emphasized text. |
| Code | <code>const x = 1;</code> | Displays inline code. |
| Preformatted | <pre><code>...</code></pre> | Displays code blocks with spacing preserved. |
| Blockquote | <blockquote>Quote</blockquote> | Represents quoted content. |
| Time | <time datetime="2026-06-26">June 26, 2026</time> | Represents machine-readable date and time. |
4. Links & Lists
| Element | Syntax | Best Use |
| Anchor Link | <a href="/about">About</a> | Navigate to pages, sections, files, or external sites. |
| External Link | <a href="https://example.com" target="_blank" rel="noopener">Visit</a> | Open external links safely in a new tab. |
| Unordered List | <ul><li>Item</li></ul> | Group related items without order. |
| Ordered List | <ol><li>Step</li></ol> | Display ordered steps or rankings. |
| Description List | <dl><dt>HTML</dt><dd>Markup language</dd></dl> | Display terms and definitions. |
7. Tables
| Element | Syntax | Purpose |
| Table | <table></table> | Displays tabular data. |
| Caption | <caption>Sales Report</caption> | Provides an accessible table title. |
| Table Header | <th scope="col">Name</th> | Defines row or column headers. |
| Table Row | <tr></tr> | Defines a table row. |
| Table Cell | <td>Data</td> | Defines a data cell. |
| Table Sections | <thead><tbody><tfoot> | Organizes table content semantically. |
8. Graphics & Drawing
| Feature | Syntax | Use Case |
| Canvas | <canvas id="canvas" width="500" height="300"></canvas> | Pixel-based drawing, games, charts, animations. |
| 2D Context | canvas.getContext("2d") | Draw shapes, text, images, and paths. |
| SVG | <svg><circle cx="50" cy="50" r="40" /></svg> | Scalable vector graphics, icons, diagrams. |
| WebGL | canvas.getContext("webgl") | GPU-powered 2D and 3D graphics. |
9. Storage APIs
| API | Syntax | Use Case |
| Local Storage | localStorage.setItem("theme", "dark") | Persistent small key-value storage. |
| Session Storage | sessionStorage.setItem("step", "1") | Temporary tab-based storage. |
| IndexedDB | indexedDB.open("app-db") | Large structured client-side database. |
| Cache API | caches.open("v1") | Stores requests and responses for offline support. |
10. Popular Browser APIs
| API | Syntax | Purpose |
| Fetch API | fetch("/api/data") | Make HTTP requests. |
| Geolocation API | navigator.geolocation.getCurrentPosition() | Access user location with permission. |
| Clipboard API | navigator.clipboard.writeText("Copied") | Read or write clipboard data. |
| Notification API | Notification.requestPermission() | Show system notifications. |
| History API | history.pushState({}, "", "/page") | Update URL without full page reload. |
| Fullscreen API | element.requestFullscreen() | Display content in fullscreen mode. |
| Broadcast Channel | new BroadcastChannel("app") | Communicate between same-origin tabs. |
| Web Workers | new Worker("worker.js") | Run JavaScript in background threads. |
| Service Workers | navigator.serviceWorker.register("/sw.js") | Enable caching, offline support, and PWA features. |
13. Accessibility & SEO Essentials
| Practice | Syntax | Benefit |
| Page Language | <html lang="en"> | Improves screen reader pronunciation and SEO. |
| Alt Text | <img src="logo.png" alt="Company logo"> | Describes images for assistive technologies. |
| Form Label | <label for="name">Name</label> | Makes form controls accessible. |
| ARIA Label | <button aria-label="Close menu">×</button> | Provides accessible names when visible text is missing. |
| Meta Description | <meta name="description" content="Learn HTML5"> | Provides search engine page summary. |
| Canonical URL | <link rel="canonical" href="https://example.com/html5"> | Prevents duplicate SEO indexing issues. |
HTML5 Cheatsheet Best Practices
- Use semantic HTML before using generic
div elements. - Include the HTML5 doctype, language attribute, charset, and viewport meta tag.
- Use labels, alt text, headings, landmarks, and accessible media captions.
- Choose native controls before building custom JavaScript widgets.
- Validate HTML and test across modern desktop and mobile browsers.
- Use feature detection before relying on advanced browser APIs.
- Optimize images, scripts, styles, and media for performance.
- Keep HTML clean, readable, SEO-friendly, and maintainable.
Pro Tip
Treat this cheatsheet as a coding checklist. Before publishing a page,
verify semantic structure, accessibility, responsive metadata, SEO tags,
optimized media, valid forms, and browser API fallbacks. Clean HTML5
improves SEO, accessibility, performance, and long-term maintainability.