First HTML Program: Hello World Tutorial

Create your first HTML page from scratch. Step-by-step guide to writing and running your first HTML program.

Introduction

Let's create your first HTML page! We'll build a simple "Hello World" web page step by step.

What You Will Learn

  • Creating an HTML file
  • Basic HTML structure
  • Adding text and headings
  • Running your HTML page in a browser
  • Understanding the basic tags

Prerequisites

  • A text editor (VS Code recommended)
  • A web browser (Chrome, Firefox, etc.)

Step 1: Create a Project Folder

Create a new folder called html-practice anywhere on your computer.

Step 2: Create Your First HTML File

  1. Open VS Code
  2. File → Open Folder → Select html-practice
  3. Click "New File" icon
  4. Name it index.html

Step 3: Write Your First HTML Code

Type this into index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My First HTML Page</title>
</head>
<body>
    <h1>Hello World!</h1>
    <p>This is my first HTML page. I'm learning HTML!</p>
</body>
</html>

Step 4: Understand the Code

Let's break it down:

<!DOCTYPE html>

  • Tells the browser this is an HTML5 document
  • Always put this first line

<html lang="en">

  • Root element of the page
  • lang="en" tells search engines the page is in English

<head>

  • Contains meta information about the page
  • Not visible on the page itself

<meta charset="UTF-8">

  • Sets the character encoding to UTF-8
  • Ensures all characters display correctly

<meta name="viewport" ...>

  • Helps with responsive design on mobile devices

<title>

  • Sets the page title shown in browser tab

<body>

  • Contains all visible content of the page
  • What users see and interact with

<h1>

  • Level 1 heading - largest and most important

<p>

  • Paragraph of text

Step 5: Save the File

  • Press Ctrl+S (Windows/Linux) or Cmd+S (Mac)
  • Make sure it's saved as index.html

Step 6: Open in Browser

Option 1: Direct Open

  1. Find index.html in file explorer
  2. Double-click it
  3. It opens in your default browser

Option 2: Live Server (Recommended)

  1. Install "Live Server" extension in VS Code
  2. Right-click index.html
  3. Select "Open with Live Server"
  4. Page opens and auto-reloads when you edit!

Step 7: Make It Better!

Let's add more content. Update your HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My First HTML Page</title>
</head>
<body>
    <header>
        <h1>Welcome to My First Website!</h1>
    </header>
    
    <main>
        <section>
            <h2>About Me</h2>
            <p>Hi! I'm learning HTML and this is my first web page.</p>
        </section>
        
        <section>
            <h2>My Hobbies</h2>
            <ul>
                <li>Reading</li>
                <li>Coding</li>
                <li>Gaming</li>
                <li>Hiking</li>
            </ul>
        </section>
    </main>
    
    <footer>
        <p>&copy; 2024 My First Website. All rights reserved.</p>
    </footer>
</body>
</html>

Step 8: Save and Refresh

  1. Save the file (Ctrl+S)
  2. Refresh your browser (F5 or Ctrl+R)
  3. See your updated page!

Let's Experiment!

Try these changes:

  1. Add another heading:
<h3>My Favorite Foods</h3>
  1. Add a longer paragraph:
<p>I love learning web development. HTML is fun and easy!</p>
  1. Add an ordered list:
<ol>
    <li>Learn HTML</li>
    <li>Learn CSS</li>
    <li>Learn JavaScript</li>
</ol>

What's Next?

Congratulations! You just created your first web page! šŸŽ‰

Now you're ready to learn:

  • More about HTML structure
  • Text elements
  • Links and images
  • Lists and tables
  • And much more!

Common Mistakes to Avoid

āŒ Forgetting closing tags āŒ Mixing up tag names āŒ Not saving the file āŒ Wrong file extension (.txt instead of .html)

Best Practices

āœ… Use proper indentation āœ… Use semantic elements āœ… Always save with .html extension āœ… Test in multiple browsers āœ… Keep code organized

FAQs

Q: What is index.html? A: It's the default filename for the home page of a website.

Q: Can I use Notepad instead of VS Code? A: Yes, but VS Code is much better for development.

Q: Do I need an internet connection? A: No, you can create and view HTML files locally.

Q: Why isn't my page updating? A: Make sure you saved the file and refresh the browser.

Related Topics

  • What is HTML
  • Installing VS Code
  • Browser Developer Tools

Summary

You created your first HTML page! You learned the basic structure, added content, and viewed it in a browser. Keep practicing!

Next Topic

Now let's learn Understanding HTML Structure in more detail.