📖 Scenario: You want to create a simple webpage that shows a welcoming message. To do this, you need to set up the basic structure of an HTML document first.
🎯 Goal: Build a complete HTML document with the correct structure including <!DOCTYPE html>, <html>, <head>, and <body> tags.
📋 What You'll Learn
Use the HTML5 doctype declaration
Include the <html> root element with the lang attribute set to "en"
Add a <head> section with <meta charset="UTF-8"> and a <title> tag
Create a <body> section with a heading that says "Welcome to My Website"
💡 Why This Matters
🌍 Real World
Every webpage on the internet starts with a basic HTML document structure like this. It is the foundation for adding content and styling.
💼 Career
Knowing how to set up a correct HTML document is essential for any web developer or designer. It ensures your pages work well across browsers and devices.
Progress0 / 4 steps
1
Create the HTML5 doctype and root element
Write the HTML5 doctype declaration <!DOCTYPE html> at the top. Then create the root <html> element with the attribute lang="en".
HTML
Hint
The doctype declaration tells the browser this is an HTML5 document. The lang attribute helps with accessibility and search engines.
2
Add the head section with meta charset and title
Inside the <html> element, add a <head> section. Inside <head>, add a <meta charset="UTF-8"> tag and a <title> tag with the text "My First Page".
HTML
Hint
The <meta charset="UTF-8"> tag ensures your page can display most characters correctly.
3
Add the body section with a heading
After the <head> section, add a <body> section. Inside <body>, add an <h1> heading with the text "Welcome to My Website".
HTML
Hint
The <h1> tag is used for the main heading on your page.
4
Complete the HTML document structure
Make sure the <html> element properly wraps the <head> and <body> sections, and that all tags are correctly closed.
HTML
Hint
Double-check that every opening tag has a matching closing tag and the structure is correct.
Practice
(1/5)
1. Which tag defines the root of an HTML document?
easy
A. <body>
B. <head>
C. <title>
D. <html>
Solution
Step 1: Understand the role of the root tag
The root tag wraps the entire HTML content and tells the browser this is an HTML document.
Step 2: Identify the root tag
The <html> tag is the root element that contains all other tags like <head> and <body>.
Final Answer:
<html> -> Option D
Quick Check:
Root tag = <html> [OK]
Hint: Root tag is always <html> wrapping the whole page [OK]
Common Mistakes:
Confusing <head> as root instead of <html>
Thinking <body> is the root tag
Using <title> as root tag
2. Which of the following is the correct way to declare the document type for HTML5?
easy
A.
B.
C.
D.
Solution
Step 1: Recall the HTML5 doctype declaration
HTML5 uses a simple doctype declaration to tell browsers to use modern standards.
Step 2: Identify the correct syntax
The correct syntax is exactly <!DOCTYPE html> with uppercase DOCTYPE and lowercase html.
Final Answer:
<!DOCTYPE html> -> Option A
Quick Check:
HTML5 doctype = <!DOCTYPE html> [OK]
Hint: DOCTYPE is uppercase, html lowercase, no version number [OK]
Common Mistakes:
Writing DOCTYPE in lowercase
Adding version number like HTML5
Missing exclamation mark
3. What will the browser display when opening this HTML snippet?
<!DOCTYPE html>
<html>
<head>
<title>Test Page</title>
</head>
<body>
<h1>Hello</h1>
<p>Welcome to the page.</p>
</body>
</html>
medium
A. Only the title 'Test Page' is shown on the page
B. An empty page with no visible content
C. A page with a heading 'Hello' and a paragraph 'Welcome to the page.'
D. An error message because of missing tags
Solution
Step 1: Analyze the body content
The body contains an <h1> with 'Hello' and a <p> with 'Welcome to the page.'
Step 2: Understand browser rendering
Browsers display the content inside the <body> tag as visible page content. The <title> appears in the browser tab, not on the page.
Final Answer:
A page with a heading 'Hello' and a paragraph 'Welcome to the page.' -> Option C
Quick Check:
Body content visible = heading + paragraph [OK]
Hint: Page shows body content, title shows in tab only [OK]