Learning Goals
- Create an index.html file in a project folder.
- Understand the boilerplate:
<!DOCTYPE html>
,<html lang>
,<head>
, meta,<title>
, and<body>
. - Add headings, paragraphs, comments, and separators.
- Open in the browser (and optionally with Live Server).
- Validate and fix common mistakes.
Part 1 — What index.html
Means
index.html is the default file name web servers and browsers look for inside a folder. If a folder is your site root, index.html becomes the homepage.
Tip: Keep your project folder tidy: one folder per lesson, with subfolders like
images/
, css/
, js/
when needed.Part 2 — Create the Project & File
- Create a folder named lesson-05.
- Inside it, create a file named index.html.
- Open it in your editor (VS Code). Optionally start Live Server.
Part 3 — Minimal Boilerplate
Paste this into lesson-05/index.html:
<!DOCTYPE html> <!-- standards mode -->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My First Page</title>
</head>
<body>
<h1>Hello, world!</h1>
<p>This is my very first HTML page.</p>
</body>
</html>
What each part does
<!DOCTYPE html>
— enables modern standards mode.<html lang="en">
— root element + document language.<meta charset="UTF-8">
— use Unicode (covers emojis & symbols).<meta name="viewport">
— responsive layout on mobile.<title>
— tab/bookmark label.<body>
— visible page content.
Live Preview (inline)
Part 4 — Add Real Content
Below your first paragraph, try these:
<h2>About Me</h2>
<p>I’m learning HTML. It’s fun!</p>
<!-- A horizontal rule as a divider -->
<hr>
<h2>Fun Facts</h2>
<p>I like coding.<br>I also like music.</p>
<!-- Comment: this note is for me only; it won't show on the page -->
Whitespace: Browsers collapse multiple spaces and newlines. Use paragraphs,
<br>
for line breaks (sparingly), and <hr>
for thematic breaks.Part 5 — Open, Save, Refresh
- Double-click index.html to open in your browser (or use Live Server).
- Edit in your editor, save (Ctrl/Cmd + S), then refresh the tab if not using Live Server.
- Right-click → View Page Source or use DevTools to inspect the DOM.
Part 6 — Validate & Fix Common Mistakes
- Run your file through the W3C Validator (File Upload).
- Close your tags properly (e.g.,
</p>
). - Include the DOCTYPE and charset meta.
- Use one <h1> and a logical heading order.
Practice Tasks
- Create sections for “About”, “Hobbies”, and “Goals” using headings and paragraphs.
- Add a comment describing what you’ll learn next.
- Insert a horizontal rule between sections.
- Validate, fix issues, and re-run the validator.
Quick Quiz
- Why is the file named index.html special?
- What does
<!DOCTYPE html>
do? - Where should
<meta charset="UTF-8">
go and why? - What’s the difference between
<br>
and starting a new<p>
?
Sample answers
- Servers/browsers look for it by default as the folder’s homepage.
- Enables standards mode (modern rendering rules).
- Inside
<head>
, so the parser knows the encoding early. <br>
forces a line break inside the same paragraph; a new<p>
is a separate block.
Lesson 5 Dictionary
- Boilerplate
- The minimal, standard structure of an HTML document you start from.
- <body>
- The container for all visible content of the page.
- charset (meta)
- Declares the document character encoding, e.g.,
<meta charset="UTF-8">
. - <!-- comment -->
- A note for authors that does not appear on the page.
- <!DOCTYPE html>
- Triggers standards mode so the browser uses modern rules.
- DevTools
- Built-in browser tools to inspect DOM and debug pages.
- <head>
- Container for document metadata (title, meta tags, links).
- Heading
- Section title elements (
<h1>…<h6>
) establishing outline. - <hr>
- A thematic break (horizontal rule) between content sections.
- <html>
- Root element that wraps the entire document.
- index.html
- The default file name browsers/servers load in a folder (homepage).
- lang (attribute)
- Specifies the language of the content (e.g.,
<html lang="en">
). - Live Server
- Editor extension that serves your page locally and auto-reloads on save.
- <meta>
- Metadata declarations (charset, viewport, etc.) inside
<head>
. - <p>
- A paragraph block for text content.
- Refresh
- Reload the page in the browser to see saved changes (if not using Live Server).
- Validator (W3C)
- A tool to check HTML for errors and best-practice conformance.
- Viewport (meta)
- Controls the layout viewport on mobile (e.g.,
width=device-width, initial-scale=1
).