In the previous chapter, Introduction to HTML, we learnt what HTML is and how a browser turns it into a page. Now it's time to actually build one. By the end of this chapter you will have written a real HTML file, opened it in your browser, changed it, and inspected it with the browser's developer tools.
The good news: you need no installation, no compiler and no internet connection. A text editor and a browser are enough.
What You Need
| Tool | Purpose | Examples |
|---|---|---|
| Text / code editor | To write the HTML file | Visual Studio Code (recommended, free), Notepad, Notepad++, Sublime Text |
| Web browser | To open and display the file | Chrome, Edge, Firefox, Safari |
Why a code editor and not Microsoft Word? Word processors save extra formatting data and often replace straight quotes " with curly "smart" quotes “ ”. Browsers do not treat curly quotes as attribute quotes, so your code silently breaks. A code editor saves plain text only, and gives you colour highlighting, auto-closing tags and error hints.
Step 1: Create a Project Folder
Keep every project in its own folder. Create a folder anywhere, for example:
D:\web-practice\my-first-page\
Open VS Code, choose File → Open Folder… and select this folder. Now every file you create will live inside it.
Step 2: Create the File index.html
Create a new file and name it exactly:
index.html
Two things matter here:
- The extension must be
.html(.htmalso works, but.htmlis the modern convention). The extension tells your operating system and the browser that the file contains HTML. - Why "index"? When a web server is asked for a folder (like
https://example.com/) instead of a specific file, most servers are configured to sendindex.htmlfrom that folder by default. Using this name from day one is a good habit.
Windows tip: By default, Windows Explorer hides file extensions. If you create a file in Notepad and name it index.html, it may actually be saved as index.html.txt. Turn on extensions in File Explorer (View → Show → File name extensions on Windows 11) so you can see the real name.
Step 3: Write the HTML
Type (don't just copy-paste — typing helps you remember) the following code into index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My First Web Page</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is my first web page. I wrote it in a plain text editor.</p>
<p>Today I learned that HTML describes the structure of a page.</p>
</body>
</html>
Save the file with Ctrl + S (Cmd + S on Mac).
VS Code shortcut: the "!" boilerplate
VS Code has a built-in tool called Emmet. In an empty .html file, type a single exclamation mark ! and press Tab (or Enter on the suggestion). VS Code expands it into a complete starter document similar to the one above, with <title>Document</title> — just change the title. Use this shortcut once you understand what each line does; while learning, typing it yourself is better.
Step 4: Open It in the Browser
There are several ways to open the file:
- Double-click
index.htmlin File Explorer (it opens in your default browser). - Drag the file and drop it onto an open browser window.
- Press Ctrl + O in the browser and choose the file.
You will see something like this:
Browser tab: My First Web Page
Hello, World! ← big, bold heading
This is my first web page. I wrote it in a plain text editor.
Today I learned that HTML describes the structure of a page.
Now look at the address bar. It shows something like:
file:///D:/web-practice/my-first-page/index.html
The file:// at the start means the browser is reading the file directly from your disk, not from a web server on the internet. That is perfectly fine for learning HTML and CSS. (A few advanced JavaScript features behave differently on file://, which is why developers later use a small local server — more on that below.)
Understanding What You Wrote (Quick Tour)
The next chapter, HTML Document Structure, explains every line in depth. For now, here is a quick map:
| Line | What it does |
|---|---|
<!DOCTYPE html> | Tells the browser to use modern standards mode. |
<html lang="en"> | The root element that wraps everything; lang says the page is in English. |
<head> … </head> | Information about the page (not shown in the page area). |
<meta charset="utf-8"> | Says the text is encoded in UTF-8, so all characters (₹, é, हिंदी) show correctly. |
<meta name="viewport" …> | Makes the page display properly on mobile screens. |
<title> | Text shown on the browser tab and in bookmarks/search results. |
<body> … </body> | Everything visible on the page. |
<h1> | The main heading. |
<p> | A paragraph. |
Step 5: Edit → Save → Refresh
This is the basic workflow of web development. Let's change something:
<h1>Hello, CS Learning Portal!</h1>
- Edit the code in the editor.
- Save the file (Ctrl + S).
- Go to the browser and refresh (F5 or Ctrl + R).
The heading changes. If it doesn't, you probably forgot to save — this is the number one beginner mistake. (VS Code shows a filled dot on the tab of an unsaved file.)
Optional: Auto-refresh with a local server
Pressing refresh every time gets boring. A popular VS Code extension called Live Server starts a small local web server and reloads the browser automatically whenever you save. After installing it, right-click index.html and choose Open with Live Server. The address changes to something like http://127.0.0.1:5500/index.html — now your page is served over HTTP, just like a real website. This is optional for HTML chapters.
Step 6: Look Behind the Page
Every browser lets you see the HTML behind any web page. These two tools will be your best friends.
View Page Source (Ctrl + U)
Right-click the page and choose View page source, or press Ctrl + U. You see the exact text the browser received — your file, character for character. Try this on any website to learn how others write HTML.
Developer Tools → Elements (F12)
Press F12 (or Ctrl + Shift + I, or right-click → Inspect). The Elements panel (called Inspector in Firefox) shows the DOM tree — the browser's live, parsed version of your page. You can expand and collapse elements, hover to highlight them on the page, and even double-click text to edit it temporarily.
| View Page Source | DevTools Elements panel |
|---|---|
| Shows the raw HTML text as downloaded | Shows the DOM tree the browser built |
| Never changes | Updates live if JavaScript changes the page |
| Shows your mistakes as you typed them | Shows the browser's repaired version of your mistakes |
That last row is a powerful learning trick. Try deleting </p> from the first paragraph and refresh. The page still looks the same, and the Elements panel shows a properly closed paragraph — the browser fixed it for you. View Source, however, still shows your missing tag.
Note: edits made in DevTools are temporary. They vanish when you refresh. The real changes must be made in your file.
Worked Example: A Small "About Me" Page
Let's practise the full workflow once more. Replace the body with this:
<body>
<h1>Rahul Sharma</h1>
<p>B.Tech CSE, 2nd year.</p>
<p>I like solving DSA problems and building small websites.</p>
<p>My goal this semester: build and publish my own portfolio.</p>
</body>
Save and refresh. Output:
Rahul Sharma
B.Tech CSE, 2nd year.
I like solving DSA problems and building small websites.
My goal this semester: build and publish my own portfolio.
Notice that each <p> starts on a new line with a gap above and below — that is the browser's default paragraph spacing. You didn't need to press Enter twice or add blank lines; in fact, as we will see in Headings & Paragraphs, extra blank lines in your source code are ignored.
Other Ways to Practise
- Online editors such as CodePen, JSFiddle or StackBlitz let you write HTML in the browser and see the result instantly — handy on a lab computer where you can't install anything.
- Mobile: you can practise on a phone with an online editor, but a laptop with VS Code is far more comfortable.
Common Mistakes
| Mistake | Symptom | Fix |
|---|---|---|
File saved as index.html.txt | Browser shows your code as plain text, tags and all | Show file extensions and rename the file to index.html |
| Forgot to save before refreshing | Changes don't appear | Ctrl + S, then refresh (or enable Auto Save in VS Code) |
| Wrote code in MS Word | Strange characters, broken attributes due to curly quotes | Use a plain text / code editor |
| Editing the page inside DevTools | Changes disappear on refresh | Make the change in the file itself |
Missing <meta charset="utf-8"> | Characters like ₹ or Hindi text may appear as garbage symbols | Always include it near the top of <head> |
| Opening the file in the editor and expecting a preview | You only see code | Open the file in a browser |
Interview / Practical Exam Questions
1. What software is required to create and view a web page?
Only a plain text editor to write the HTML file and a web browser to open it. No compiler or interpreter needs to be installed.
2. Why is the home page file usually named index.html?
Web servers are commonly configured to serve index.html automatically when a URL points to a folder rather than a specific file. Naming the main page index.html lets users visit example.com/ instead of example.com/home.html.
3. What is the difference between "View Page Source" and "Inspect Element"?
View Source shows the raw HTML text received from the server. Inspect (DevTools Elements panel) shows the live DOM tree the browser built — after error correction and after any changes made by JavaScript.
4. What does file:// in the address bar mean?
It means the browser loaded the file directly from the local file system, not over HTTP from a web server.
5. Is there any difference between .htm and .html?
No functional difference — both are treated as HTML. .htm comes from old systems that allowed only three-character extensions. .html is the modern convention.
Summary
- You need only a code editor and a browser to create a web page.
- Save HTML files with the
.htmlextension; name the main pageindex.html. - The workflow is edit → save → refresh; Live Server can automate the refresh.
- A
file://address means the page is opened from your disk. - View Source shows the raw text; DevTools Elements shows the DOM the browser built.
- VS Code's Emmet
!+ Tab generates a starter document.
Next, in HTML Document Structure, we will go through the starter document line by line and understand exactly why each part is there.