Getting everything ready for you…

Loading courses, problems and your progress. This takes just a moment.

0s

HTML Documentation

The structure of every web page — elements, forms, semantic markup, accessibility and SEO basics.

HTML (HyperText Markup Language) describes the structure and meaning of web content — headings, paragraphs, links, images, forms and more. Browsers read HTML and render it as a page. CSS adds the style and JavaScript adds behaviour, but every web page starts with HTML.

1. Introduction & Setup

All you need is a text editor (VS Code is recommended) and a browser.

  1. Create a folder and a file named index.html.
  2. In VS Code, type ! and press Tab to generate a starter template.
  3. Open the file in a browser, or install the Live Server extension to auto-reload on save.
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>My First Page</title>
  </head>
  <body>
    <h1>Hello, Codify!</h1>
    <p>This is my first web page.</p>
  </body>
</html>

Output:

(browser tab title: "My First Page")
Hello, Codify!            ← large bold heading
This is my first web page.

⚠️ Common error: Hindi or emoji text shows as é / ’ garbage — add <meta charset="UTF-8"> as the first thing in <head>.

2. Basic Syntax & Document Structure

  • An element = opening tag + content + closing tag: <p>Text</p>.
  • Void elements have no closing tag: <br>, <img>, <input>, <meta>, <link>, <hr>.
  • Attributes add information: <a href="/docs" title="Docs">.
  • Elements nest — close them in reverse order: <p><strong>Hi</strong></p>.
  • <head> holds information about the page (title, meta tags, CSS links); <body> holds visible content.
  • Comments: <!-- not shown -->. HTML is not case-sensitive, but lowercase is the convention.
<body>
  <!-- Main heading -->
  <h1 id="top" class="title">Codify Docs</h1>
  <p>Learn <strong>HTML</strong>, <em>CSS</em> and JavaScript.<br />One step at a time.</p>
  <hr />
</body>

Output:

Codify Docs
Learn HTML, CSS and JavaScript.   (HTML in bold, CSS in italics)
One step at a time.
──────────────────────────────    (horizontal rule)

⚠️ Common error: wrong nesting like <p><b>text</p></b> — browsers try to fix it, but layout and CSS can break. Close inner tags first.

3. Text Elements

Element Use
<h1> … <h6> headings — one <h1> per page, don't skip levels
<p> paragraph
<strong> / <em> important (bold) / emphasis (italic)
<mark>, <small>, <del>, <ins> highlight, fine print, deleted, inserted text
<code>, <pre>, <kbd> inline code, preformatted block, keyboard input
<blockquote>, <q>, <cite> quotations
<sub>, <sup> H₂O, x²
<abbr title="..."> abbreviation with tooltip
<h2>Water formula</h2>
<p>H<sub>2</sub>O and E = mc<sup>2</sup></p>
<p>Press <kbd>Ctrl</kbd> + <kbd>S</kbd> to save. Use <code>console.log()</code> to debug.</p>
<p><mark>Exam on Monday</mark> — <del>Tuesday</del> <ins>Monday</ins></p>
<blockquote cite="https://example.com">Code is like humour. When you have to explain it, it's bad.</blockquote>
<p><abbr title="HyperText Markup Language">HTML</abbr> is easy.</p>

Output:

Water formula
H₂O and E = mc²
Press [Ctrl] + [S] to save. Use console.log() to debug.
Exam on Monday — T̶u̶e̶s̶d̶a̶y̶ Monday       (highlighted, strikethrough, underlined)
    Code is like humour. When you have to explain it, it's bad.   (indented quote)
HTML is easy.   (hover HTML → tooltip)

⚠️ Common error: using <h1>–<h6> just to make text big. Headings define the outline of the page (screen readers and Google use them) — use CSS for size.

5. Lists & Tables

<h3>Unordered list</h3>
<ul>
  <li>HTML</li>
  <li>CSS
    <ul><li>Flexbox</li><li>Grid</li></ul>
  </li>
</ul>

<h3>Ordered list</h3>
<ol start="1" type="1">
  <li>Learn HTML</li>
  <li>Learn CSS</li>
</ol>

<h3>Description list</h3>
<dl>
  <dt>DOM</dt>
  <dd>Document Object Model</dd>
</dl>

<table>
  <caption>Marks</caption>
  <thead>
    <tr><th scope="col">Name</th><th scope="col">Maths</th><th scope="col">Science</th></tr>
  </thead>
  <tbody>
    <tr><td>Asha</td><td>91</td><td>88</td></tr>
    <tr><td>Ravi</td><td colspan="2">Absent</td></tr>
  </tbody>
</table>

Output:

Unordered list
 • HTML
 • CSS
    ◦ Flexbox
    ◦ Grid
Ordered list
 1. Learn HTML
 2. Learn CSS
Description list
 DOM
     Document Object Model
            Marks
 Name | Maths | Science
 Asha |  91   |  88
 Ravi |    Absent        (spans two columns)

⚠️ Common error: using tables for page layout. Tables are for tabular data only — use CSS Flexbox/Grid for layout.

6. Forms & Inputs

<form action="/register" method="post">
  <label for="name">Full name</label>
  <input id="name" name="name" type="text" required minlength="2" placeholder="Asha Rao" />

  <label for="email">Email</label>
  <input id="email" name="email" type="email" required />

  <label for="pass">Password</label>
  <input id="pass" name="password" type="password" minlength="8" required />

  <label for="age">Age</label>
  <input id="age" name="age" type="number" min="13" max="100" />

  <label for="course">Course</label>
  <select id="course" name="course">
    <option value="dsa">DSA</option>
    <option value="web" selected>Web Development</option>
  </select>

  <fieldset>
    <legend>Level</legend>
    <label><input type="radio" name="level" value="beginner" checked /> Beginner</label>
    <label><input type="radio" name="level" value="pro" /> Pro</label>
  </fieldset>

  <label><input type="checkbox" name="terms" required /> I accept the terms</label>

  <label for="bio">About you</label>
  <textarea id="bio" name="bio" rows="3"></textarea>

  <button type="submit">Create account</button>
</form>

Output:

Full name   [Asha Rao        ]
Email       [                ]
Password    [••••••••        ]
Age         [   ▲▼]
Course      [Web Development ▼]
┌ Level ─────────────────────┐
│ (•) Beginner  ( ) Pro      │
└────────────────────────────┘
[✓] I accept the terms
About you   [                ]
[Create account]
(Submitting with an empty or invalid field shows the browser's built-in error message.)

Other input types: date, time, color, range, file, search, tel, url, hidden. method="get" puts data in the URL; method="post" sends it in the request body (use it for passwords).

⚠️ Common error: inputs without a name attribute are not sent to the server, and inputs without a <label> are inaccessible. Always add both.

7. Semantic HTML

Semantic elements describe what content is, not how it looks. They help screen readers, SEO and your own code readability.

<body>
  <header>
    <a href="/" class="logo">Codify</a>
    <nav aria-label="Main">
      <a href="/courses">Courses</a>
      <a href="/docs">Docs</a>
    </nav>
  </header>

  <main>
    <article>
      <h1>Learn Flexbox in 10 minutes</h1>
      <p>Published <time datetime="2026-10-20">20 October 2026</time></p>
      <section>
        <h2>What is Flexbox?</h2>
        <p>...</p>
      </section>
    </article>
    <aside>Related: CSS Grid</aside>
  </main>

  <footer>
    <p>&copy; 2026 Codify</p>
  </footer>
</body>
Element Meaning
<header>, <footer> intro / closing content of the page or a section
<nav> main navigation links
<main> the unique main content (one per page)
<article> self-contained content (blog post, card, comment)
<section> a thematic group with a heading
<aside> side content (related links, ads)
<figure> / <figcaption> image/diagram with caption
<time>, <address> dates, contact info

⚠️ Common error: "div soup" — building everything with <div>s. Use semantic elements first and <div>/<span> only for styling hooks.

8. Accessibility

Accessible HTML works for everyone — including people using screen readers, keyboards or zoom.

<!-- 1. Meaningful alt text (empty alt for decorative images) -->
<img src="chart.png" alt="Bar chart: Python is the most used language at 45%" />
<img src="divider.svg" alt="" />

<!-- 2. Real buttons and links (keyboard-focusable by default) -->
<button type="button" onclick="openMenu()">Menu</button>

<!-- 3. Labels for every input -->
<label for="q">Search docs</label>
<input id="q" type="search" />

<!-- 4. ARIA only when HTML has no built-in way -->
<button aria-expanded="false" aria-controls="faq1">What is HTML?</button>
<div id="faq1" hidden>HTML is the structure of web pages.</div>

<!-- 5. Language and skip link -->
<html lang="en">
<a href="#main" class="skip-link">Skip to content</a>

Checklist: one <h1> and a logical heading order, sufficient colour contrast, visible focus outlines, lang on <html>, captions for videos, and test with only the keyboard (Tab, Enter, Space). Tools: Lighthouse (Chrome DevTools) and axe.

⚠️ Common error: <div onclick="..."> as a button — it can't be focused with Tab or activated with Enter. Use <button>.

9. SEO Basics

Search engines read your HTML. Good structure + meta tags = better ranking and nicer search results.

<head>
  <title>Learn Python Free — Notes, Examples & Practice | Codify</title>
  <meta name="description" content="Free Python tutorial with examples, practice problems and a cheat sheet." />
  <link rel="canonical" href="https://example.com/docs/python" />

  <!-- Social previews (WhatsApp, LinkedIn, X) -->
  <meta property="og:title" content="Python Documentation | Codify" />
  <meta property="og:description" content="Learn Python with examples and practice." />
  <meta property="og:image" content="https://example.com/og-image.png" />
  <meta name="twitter:card" content="summary_large_image" />

  <!-- Structured data -->
  <script type="application/ld+json">
    { "@context": "https://schema.org", "@type": "Article", "headline": "Python Documentation" }
  </script>
</head>

Also: one clear <h1> containing the main keyword, descriptive link text ("Read the CSS guide", not "click here"), alt text on images, fast pages, mobile-friendly layout (viewport meta), robots.txt and sitemap.xml.

⚠️ Common error: the same <title> on every page — each page needs a unique, descriptive title (50–60 characters) and description (~155 characters).

10. Advanced Concepts

Data attributes store custom data for JavaScript:

<button data-product-id="42" data-price="499">Add to cart</button>
<script>
  document.querySelector("button").addEventListener("click", (e) => {
    const { productId, price } = e.target.dataset;   // "42", "499"
    console.log(`Added product ${productId} for ₹${price}`);
  });
</script>

Loading scripts and styles correctly:

<head>
  <link rel="stylesheet" href="styles.css" />
  <link rel="preconnect" href="https://fonts.googleapis.com" />
  <script src="app.js" defer></script>   <!-- defer: run after HTML is parsed -->
</head>

Other powerful elements: <details>/<summary> (accordion without JS), <dialog> (modal), <template>, <canvas> (drawing with JS), inline <svg> graphics, <progress> and <meter>, <datalist> (input suggestions).

<details>
  <summary>Show answer</summary>
  <p>The answer is 42.</p>
</details>
<label>Upload <progress value="70" max="100">70%</progress></label>
<input list="langs" placeholder="Pick a language" />
<datalist id="langs"><option value="Python" /><option value="Java" /></datalist>

Output:

▸ Show answer            (click to expand → "The answer is 42.")
Upload [███████░░░]
[Pick a language  ]      (typing shows Python / Java suggestions)

Also learn: HTML entities (&lt; &gt; &amp; &nbsp; &copy;), <meta http-equiv>, Open Graph, web components, and validating your HTML at validator.w3.org.

11. Examples with Output

Example 1 — Profile card

<article class="card">
  <img src="asha.jpg" alt="Photo of Asha" width="96" height="96" />
  <h2>Asha Rao</h2>
  <p>Frontend developer · Pune</p>
  <a href="https://github.com/asha" target="_blank" rel="noopener">GitHub</a>
</article>
[photo]
Asha Rao
Frontend developer · Pune
GitHub

Example 2 — Newsletter form with validation

<form>
  <label for="mail">Get weekly coding tips</label>
  <input id="mail" type="email" required placeholder="you@example.com" />
  <button>Subscribe</button>
</form>
Get weekly coding tips
[you@example.com      ] [Subscribe]
(Typing "abc" and clicking Subscribe shows: "Please include an '@' in the email address.")

Example 3 — FAQ with no JavaScript

<section>
  <h2>FAQ</h2>
  <details open><summary>Is Codify free?</summary><p>Yes, completely free.</p></details>
  <details><summary>Do I get a certificate?</summary><p>Yes, after finishing a roadmap.</p></details>
</section>
FAQ
▾ Is Codify free?
   Yes, completely free.
▸ Do I get a certificate?

12. Practice Problems

  1. Build a personal bio page: heading, photo with alt text, short intro, and a list of hobbies.
  2. Recreate a restaurant menu with headings, a description list and prices in a table.
  3. Make a registration form (name, email, password, gender radio buttons, course select, terms checkbox) using proper labels and validation attributes.
  4. Rebuild a news article page using header, nav, main, article, aside and footer.
  5. Add an FAQ section using <details> and <summary>.
  6. Create a page with an embedded YouTube video, an image with <figure>/<figcaption> and an audio player.
  7. Run your page through validator.w3.org and Lighthouse; fix every error and accessibility warning.
  8. Write the full <head> for a blog post: title, description, canonical, Open Graph tags.

13. Interview Questions

1. What is the purpose of <!DOCTYPE html>? It tells the browser to render the page in standards mode (HTML5) instead of quirks mode.

2. Block vs inline elements? Block elements (div, p, h1, section) start on a new line and take full width; inline elements (span, a, strong, img) flow within text.

3. What is semantic HTML and why does it matter? Using elements that describe meaning (header, nav, article). It improves accessibility, SEO and maintainability.

4. id vs class? An id must be unique on the page (one element); a class can be shared by many elements and an element can have several classes.

5. What do async and defer do on scripts? Both download without blocking parsing. defer runs scripts in order after the HTML is parsed; async runs each script as soon as it downloads (order not guaranteed).

6. Why is alt text important? Screen readers read it, it shows if the image fails to load, and search engines use it to understand images.

7. GET vs POST in forms? GET appends data to the URL (bookmarkable, for searches); POST sends it in the body (for sensitive data or actions that change things).

8. What are data-* attributes? Custom attributes for storing extra information on elements, readable in JS through element.dataset.

9. <section> vs <div>? <section> is a thematic grouping with a heading (semantic); <div> is a generic container with no meaning, used for styling.

10. What are meta tags? Elements in <head> providing metadata: charset, viewport (mobile layout), description (search snippet), Open Graph (social previews), robots.

14. Cheat Sheet & References

Page skeleton

<!-- Starter template -->
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Page</title></head>
<body></body>
</html>

Text

<h1>Title</h1> <h2>Subtitle</h2> <p>Paragraph</p>
<strong>bold</strong> <em>italic</em> <mark>highlight</mark> <br /> <hr />
<code>inline code</code> <pre>preformatted</pre> <blockquote>quote</blockquote>

Links and media

<a href="https://site.com" target="_blank" rel="noopener noreferrer">Link</a>
<a href="#id">Jump</a> <a href="mailto:a@b.com">Email</a>
<img src="a.png" alt="description" loading="lazy" />
<video src="v.mp4" controls></video> <audio src="a.mp3" controls></audio>

Lists and tables

<ul><li>Item</li></ul> <ol><li>Step</li></ol>
<table><thead><tr><th>H</th></tr></thead><tbody><tr><td>D</td></tr></tbody></table>

Forms

<form action="/submit" method="post"></form>
<label for="e">Email</label> <input id="e" name="email" type="email" required />
<input type="password" minlength="8" /> <input type="number" min="0" max="10" />
<input type="checkbox" checked /> <input type="radio" name="g" value="a" />
<select name="s"><option value="1">One</option></select> <textarea rows="4"></textarea>
<button type="submit">Send</button>

Semantic layout

<header></header> <nav></nav> <main></main>
<article></article> <section></section> <aside></aside> <footer></footer>
<figure><img src="x.png" alt="" /><figcaption>Caption</figcaption></figure>

Head and SEO

<meta name="description" content="Page summary" />
<link rel="canonical" href="https://site.com/page" />
<meta property="og:image" content="https://site.com/og.png" />
<link rel="stylesheet" href="style.css" /> <script src="app.js" defer></script>

Official documentation