HTML Cheat Sheet with Examples & Best Practices
Complete HTML5 cheat sheet covering document structure, semantic tags, forms, inputs, tables, media, native dialogs, accessibility, and modern best practices.
2026-09-10 ยท 9 min read
HTML & Web Development Complete Tutorial Series & Course List
Master HTML5 tags, forms, tables, dropdowns, lists, Google Fonts, VS Code tools, and web development fundamentals step-by-step with 11 complete tutorials.
Hello my friend! Today I share with you complete HTML Cheat Sheet with clear code examples, modern HTML5 semantic elements, interactive components, forms, tables, media tags, and essential accessibility tips!
This cheat sheet is designed as a fast reference for web developers, beginners, and experienced programmers. Bookmark this page and use it whenever you write HTML! Let's get started!
1. Modern HTML5 Document Skeleton
Every HTML5 document starts with a standard boiler structure containing standard UTF-8 charset, responsive viewport meta tags, page title, and linked stylesheets.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document Title - My Website</title>
<!-- Primary Meta Tags -->
<meta name="description" content="A brief description of your website for search engines." />
<!-- Open Graph / Social Media Meta -->
<meta property="og:title" content="Document Title - My Website" />
<meta property="og:description" content="A brief description of your website." />
<meta property="og:image" content="https://example.com/og-image.jpg" />
<!-- Favicon & Stylesheet -->
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<!-- Page content goes here -->
<header>
<h1>Welcome to My Website</h1>
</header>
<main>
<p>Main content area.</p>
</main>
<footer>
<p>© 2026 My Website. All rights reserved.</p>
</footer>
</body>
</html>
๐ก Tip: Always include
<meta name="viewport" content="width=device-width, initial-scale=1.0">inside<head>to ensure mobile responsiveness on mobile phones and tablets!
2. Semantic Structural Elements
Semantic HTML tags give meaning to webpage structure for search engine crawlers (SEO) and screen readers (Accessibility).
<!-- Main page header, logo, and navigation -->
<header>
<a href="/" class="logo">MyBrand</a>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</header>
<!-- Main content container (only one <main> per page) -->
<main>
<!-- Self-contained post or card -->
<article>
<h2>Understanding HTML5 Semantics</h2>
<p>Published on September 10, 2026 by Author</p>
<p>Article content goes here...</p>
</article>
<!-- Thematic section of content -->
<section>
<h2>Key Features</h2>
<p>Section details and list of features.</p>
</section>
<!-- Sidebar or complementary content -->
<aside>
<h3>Related Posts</h3>
<ul>
<li><a href="#">CSS Flexbox Guide</a></li>
<li><a href="#">JavaScript Fundamentals</a></li>
</ul>
</aside>
</main>
<!-- Footer section -->
<footer>
<p>© 2026 Dev Rean. All rights reserved.</p>
</footer>
๐ก Tip: Avoid "Div Soup"! Use
<article>for standalone blog posts or cards,<section>for grouped content, and<aside>for sidebars.
3. Text Formatting & Typography
HTML provides tags for headings, paragraphs, emphasis, inline code, and quotes.
<!-- Headings (H1 to H6) -->
<h1>Main Heading (Only one H1 per page!)</h1>
<h2>Section Heading</h2>
<h3>Subsection Heading</h3>
<!-- Paragraphs & Inline Formatting -->
<p>This is a paragraph with <strong>bold text</strong> for importance and <em>italic text</em> for emphasis.</p>
<p>Highlight text using <mark>highlighted background</mark> or show <small>small fine print text</small>.</p>
<p>Chemical formula: H<sub>2</sub>O (subscript) | Math equation: E = mc<sup>2</sup> (superscript).</p>
<!-- Quotes & Abbreviations -->
<blockquote cite="https://example.com/quote-source">
<p>"Code is like humor. When you have to explain it, it's bad."</p>
</blockquote>
<p><abbr title="HyperText Markup Language">HTML</abbr> is easy to learn!</p>
<!-- Code & Preformatted Text -->
<p>Use inline code <code>const greeting = "Hello";</code> inside sentences.</p>
<pre><code>
// Preformatted code block preserving whitespace and formatting
function sayHello() {
console.log("Hello World!");
}
</code></pre>
4. Links & Navigation Buttons
Hyperlinks connect pages, jump to sections on the same page, or trigger email/phone actions.
<!-- External link opening in a new browser tab -->
<a href="https://google.com" target="_blank" rel="noopener noreferrer">
Visit Google
</a>
<!-- Internal link to another page -->
<a href="/about.html">About Us</a>
<!-- Anchor link to jump to element with id="contact-form" -->
<a href="#contact-form">Jump to Contact Form</a>
<!-- Email link -->
<a href="mailto:support@example.com">Email Support</a>
<!-- Phone call link -->
<a href="tel:+1234567890">Call Us Now</a>
<!-- Download file link -->
<a href="/downloads/cheat-sheet.pdf" download="HTML-Cheat-Sheet.pdf">
Download PDF
</a>
๐ก Tip: When opening external links with
target="_blank", ALWAYS addrel="noopener noreferrer"to prevent tab-nabbing security risks and performance slowdowns!
5. Lists (Ordered, Unordered, & Description)
Organize items into bullet points, numbered steps, or key-value dictionary definitions.
<!-- Unordered Bullet List (ul) -->
<ul>
<li>HTML5 Semantics</li>
<li>CSS Grid & Flexbox</li>
<li>Modern JavaScript</li>
</ul>
<!-- Ordered Numbered List (ol) -->
<ol>
<li>Step 1: Write HTML markup</li>
<li>Step 2: Add CSS styles</li>
<li>Step 3: Add JS interactivity</li>
</ol>
<!-- Nested List -->
<ul>
<li>Frontend Frameworks
<ul>
<li>React</li>
<li>Vue</li>
<li>Next.js</li>
</ul>
</li>
</ul>
<!-- Description List (dl) -->
<dl>
<dt>HTML</dt>
<dd>HyperText Markup Language for web page structure.</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets for visual styling.</dd>
</dl>
6. HTML Tables with Semantic Markup
Structure tabular data cleanly using <thead>, <tbody>, <tfoot>, colspan, and rowspan.
<table>
<caption>Developer Salary Overview (2026)</caption>
<thead>
<tr>
<th>Role</th>
<th>Level</th>
<th>Average Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>Frontend Developer</td>
<td>Junior</td>
<td>$65,000</td>
</tr>
<tr>
<td>Backend Developer</td>
<td>Senior</td>
<td>$120,000</td>
</tr>
<tr>
<!-- Column span spanning across 2 columns -->
<td colspan="2">Full Stack Developer Average</td>
<td>$95,000</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3">Data based on 2026 industry survey.</td>
</tr>
</tfoot>
</table>
7. Forms, Inputs, & Interactive Controls
Collect user input safely with proper input types, labels, datalists, fieldsets, and validation attributes.
<form action="/api/submit" method="POST">
<!-- Group related inputs using Fieldset & Legend -->
<fieldset>
<legend>Personal Information</legend>
<!-- Text Input -->
<div>
<label for="username">Username:</label>
<input type="text" id="username" name="username" placeholder="Enter username" required />
</div>
<!-- Email Input -->
<div>
<label for="useremail">Email Address:</label>
<input type="email" id="useremail" name="useremail" placeholder="name@example.com" required />
</div>
<!-- Password Input -->
<div>
<label for="userpass">Password:</label>
<input type="password" id="userpass" name="userpass" minlength="8" required />
</div>
</fieldset>
<fieldset>
<legend>Preferences & Choices</legend>
<!-- Checkboxes -->
<div>
<input type="checkbox" id="subscribe" name="subscribe" value="yes" checked />
<label for="subscribe">Subscribe to newsletter</label>
</div>
<!-- Radio Buttons (Shared name attribute) -->
<div>
<p>Select Plan:</p>
<input type="radio" id="plan-free" name="plan" value="free" checked />
<label for="plan-free">Free Plan</label>
<input type="radio" id="plan-pro" name="plan" value="pro" />
<label for="plan-pro">Pro Plan</label>
</div>
<!-- Select Dropdown Menu -->
<div>
<label for="country">Country:</label>
<select id="country" name="country">
<option value="">-- Choose Country --</option>
<optgroup label="Asia">
<option value="kh">Cambodia</option>
<option value="jp">Japan</option>
</optgroup>
<optgroup label="America">
<option value="us">United States</option>
</optgroup>
</select>
</div>
<!-- Auto-complete Datalist -->
<div>
<label for="browser">Preferred Browser:</label>
<input list="browsers" id="browser" name="browser" placeholder="Type or select..." />
<datalist id="browsers">
<option value="Chrome"></option>
<option value="Firefox"></option>
<option value="Safari"></option>
<option value="Edge"></option>
</datalist>
</div>
<!-- Textarea -->
<div>
<label for="message">Message:</label>
<textarea id="message" name="message" rows="4" placeholder="Write your message..."></textarea>
</div>
</fieldset>
<!-- Submit & Reset Buttons -->
<div>
<button type="submit">Submit Form</button>
<button type="reset">Reset</button>
</div>
</form>
๐ก Tip: ALWAYS pair
<input id="foo">with<label for="foo">. Clicking label text focuses the input box automatically, which is essential for mobile tap targets and screen readers!
8. Media & Embedded Content (Images, Video, Audio, & SVG)
Embed responsive images, audio tracks, videos, and scalable vector graphics.
<!-- Responsive Image with Lazy Loading -->
<img
src="developer.jpg"
alt="Developer coding on laptop"
width="800"
height="500"
loading="lazy"
/>
<!-- Picture Element for Art Direction / Next-Gen Formats -->
<picture>
<source srcset="hero-dark.webp" media="(prefers-color-scheme: dark)" type="image/webp" />
<source srcset="hero.webp" type="image/webp" />
<img src="hero.jpg" alt="Hero banner image" loading="lazy" />
</picture>
<!-- Image with Caption -->
<figure>
<img src="diagram.png" alt="Architecture Diagram" />
<figcaption>Figure 1: Client-Server Web Application Architecture.</figcaption>
</figure>
<!-- Embedded Video with Controls -->
<video controls width="640" poster="thumbnail.jpg">
<source src="tutorial.mp4" type="video/mp4" />
<source src="tutorial.webm" type="video/webm" />
Your browser does not support HTML video.
</video>
<!-- Embedded Audio -->
<audio controls preload="none">
<source src="podcast.mp3" type="audio/mpeg" />
Your browser does not support audio element.
</audio>
๐ก Tip: Always specify
alt="...",width="...", andheight="..."attributes on images to prevent Layout Shift (CLS) during page render!
9. Modern Native Interactive Elements (<details>, <dialog>, & <progress>)
HTML5 provides native UI elements without requiring complex JavaScript libraries!
<!-- Native Accordion Collapsible Content -->
<details>
<summary>What is HTML5?</summary>
<p>HTML5 is the latest standard version of HyperText Markup Language used for structuring web pages.</p>
</details>
<!-- Native Progress Bar & Meter -->
<div>
<label for="file-progress">Uploading File:</label>
<progress id="file-progress" value="70" max="100">70%</progress>
</div>
<div>
<label for="disk-storage">Disk Usage:</label>
<meter id="disk-storage" value="0.8" min="0" max="1" low="0.5" high="0.85" optimum="0.3">80%</meter>
</div>
<!-- Native Dialog Modal Window -->
<dialog id="myModal">
<h2>Welcome Modal</h2>
<p>This is a native HTML5 modal dialog!</p>
<form method="dialog">
<button>Close</button>
</form>
</dialog>
<!-- JavaScript to show modal -->
<!-- document.getElementById('myModal').showModal(); -->
10. Essential Attributes & Accessibility (ARIA)
Common attributes and accessibility properties to make your website accessible to everyone.
| Attribute | Description | Example |
|---|---|---|
id | Unique identifier for an element on the page | <div id="navbar"> |
class | Reusable styling identifier | <button class="btn btn-primary"> |
title | Tooltip text on hover | <span title="More information">Hover</span> |
data-* | Custom dataset attribute accessible in JS | <div data-user-id="101"> |
tabindex | Control keyboard focus navigation | <div tabindex="0"> |
aria-label | Accessible label for screen readers | <button aria-label="Close Modal">X</button> |
aria-hidden | Hide element from screen readers | <svg aria-hidden="true">...</svg> |
hidden | Hide element visually and from screen readers | <p hidden>Secret text</p> |
11. HTML5 Best Practices (Bad โ vs Good โ )
1. Document Language & Charset
โ Bad:
<html>
<head>
<title>My Site</title>
</head>
โ Good:
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>My Site</title>
</head>
2. Semantic Structural Containers
โ Bad (Div Soup):
<div class="header">
<div class="nav">Links</div>
</div>
<div class="main">Content</div>
โ Good (Semantic Tags):
<header>
<nav>Links</nav>
</header>
<main>Content</main>
3. Accessible Form Labels
โ Bad (Unlinked Label):
<span>Email:</span>
<input type="email" name="email" />
โ Good (Explicitly Linked Label):
<label for="user-email">Email:</label>
<input type="email" id="user-email" name="email" />
Summary Checklist for HTML Developers
- Use
<!DOCTYPE html>declaration at the very top. - Set
<html lang="en">and UTF-8 meta charset. - Add responsive viewport meta tag inside
<head>. - Only use one
<h1>tag per page for main title. - Use semantic tags (
<header>,<nav>,<main>,<article>,<section>,<footer>). - Connect form inputs with
<label for="...">. - Provide descriptive
altattributes for images. - Add
rel="noopener noreferrer"to external links usingtarget="_blank".
If you found this cheat sheet helpful, share it with your developer friends! Happy coding! ๐
HTML & Web Development Complete Tutorial Series & Course List
Master HTML5 tags, forms, tables, dropdowns, lists, Google Fonts, VS Code tools, and web development fundamentals step-by-step with 11 complete tutorials.