Logo OnlineCBT
HTML Tutorial
HTML · LESSON 4

Creating Your First HTML Page

Build, save, and run your first HTML webpage in the browser.

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive
Updated: 30 Jul 2026

Creating Your First HTML Page

1. Anatomy of File Creation and Naming Conventions

Creating a webpage begins with saving source code inside a correctly formatted file. Web servers and browsers process code files based on their file extension and naming structure.

Critical Rules for Naming HTML Files

  • Always Use Lowercase: File names must be written entirely in lowercase letters (e.g., index.html instead of Index.HTML). Linux-based web servers are case-sensitive; About.html and about.html are treated as two entirely different files.
  • No Spaces in File Names: Never use spaces in file names. Spaces get converted into messy URL characters like %20 (e.g., my%20page.html). Use hyphens (my-page.html) or underscores (my_page.html) instead.
  • The Special Role of index.html: The name index.html is reserved by web servers as the default homepage entry point. When a user navigates to www.example.com, the web server automatically serves index.html without forcing the user to type the file name in the address bar.
  • Correct Extension: Every file containing HTML markup must end with the .html (or legacy .htm) file extension so operating systems and browsers map it correctly.
Pro Tip for Windows Users:

Windows hides file extensions by default. Ensure you enable "File name extensions" in File Explorer view settings, otherwise saving a file as index.html might accidentally result in a hidden text file named index.html.txt!

2. Building Your First HTML File Step-by-Step

Let's construct a minimal, standards-compliant HTML5 page manually without using auto-generation tools to understand how each tag contributes to the document tree.

Step 1: Declaring the Document Type

The very first line of your HTML document must tell the browser which specification standard to use. In modern web development, we use the HTML5 DOCTYPE declaration:

<!DOCTYPE html>

Step 2: Defining the Root Element

Directly under the DOCTYPE declaration, we wrap the entire document inside the root <html> tag. We always specify the human language using the lang attribute:

<!DOCTYPE html>
<html lang="en">

</html>

Step 3: Setting Up Document Metadata

Inside the root <html> tag, we add a <head> section to hold machine-readable data such as character encoding, responsive viewport settings, and the page title:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My First Webpage</title>
</head>
</html>

Step 4: Writing Visible Body Content

Finally, we add the <body> section, which contains all visible content displayed directly inside the main browser viewport window:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My First Webpage</title>
</head>
<body>
    <h1>Welcome to My Developer Journey</h1>
    <p>This is my very first webpage constructed manually step-by-step.</p>
</body>
</html>
Hardcoded Output Result (Browser Rendering)

Welcome to My Developer Journey

This is my very first webpage constructed manually step-by-step.

3. Essential Tags Introduced in Your First Page

To communicate structure clearly to web browsers, you must understand the specific responsibilities of primary structural tags.

Tag Syntax Element Name Primary Purpose & Responsibility
<!DOCTYPE html> DocType Declaration Informs the browser engine that the document uses modern HTML5 parsing rules.
<html> Root Element Wraps all document nodes. Contains the lang attribute for SEO and accessibility.
<head> Document Head Stores non-visible metadata, character set configs, and window tab title definitions.
<title> Page Title Sets the text string displayed on the browser tab and search engine results (SERPs).
<body> Document Body Holds all visual content (headings, paragraphs, images, tables, forms) rendered on screen.
<h1> Primary Heading Represents the main, most important heading on a page. Should generally appear once per page.
<p> Paragraph Groups blocks of textual content with automatic top and bottom margins.

4. Understanding Heading Hierarchy (h1 to h6)

HTML provides six levels of headings, ranging from <h1> (most important) down to <h6> (least important). Headings are not merely for making text large or bold; they define the logical outline and SEO index structure of your document.

<!-- Correct Heading Hierarchy -->
<h1>Heading Level 1 (Main Topic)</h1>
<h2>Heading Level 2 (Major Sub-topic)</h2>
<h3>Heading Level 3 (Sub-section)</h3>
<h4>Heading Level 4 (Minor Detail)</h4>
<h5>Heading Level 5 (Deep Detail)</h5>
<h6>Heading Level 6 (Lowest Priority)</h6>
Hardcoded Output Result (Heading Scale)

Heading Level 1 (Main Topic)

Heading Level 2 (Major Sub-topic)

Heading Level 3 (Sub-section)

Heading Level 4 (Minor Detail)

Heading Level 5 (Deep Detail)
Heading Level 6 (Lowest Priority)
Golden Rule of Headings:

Never skip heading levels (e.g., jumping from an <h1> directly to an <h4>). Skipped levels break document outlines for screen reader users and confuse search engine indexing bots.

5. Validating Your HTML Code via W3C

Because modern browsers are designed to be extremely forgiving, they will try to render pages even if you forget to close tags or make syntax errors. However, bad markup leads to inconsistent rendering across different browsers and mobile devices.

To verify that your HTML code adheres strictly to web standards, professional developers use the official W3C Markup Validation Service (validator.w3.org).

How to Validate Your Page

  1. Navigate to validator.w3.org in your web browser.
  2. Select the Validate by File Upload or Validate by Direct Input tab.
  3. Paste your raw HTML code into the input field and click the Check button.
  4. Review the report: green indicates fully compliant HTML5, while red warnings point out missing tags or invalid attribute usages.

6. Homework Assignments & Practical Exercises

Task 1: Creating Your First Page (Current Lesson)

Open VS Code, create a folder named my-first-website, and inside it create an index.html file. Manually type out the complete HTML5 boilerplate structure (without using Emmet auto-complete). Set the page title to "My Coding Debut", add a main <h1> heading, and write two structured paragraphs about why you are learning HTML.

Task 2: Heading Hierarchy & Validation (Current Lesson)

Expand your index.html file by adding an <h2> sub-heading titled "My Top 3 Goals" followed by three separate <h3> headings detailing each individual goal. Copy your complete code, paste it into validator.w3.org, and ensure you achieve a 100% clean validation result with zero errors.

Task 3: Full Developer Workflow Revision (All-Inclusive Task)

Combine your knowledge from Lessons 01 through 04: Launch Live Server in VS Code to preview your index.html page. Right-click the heading in your browser, inspect it using Browser DevTools, edit the text live in the Elements panel, and write a brief note explaining why those DevTools changes disappear upon refreshing the browser tab.

7. Frequently Asked Interview Questions

Q1: Why is the default entry homepage file named index.html on web servers?

Answer: Web server software (such as Apache, Nginx, or IIS) is pre-configured to look for a designated index file (like index.html or index.php) when a client requests a directory path without specifying an explicit filename. Naming your main page index.html allows users to access your site directly via www.domain.com/.

Q2: Why is it important to specify the lang attribute on the <html> root tag?

Answer: The lang attribute (e.g., lang="en") informs screen readers which voice pronunciation rules to load for visually impaired users. It also helps search engines categorize the natural language of the page content for localized search queries and aids browser translation tools.

Q3: How many <h1> elements should typically exist on a single web page?

Answer: From an SEO and accessibility best practices perspective, a page should contain exactly one <h1> tag. The <h1> serves as the primary title of the entire document. Multiple <h1> tags dilute document focus and create ambiguity for search engine crawlers.

Q4: What happens if a developer omits the closing </p> tag on a paragraph?

Answer: Modern HTML5 parser specifications allow browsers to automatically infer paragraph closure when encountering another block element (like a new <p> or <h2>). However, relying on auto-closure can lead to unpredictable CSS styling bugs and invalid DOM nesting trees.

Lesson 05 Preview: HTML Document Structure

Now that you know how to build, save, and validate a basic HTML page, our next lesson takes a deep dive into advanced document structure:

  • Block vs. Inline Elements: Understanding how different elements behave in the normal page flow.
  • Grouping Content with Divs and Spans: Using structural containers effectively without creating "div soup".
  • HTML Document Tree Architecture: Understanding parent, child, and sibling relationships within the Document Object Model (DOM).
  • Semantic Content Segmentation: Structuring real-world multi-page web applications for optimal SEO and performance.

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
Address Contact

+91 7877547686

E-mail

onlinecbtportal@gmail.com

Helpline Number

+91 7877547686


Click To Download
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat