The HTML document structure is the basic skeleton of every webpage. It helps browsers understand and display your content correctly.
HTML document structure
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Your Page Title</title> </head> <body> <!-- Your visible content goes here --> </body> </html>
The <!DOCTYPE html> tells the browser this is an HTML5 document.
The <html> tag wraps all the content and sets the language.
<!DOCTYPE html> <html lang="en"> <head> <title>Simple Page</title> </head> <body> <p>Hello, world!</p> </body> </html>
<!DOCTYPE html> <html lang="fr"> <head> <meta charset="UTF-8"> <title>Page en Français</title> </head> <body> <h1>Bonjour!</h1> </body> </html>
This example shows a complete HTML document with semantic sections: header, main, and footer. It includes metadata for character set and responsive design.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My First Webpage</title> </head> <body> <header> <h1>Welcome to My Website</h1> </header> <main> <p>This is a simple page to show the HTML document structure.</p> </main> <footer> <p>© 2024 My Website</p> </footer> </body> </html>
Always include lang attribute in <html> for accessibility and SEO.
Use <meta charset="UTF-8"> to support most characters and symbols.
The <meta name="viewport"> tag helps your page look good on phones and tablets.
The HTML document structure is the foundation of every webpage.
It includes <!DOCTYPE html>, <html>, <head>, and <body> tags.
Proper structure helps browsers display your page correctly and improves accessibility.
Practice
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 DQuick Check:
Root tag = <html> [OK]
- Confusing <head> as root instead of <html>
- Thinking <body> is the root tag
- Using <title> as root tag
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 AQuick Check:
HTML5 doctype = <!DOCTYPE html> [OK]
- Writing DOCTYPE in lowercase
- Adding version number like HTML5
- Missing exclamation mark
<!DOCTYPE html> <html> <head> <title>Test Page</title> </head> <body> <h1>Hello</h1> <p>Welcome to the page.</p> </body> </html>
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 CQuick Check:
Body content visible = heading + paragraph [OK]
- Thinking <title> shows on the page
- Expecting error from correct tags
- Ignoring body content
<!DOCTYPE html> <html> <head> <title>Page</title> <body> <h1>Welcome</h1> </body> </html>
Solution
Step 1: Check tag nesting
The <head> tag is opened but never closed before <body> starts, which breaks structure.Step 2: Confirm correct closing tags
Proper HTML requires closing <head> before starting <body>. Missing </head> causes parsing issues.Final Answer:
Missing closing <head> tag before <body> -> Option BQuick Check:
Head must close before body starts [OK]
- Forgetting to close <head>
- Placing <title> outside <head>
- Misplacing DOCTYPE
Solution
Step 1: Check for required tags and order
Valid HTML5 requires <!DOCTYPE html>, <html> with lang attribute, <head> with meta charset and title, and <body> with semantic sections.Step 2: Verify semantic tags and placement
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>My Page</title> </head> <body> <header>Site Header</header> <main>Main content here</main> <footer>Site Footer</footer> </body> </html>
correctly places <header>, <main>, and <footer> inside <body> and includes meta charset and lang attribute.Final Answer:
The complete valid HTML5 structure with lang, meta charset, title, header, main, footer -> Option AQuick Check:
Valid HTML5 = DOCTYPE + lang + meta + semantic tags [OK]
- Placing <header> inside <head>
- Missing lang or meta charset
- Incorrect order of semantic tags
Ready to prove it?
Pass the test and this pattern moves unknown
