Phase 2: Core HTML 35 min interactive guide⭐ Foundation of Every Webpage

HTML Fundamentals: Building the Structure of Web Pages

Learn how HTML elements, tags, attributes, semantic hierarchy, accessible forms, tables, and media create the skeleton of modern web applications. Build and test live HTML pages right in your browser.

01

1. What Is HTML?

HTML (HyperText Markup Language) is the standard markup language used to structure documents displayed in web browsers. It is NOT a programming language (it has no variables, functions, or execution loops) — rather, it tells the browser what content exists and what role that content serves.

Structure

🧱 HTML

The raw skeleton. Defines headings, text, buttons, forms, links, and images.

Presentation

🎨 CSS

The skin and styling. Adds colors, layouts, typography, grids, and responsive design.

Interactivity

⚡ JavaScript

The nervous system. Handles click logic, data fetching from APIs, and state changes.

02

2. How HTML Works with the Browser

When a browser receives an HTML text stream over HTTP:

  1. Bytes to Characters: Converts raw binary bytes into characters based on the document encoding (e.g. UTF-8).
  2. Tokenization: Identifies opening tags, closing tags, and text nodes.
  3. DOM Tree Generation: Builds the Document Object Model (DOM) — a nested parent-child tree representing every element on the page.
💡 Key Takeaway: If you write malformed HTML (e.g. forgetting to close a tag), the browser tries to self-correct using its internal error-recovery parser, which can cause subtle layout bugs. Writing clean, valid HTML prevents rendering surprises.
03

3. HTML Document Structure: The Standard Skeleton

Every valid HTML5 document must follow this standard boilerplate structure:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My First Website</title>
  </head>
  <body>
    <h1>Welcome to Pathubs</h1>
    <p>Start learning frontend engineering today.</p>
  </body>
</html>

<head> (Metadata)

Contains info for the browser and search engines: character set, title bar text, viewport scaling, favicons, and stylesheet links. Never visible directly on the page canvas.

<body> (Visible Content)

Contains everything the user sees and interacts with: headings, paragraphs, images, videos, tables, buttons, and navigation bars.

04

4. HTML Elements and Tags

Understanding the distinction between tags, elements, and void elements:

TypeSyntax PatternExamplesHas Closing Tag?
Standard Elements<tag>content</tag><p>, <h1>, <button>, <div>✅ Yes (required)
Void / Self-Closing<tag attribute="..." /><img>, <input>, <br>, <hr>, <meta>❌ No (Cannot have inner content)
Nested Elements<parent><child>..</child></parent><ul><li>Item</li></ul>✅ Yes (Strict LIFO nesting order)
05

5. Attributes: Adding Properties and Metadata

Attributes provide additional instructions or configuration to elements and are always placed inside the opening tag in name="value" format:

<a href="https://pathubs.com" target="_blank" rel="noopener noreferrer">Visit Pathubs</a>
<img src="hero.jpg" alt="Modern frontend classroom" width="600" />
<button type="submit" id="submit-btn" class="btn-primary active" data-user-id="42">Enroll Now</button>
  • id: Must be unique across the entire webpage. Used for anchor links, form associations, and specific JavaScript targeting.
  • class: Reusable classifier for styling multiple elements with CSS.
  • title: Displays a native browser tooltip when hovering over the element.
  • data-*: Custom data attributes (e.g. data-analytics-id="cart_checkout") for JavaScript to read without altering visual semantics.
06

6. Headings (h1–h6) and Paragraphs (p)

HTML provides six levels of heading tags (<h1> to <h6>) to create an outline for your document:

Heading Hierarchy

<h1>Main Page Title (1 per page)</h1>
<h2>Major Section Heading</h2>
<h3>Subsection Topic</h3>
<h4>Minor Subheading</h4>
<h5>Deep Section Level</h5>
<h6>Lowest Level Heading</h6>

Paragraphs & Line Breaks

<p>Paragraphs wrap blocks of continuous body copy.</p>
<p>Always use <p> tags instead of multiple <br><br> line breaks to separate text.</p>
07

7. Inline Text Formatting Elements

TagVisual ResultSemantic MeaningExample Code
<strong>Bold TextHigh importance / urgency<strong>Warning:</strong> Save work
<em>Italicized TextStressed emphasis in speechYou <em>must</em> attend
<mark>HighlightedRelevance in search or text reference<mark>search keyword</mark>
<small>Small textSide comments, disclaimers, copyright<small>© 2026 Pathubs</small>
<del>StrikethroughDeleted or obsolete information<del>$99</del> $49
<sub> / <sup>H2O / 102Subscript & Superscript formulasH<sub>2</sub>O
08

8. Hyperlinks: The <a> Anchor Element

The anchor tag (<a>) links documents across the internet or navigates to specific sections within the current document:

<!-- 1. Absolute External URL -->
<a href="https://github.com" target="_blank" rel="noopener noreferrer">Visit GitHub</a>

<!-- 2. Relative Internal Path -->
<a href="/about">About Us</a>

<!-- 3. Same-Page Jump Anchor -->
<a href="#faq-section">Jump to FAQ</a>

<!-- 4. Special Protocols (Email & Phone) -->
<a href="mailto:support@pathubs.com">Email Support</a>
<a href="tel:+1234567890">Call Us</a>
🛡️ Security Tip: Whenever using target="_blank" to open a new tab, always add rel="noopener noreferrer" to prevent security vulnerabilities like tab-nabbing.
09

9. Images: The <img> Element

The <img> element is a void tag requiring at minimum a src path and a descriptive alt attribute:

<img
  src="/images/profile-avatar.webp"
  alt="Portrait of Sandeep smiling in front of a laptop"
  width="300"
  height="300"
  loading="lazy"
/>
  • alt Text: Read aloud by screen readers for visually impaired learners and displayed if the image URL breaks.
  • width & height: Providing explicit pixel dimensions prevents Cumulative Layout Shift (CLS) as images load.
  • loading="lazy": Tells the browser to defer downloading images until the user scrolls near them.
10

10. Lists: Unordered, Ordered, and Description

<ul> Unordered List

Bullet points for items where order does not matter (e.g. navigation links, feature lists).

<ul>
  <li>HTML5</li>
  <li>CSS3</li>
  <li>JavaScript</li>
</ul>

<ol> Ordered List

Numbered sequence for step-by-step instructions, rankings, and recipes.

<ol>
  <li>Write HTML</li>
  <li>Style with CSS</li>
  <li>Deploy Live</li>
</ol>

<dl> Description List

Key-value pairs for glossaries, FAQs, and metadata specs.

<dl>
  <dt>DOM</dt>
  <dd>Document Object Model</dd>
</dl>
11

11. Semantic HTML: Clean Code vs "div Soup"

Semantic elements clearly describe their meaning to both the browser and the developer:

Semantic TagPurpose on the PageAvoid Doing This (div soup)
<header>Top branding, logos, search bars, and main navigation<div class="top-header-box">
<nav>Major navigational link groups<div class="nav-links">
<main>The dominant, unique content of the document (only 1 per page)<div id="content-wrapper">
<section>Thematic grouping of content, typically with a heading<div class="section-1">
<article>Self-contained, syndicatable item (e.g. blog post, card, review)<div class="post-box">
<aside>Tangentially related sidebar content (glossary, related links)<div class="sidebar">
<footer>Bottom metadata, copyright notices, terms links, and sitemaps<div class="bottom-footer">
12

12. Generic Containers: <div> vs <span>

When no semantic element matches your structural needs (e.g. creating a CSS flexbox wrapper or styling a single word):

<div> (Block-level Container)

Starts on a new line and takes up 100% of available width. Used as layout wrappers for CSS Grid or Flexbox.

<div class="grid-wrapper">
  <article>Card 1</article>
  <article>Card 2</article>
</div>

<span> (Inline-level Container)

Does not start on a new line. Takes up only the width of its text content. Used to target specific words inside paragraphs.

<p>The price is <span class="highlight">$49</span>.</p>
13

13. HTML Forms: Collecting User Input

Forms gather data to send to server endpoints or handle with JavaScript:

<form action="/api/register" method="POST">
  <div>
    <label for="user-email">Email Address:</label>
    <input type="email" id="user-email" name="email" placeholder="alex@example.com" required />
  </div>

  <div>
    <label for="user-tier">Select Plan:</label>
    <select id="user-tier" name="tier">
      <option value="free">Free Community</option>
      <option value="pro">Pro Career Track</option>
    </select>
  </div>

  <div>
    <label for="user-bio">Tell us about your learning goals:</label>
    <textarea id="user-bio" name="bio" rows="4"></textarea>
  </div>

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

Common <input> Types

type="text"

Single-line strings.

type="email"

Validates email syntax (@).

type="password"

Masks characters with dots.

type="checkbox"

Toggle options on/off.

14

14. Tables: Structuring Tabular Data

Tables must ONLY be used for displaying actual grid/matrix data (like spreadsheets, pricing matrices, and schedules) — never for page layout!

<table>
  <thead>
    <tr>
      <th>Topic</th>
      <th>Est. Time</th>
      <th>Difficulty</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>HTML Fundamentals</td>
      <td>35 min</td>
      <td>Beginner</td>
    </tr>
  </tbody>
</table>
15

15. HTML Comments

Comments are ignored by the browser and will not display on screen:

<!-- This is a single-line comment in HTML -->

<!--
  Multi-line comment:
  TODO: Connect authentication backend API endpoint
-->
16

16. File Paths and Linking CSS & JavaScript

Linking Stylesheets & Scripts

<!-- Inside <head> -->
<link rel="stylesheet" href="styles.css" />

<!-- At bottom of <body> or with defer -->
<script src="app.js" defer></script>

Relative Path Rules

  • ./style.css: Same folder as current file
  • ../images/logo.png: Up one folder directory
  • /assets/css/main.css: Absolute root path
17

17. Accessibility (a11y) Basics

Web accessibility ensures all individuals, including people with visual, motor, auditory, or cognitive disabilities, can navigate your website.

1. Descriptive Alt Text

Never leave alt="" empty unless the image is purely decorative background ornament.

2. Explicit Labels

Always connect form controls using <label for="id"> so screen readers announce input purposes.

3. Keyboard Focus

Use real native <button> and <a> elements so users can Tab and press Enter.

18

18. A Complete HTML Page: From Scratch to Reality

Here is how all these elements come together to create a production-ready, accessible webpage structure:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Sandeep • Frontend Engineer</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <header>
    <nav>
      <ul>
        <li><a href="#about">About</a></li>
        <li><a href="#projects">Projects</a></li>
        <li><a href="#contact">Contact</a></li>
      </ul>
    </nav>
  </header>

  <main>
    <section id="about">
      <h1>Hi, I'm Sandeep!</h1>
      <p>Building modern web applications with clean, semantic code.</p>
      <img src="avatar.jpg" alt="Sandeep smiling in front of laptop" width="200" height="200">
    </section>
  </main>

  <footer>
    <p>© 2026 Sandeep. Built with accessible HTML5.</p>
  </footer>
</body>
</html>
19

19. Common HTML Beginner Mistakes

Mistake 1

Using <div onclick> instead of <button>

Divs are not keyboard accessible by default. Always use native <button> for actions and <a> for page navigation.

Mistake 2

Skipping Form <label> Tags

Using only placeholders instead of permanent labels destroys usability on mobile and breaks screen reader navigation.

Mistake 3

Jumping Heading Levels

Never jump from <h1> directly to <h4> just to make text small. Control sizes with CSS!

Mistake 4

Multiple <h1> tags

Keep exactly one <h1> per document to provide a clear primary subject to search engines.

20

20. HTML Best Practices

  • Always include <!DOCTYPE html> and <html lang="en">.
  • Always provide meaningful alt text on non-decorative images.
  • Write lowercase tag and attribute names for consistency.
  • Always quote attribute values: class="active".
  • Validate your markup with the official W3C HTML Validator.
21

21. What You Should Know Before Moving to CSS

Before jumping into styling with CSS (Cascading Style Sheets):

1. Class & ID Targeting

Know how CSS selectors target tags (p), classes (.btn), and IDs (#header).

2. Block vs Inline

Understand default display behaviors: block elements start on new lines, inline elements flow inside text.

3. Clean Parent-Child Nesting

A clean DOM tree with well-structured semantic parents makes CSS Flexbox and Grid intuitive.

LIVE INTERACTIVE LAB

Build Your First HTML Page (Live Workbench)

Write HTML in the live editor on the left and see it instantly rendered on the right. Complete the 5 guided challenges or build any layout you like!

index.html
Insert:
https://my-first-html-page.local

My Awesome Website

Welcome to my first web page built with semantic HTML5!

Explore More Resources →

Laptop with code on screen

Challenge 1 Completed! Valid heading tag detected.
TEST YOUR KNOWLEDGE

HTML Fundamentals Mastery Quiz

8 practical questions covering HTML elements, document skeleton, semantic tags, accessibility (a11y), and forms.

Question 1 of 8Score: 0 / 8
🧱 What is the primary purpose of HTML in web development?