The Complete HTML Guide

Every HTML topic in one page โ€” from your first tag to HTML5 APIs. Bookmark this as your permanent reference. Each section links to a deeper lesson where available.

01Document Structure

Every HTML page has the same skeleton. Browsers are forgiving, but writing it correctly matters for SEO and rendering mode.

html
<!DOCTYPE html>                  <!-- HTML5 mode โ€” always first line -->
<html lang="en">                 <!-- lang helps screen readers & SEO -->
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Page Title</title>      <!-- shown in the browser tab -->
</head>
<body>
  <!-- everything visible goes here -->
</body>
</html>

Deeper lesson: Your First HTML Page

02Text & Headings

html
<h1>Main title โ€” one per page</h1>
<h2>Section heading</h2>         <!-- h1 โ†’ h6, never skip levels -->
<p>A paragraph of text.</p>
<strong>Important</strong> and <em>emphasized</em> text.
<mark>Highlighted</mark>, <del>deleted</del>, <ins>inserted</ins>,
<sub>subscript</sub>, <sup>superscript</sup>, <small>fine print</small>
<br>  <!-- line break -->   <hr>  <!-- horizontal rule -->
<blockquote cite="src">A long quotation.</blockquote>
<pre><code>preformatted   code</code></pre>
<abbr title="HyperText Markup Language">HTML</abbr>

Interview favourite: <strong>/<em> carry meaning (semantics) for screen readers; <b>/<i> are purely visual. Prefer the semantic pair.

Deeper lessons: Headings ยท Paragraphs & Text

html
<a href="https://example.com">External link</a>
<a href="/about.php">Internal link</a>
<a href="#section-id">Jump to a section on this page</a>
<a href="mailto:hi@site.com">Email</a>
<a href="tel:+919876543210">Call</a>
<a href="file.pdf" download>Download file</a>
<a href="https://example.com" target="_blank" rel="noopener noreferrer">
  New tab (always add rel for security)
</a>

Deeper lesson: Links in depth

04Images

html
<img src="photo.jpg" alt="Description for accessibility & SEO"
     width="600" height="400" loading="lazy">

<!-- Responsive images โ€” browser picks the best size -->
<picture>
  <source media="(max-width: 600px)" srcset="small.webp">
  <source srcset="large.webp" type="image/webp">
  <img src="fallback.jpg" alt="...">
</picture>

<figure>
  <img src="chart.png" alt="Sales chart">
  <figcaption>Fig 1 โ€” Quarterly sales</figcaption>
</figure>

Deeper lesson: Images

05Lists

html
<ul><li>Unordered โ€” bullets</li></ul>
<ol start="5" reversed type="A"><li>Ordered โ€” numbered</li></ol>
<dl>                              <!-- description list -->
  <dt>HTML</dt><dd>Structure</dd>
  <dt>CSS</dt><dd>Styling</dd>
</dl>

Lists nest โ€” a <ul> inside an <li> makes sub-menus. Deeper lesson: Lists

06Tables

html
<table>
  <caption>Semester Marks</caption>
  <thead>
    <tr><th scope="col">Subject</th><th scope="col">Grade</th></tr>
  </thead>
  <tbody>
    <tr><td>Data Structures</td><td>A+</td></tr>
    <tr><td colspan="2">spans two columns</td></tr>
    <tr><td rowspan="2">spans two rows</td><td>โ€ฆ</td></tr>
  </tbody>
  <tfoot><tr><td>GPA</td><td>9.1</td></tr></tfoot>
</table>

Tables are for tabular data only โ€” never for page layout (that's CSS Grid's job). Deeper lesson: Tables

07Forms โ€” The Complete Set

html
<form action="/submit" method="post">
  <label for="name">Name</label>
  <input type="text" id="name" name="name" placeholder="Your name"
         required minlength="3" maxlength="40">

  <input type="email" name="email" required>
  <input type="password" name="pw" minlength="8">
  <input type="number" min="0" max="100" step="5">
  <input type="date">  <input type="time">  <input type="color">
  <input type="range" min="0" max="10">
  <input type="file" accept=".pdf,image/*" multiple>
  <input type="search">  <input type="tel">  <input type="url">
  <input type="hidden" name="token" value="abc">

  <input type="checkbox" id="agree" name="agree">
  <input type="radio" name="gender" value="m"> <input type="radio" name="gender" value="f">

  <select name="dept">
    <optgroup label="Engineering">
      <option value="cse" selected>CSE</option>
      <option value="it">IT</option>
    </optgroup>
  </select>

  <textarea name="msg" rows="4" placeholder="Message"></textarea>

  <input list="cities" name="city">      <!-- autocomplete -->
  <datalist id="cities">
    <option value="Chennai"><option value="Coimbatore">
  </datalist>

  <fieldset><legend>Group label</legend> โ€ฆinputsโ€ฆ </fieldset>

  <button type="submit">Send</button>
  <button type="reset">Clear</button>
</form>

Built-in validation attributes

AttributeDoes
requiredField must be filled
min / max / stepNumeric and date limits
minlength / maxlengthText length limits
pattern="[0-9]{6}"Regex the value must match (e.g., pincode)
disabled / readonlyNot editable (disabled isn't submitted, readonly is)
autocomplete="off"Disable browser autofill

Interview question: GET vs POST โ€” GET puts data in the URL (bookmarkable, ~2KB limit, never for passwords); POST sends it in the request body (secure-ish, no size limit, use for anything that changes data).

Deeper lesson: Forms

08Semantic HTML

Semantic tags describe meaning, not appearance. Google and screen readers rely on them โ€” pages built from a hundred <div>s rank worse.

html
<header>   site or section header โ€” logo, nav
<nav>      primary navigation links
<main>     the unique content โ€” exactly ONE per page
<section>  thematic grouping with a heading
<article>  self-contained content (blog post, card, comment)
<aside>    tangential content โ€” sidebar, related links
<footer>   footer of page or section
<figure> + <figcaption>   image/diagram with caption
<time datetime="2026-07-02">July 2, 2026</time>
<details> + <summary>      native accordion, no JS needed
<dialog>   native modal (open with JS: dialog.showModal())

Deeper lesson: Semantic HTML

09Audio & Video

html
<video controls width="640" poster="thumb.jpg" preload="metadata">
  <source src="movie.webm" type="video/webm">
  <source src="movie.mp4" type="video/mp4">
  <track src="subs.vtt" kind="subtitles" srclang="en" label="English">
  Fallback text for old browsers.
</video>

<audio controls loop>
  <source src="song.mp3" type="audio/mpeg">
</audio>

<!-- autoplay only works when muted (browser policy) -->
<video autoplay muted loop playsinline>โ€ฆ</video>

Deeper lesson: Audio & Video

10Iframes & Embedding

html
<!-- YouTube -->
<iframe width="560" height="315"
  src="https://www.youtube.com/embed/VIDEO_ID"
  title="YouTube video" allowfullscreen loading="lazy"></iframe>

<!-- Google Maps -->
<iframe src="https://www.google.com/maps/embed?pb=โ€ฆ"
  width="600" height="450" loading="lazy"
  referrerpolicy="no-referrer-when-downgrade"></iframe>

<!-- Sandboxed iframe โ€” restricts what embedded content can do -->
<iframe src="page.html" sandbox="allow-scripts allow-forms"></iframe>

11Block vs Inline Elements

BlockInline
New line?Starts on a new line, full widthFlows within text
width/heightRespectedIgnored (use inline-block)
Examplesdiv p h1 ul table form sectionspan a img strong em code input

<div> is the generic block container; <span> is the generic inline one. Use them only when no semantic tag fits.

12Entities & Symbols

Reserved characters must be escaped, otherwise browsers parse them as code:

To showWriteTo showWrite
<&lt;ยฉ&copy;
>&gt;โ‚น&#8377;
&&amp;โ†’&rarr;
"&quot;non-breaking space&nbsp;

13Data Attributes

Store custom data on any element โ€” the official way to pass values from HTML to JavaScript and CSS:

html
<button data-product-id="42" data-price="199">Add to cart</button>

<script>
  const btn = document.querySelector('button');
  console.log(btn.dataset.productId);  // "42"  (camelCase!)
  console.log(btn.dataset.price);      // "199"
</script>

<style>
  /* target from CSS too */
  [data-price="199"] { border: 1px solid gold; }
</style>

14Canvas & SVG

Canvas โ€” pixel drawing with JavaScript

html
<canvas id="c" width="300" height="150"></canvas>
<script>
  const ctx = document.getElementById('c').getContext('2d');
  ctx.fillStyle = '#6d6ffb';
  ctx.fillRect(20, 20, 100, 60);            // rectangle
  ctx.beginPath();
  ctx.arc(200, 60, 40, 0, Math.PI * 2);     // circle
  ctx.stroke();
</script>

SVG โ€” scalable vector shapes in markup

html
<svg width="200" height="100" viewBox="0 0 200 100">
  <rect x="10" y="10" width="80" height="50" rx="8" fill="#6d6ffb"/>
  <circle cx="150" cy="35" r="25" fill="none" stroke="#f97316" stroke-width="3"/>
  <text x="20" y="90" font-size="14">SVG text</text>
</svg>

When to use which: SVG for icons, logos, charts (crisp at any zoom, stylable with CSS). Canvas for games, image processing, thousands of drawn objects.

15Meta Tags & SEO

html
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Shown in Google results โ€” ~155 chars">
<link rel="canonical" href="https://site.com/page">
<link rel="icon" href="/favicon.ico">

<!-- Open Graph โ€” controls WhatsApp/social share preview -->
<meta property="og:title" content="Page title">
<meta property="og:description" content="Share description">
<meta property="og:image" content="https://site.com/preview.png">
<meta name="robots" content="index, follow">

Deeper lesson: Meta & SEO

16Accessibility (a11y)

Accessible sites are also better-ranked and demonstrate senior-level care in interviews:

17HTML5 APIs (Quick Tour)

APIWhat it doesOne-liner
localStoragePersistent key-value storage (~5MB)localStorage.setItem('k','v')
sessionStorageSame, cleared when tab closessessionStorage.getItem('k')
GeolocationUser's location (with permission)navigator.geolocation.getCurrentPosition(cb)
Drag & DropNative dragging<div draggable="true">
Web WorkersRun JS off the main threadnew Worker('w.js') โ€” powers our DSA judge
contenteditableMake any element editable<div contenteditable>

18Best Practices Checklist

Practice everything above in the live Code Playground, then test yourself with the 50 HTML interview questions.