Your First HTML Program
Your First HTML Program
Let's create your first HTML page from scratch. You will create an
index.html file, write a simple page, open it in a browser,
and understand exactly what each line does.
Create a file called index.html, add a heading and paragraph, save it, and open it in your browser.
That's it â you have created your first real web page.
.html extension. The browser reads your HTML and renders the page.1ī¸âŖ Create your HTML file
Open your project folder
Open the folder where you want to keep your HTML files in VS Code.
Create a new file
Create a new file and name it index.html.
Write your HTML
Type the basic HTML structure and add your first heading and paragraph.
Save and open it
Save the file and open index.html in a web browser.
2ī¸âŖ Write your first HTML program
<h1> or <p>, then click Run to see your changes.3ī¸âŖ Understand it line by line
Line 1: Declares the document as an HTML document and enables standards-based rendering.
Line 2: Starts the root HTML element. The lang attribute identifies English as the document's primary language.
Line 3: Starts the head section, which contains information about the document and its resources.
Line 4: Sets the character encoding to UTF-8.
Line 5: Sets the document title, normally shown in the browser tab.
Line 6: Closes the head section.
Line 7: Starts the body, where the page's visible content is placed.
Line 8: Creates the main heading displayed on the page.
Line 9: Creates a paragraph of text.
Line 10: Closes the body section.
Line 11: Closes the root HTML element.
4ī¸âŖ What will you see?
Hello, World!
This is my first HTML program.
5ī¸âŖ Try changing the page
<h1>Change the heading
Replace Hello, World! with your own heading.
<p>Change the paragraph
Write a sentence that describes yourself or your project.
<title>Change the tab title
Replace the title with the name of your website.
6ī¸âŖ Add more HTML elements
7ī¸âŖ Common beginner mistakes
Make sure the filename ends with .html, for example index.html.
HTML tags must be written correctly. For example, use <h1>, not <h01>.
Elements such as <h1> and <p> normally need matching closing tags.
Save your changes before checking the page again in the browser.
đ¯ Your first challenge
Create an HTML page containing:
- A page title
- Your name as an
<h1> - A short introduction using
<p> - An
<h2>called "My Skills" - A list of at least three skills
- A link to a website you like
đ¤ Interview questions
What is the purpose of <!DOCTYPE html>?
It declares that the document is an HTML document and helps the browser use standards mode.
What is the difference between <head> and <body>?
The head contains document information and resources; the body contains the content displayed on the page.
What does the <h1> element do?
It represents a level-one heading and is commonly used for the main heading of a page or section.
What does the <p> element do?
It represents a paragraph of text.
What happens when an HTML file is opened in a browser?
The browser parses the HTML and renders the document according to its elements and structure.
⥠Quick Summary
- Create an HTML file using the
.htmlextension. - Start with
<!DOCTYPE html>. - Use
<html>as the root element. - Put page information inside
<head>. - Put visible content inside
<body>. - Use
<h1>for a main heading and<p>for a paragraph. - Save the file and open it in a browser to see the result.