Master Code
On The Go

Learn. Practice. Build.

How-To Guide

How to Run Your First HTML File

Create, save, and open an HTML file in your browser in under 5 minutes. No server, no setup, no frameworks — just plain HTML.

🎯 What You'll Build

By the end of this guide, you'll have a working HTML page that looks like this in your browser:

file:///index.html

Hello, World!

This is my first web page.

📋 What You'll Need

✅ No installation required. No Python, no Node.js, no terminal. HTML runs natively in every browser.

1

Create a New File

Open VS Code. Create a new file with Ctrl+N (Windows/Linux) or Cmd+N (Mac).

Save it immediately with Ctrl+S or Cmd+S. Name it:

index.html

⚠️ Important: The file must end in .html — not .txt or .htm.txt. If you're on Windows and can't see file extensions, turn on "File name extensions" in File Explorer first.

2

Write Your First HTML Code

Paste this into your index.html file:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>My First Page</title>
</head>
<body>
    <h1>Hello, World!</h1>
    <p>This is my first web page.</p>
</body>
</html>

Here's what each line does:

  • <!DOCTYPE html> — tells the browser this is HTML5
  • <html> — wraps the entire page
  • <head> — invisible metadata (title, encoding)
  • <body> — everything visible on the page
  • <h1> — a big heading
  • <p> — a paragraph
3

Save the File

Press Ctrl+S (Windows/Linux) or Cmd+S (Mac).

If VS Code shows a dot next to the filename, it means unsaved changes exist. Make sure it's saved before continuing.

💡 Enable Auto Save: In VS Code, go to File → Auto Save. From now on, every change saves automatically. You'll never lose work again.

4

Open It in Your Browser

There are two easy ways:

Method A: Double-click the file

  1. Open your file manager (Explorer on Windows, Finder on Mac)
  2. Find index.html
  3. Double-click it
  4. It opens in your default browser 🎉

Method B: Drag into the browser

  1. Open Chrome, Firefox, Safari, or Edge
  2. Drag index.html from your folder into the browser window
  3. It renders instantly

You should see a big "Hello, World!" heading and a paragraph below it.

💡 Why does the URL say file:///...? That means the browser is reading a file directly from your computer, not from a web server. It works perfectly for local development.

5

Use Live Server for Auto-Reload (Recommended)

Without Live Server, you have to refresh the browser manually every time you change the file. With Live Server, the page reloads automatically.

Install Live Server:

  1. In VS Code, click the Extensions icon on the left sidebar (or press Ctrl+Shift+X)
  2. Search for Live Server
  3. Click Install on the one by Ritwick Dey (the most popular one, 30M+ downloads)

Use it:

  1. Right-click anywhere inside your index.html file
  2. Click Open with Live Server
  3. Your browser opens with the page at http://127.0.0.1:5500/index.html
  4. ;
  5. Now edit your HTML and save — the browser auto-refreshes

💡 Why this matters: Live Server simulates a real web server environment, so features like JavaScript modules, fetch API, and form submission work correctly — things that don't always work with the file:// protocol.

✅ Verify It Works

Your page is working correctly if you see:

If you see raw code instead of a rendered page, the file was probably saved with the wrong extension. Rename it to index.html and try again.

🔧 Common Issues (and Fixes)

❌ The file saves as index.html.txt

Windows hides file extensions by default. Turn them on:

  1. Open File Explorer → View menu → Show → File name extensions ✅
  2. Then rename your file to remove the .txt

❌ The browser shows the HTML as plain text

This means the file extension isn't .html. Right-click the file → Rename → make sure it ends with .html.

❌ Nothing happens when I double-click the file

Your default app for .html files might be VS Code or a text editor. Right-click → Open With → choose Chrome/Firefox/Edge.

To fix it permanently, right-click the file → Properties → Open with: Change → select your browser → "Always use this app."

❌ Live Server doesn't appear in the right-click menu

Make sure you're right-clicking inside the file content area, not in the sidebar. Or use the "Go Live" button at the bottom-right of VS Code.

❌ Port 5500 is already in use

Another instance of Live Server is running. Close other VS Code windows or check localhost:5500 in your browser.

🎯 What's Next?

You just wrote and ran your first HTML file. Time to learn HTML properly.

← All How-To Guides