Clean HTML structure helps your webpage work well and be easy to understand. It makes your site look good on all devices and helps people and search engines read your content.
Clean HTML structure
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Page Title</title> </head> <body> <header></header> <nav></nav> <main></main> <footer></footer> </body> </html>
Use <!DOCTYPE html> at the top to tell browsers this is an HTML5 page.
Use semantic tags like <header>, <nav>, <main>, and <footer> to organize content clearly.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Simple Page</title> </head> <body> <header> <h1>Welcome</h1> </header> <main> <p>This is a clean HTML page.</p> </main> <footer> <p>Ā© 2024</p> </footer> </body> </html>
<nav> tag for easy site navigation.<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Page with Navigation</title> </head> <body> <header> <h1>Site Title</h1> </header> <nav> <ul> <li><a href="#home">Home</a></li> <li><a href="#about">About</a></li> </ul> </nav> <main> <section> <h2>About Us</h2> <p>Information about the site.</p> </section> </main> <footer> <p>Contact info here.</p> </footer> </body> </html>
This full example shows a clean HTML page with header, navigation, main content divided into sections, and a footer. It uses semantic tags and includes a viewport meta tag for mobile friendliness.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Clean HTML Example</title> </head> <body> <header> <h1>My Website</h1> </header> <nav> <ul> <li><a href="#home">Home</a></li> <li><a href="#services">Services</a></li> <li><a href="#contact">Contact</a></li> </ul> </nav> <main> <section id="home"> <h2>Welcome</h2> <p>This is a clean and simple HTML page structure.</p> </section> <section id="services"> <h2>Services</h2> <p>We offer web design and development.</p> </section> <section id="contact"> <h2>Contact Us</h2> <p>Email: info@example.com</p> </section> </main> <footer> <p>Ā© 2024 My Website</p> </footer> </body> </html>
Always include lang attribute in <html> for accessibility and SEO.
Use <meta name="viewport"> to make your page look good on phones and tablets.
Keep your code neat with indentation to make it easy to read and fix later.
Clean HTML uses semantic tags to organize content clearly.
Include important meta tags for character set and responsive design.
Good structure helps users, search engines, and devices understand your page.
Practice
Solution
Step 1: Understand semantic tags purpose
The <main> tag is designed to hold the main content of a page, making it clear and meaningful.Step 2: Compare with other tags
Whileand <section> can group content, <main> specifically indicates the primary content, improving clarity for users and search engines.Final Answer:
<main> -> Option DQuick Check:
Semantic main content = <main> [OK]
- Using <div> instead of semantic <main>
- Confusing <section> with main content
- Using <span> which is inline, not structural
Solution
Step 1: Check correct charset attribute value
The standard and correct value for UTF-8 encoding is 'UTF-8' with a hyphen and uppercase letters.Step 2: Validate syntax correctness
The meta tag must be written as exactly for browsers to recognize it properly.Final Answer:
<meta charset='UTF-8'> -> Option AQuick Check:
Correct charset syntax = <meta charset='UTF-8'> [OK]
- Writing 'utf8' without hyphen
- Using lowercase or missing hyphen
- Incorrect attribute name or missing quotes
<!DOCTYPE html> <html lang='en'> <head> <meta charset='UTF-8'> <title>Test</title> </head> <body> <header><h1>Welcome</h1></header> <main><p>Hello World</p></main> <footer><p>Footer text</p></footer> </body> </html>
Solution
Step 1: Identify semantic tags and their content
The header contains an h1 with 'Welcome', main has a paragraph 'Hello World', and footer has 'Footer text'.Step 2: Understand browser rendering of semantic tags
All these tags are valid and will display their content in order on the page.Final Answer:
Page with header 'Welcome', paragraph 'Hello World', and footer 'Footer text' -> Option AQuick Check:
Semantic tags show all content correctly [OK]
- Assuming main content is hidden
- Thinking body tag is missing
- Ignoring footer content display
<html> <head> <title>Page</title> <meta name='viewport' content='width=device-width, initial-scale=1.0'> </head> <body> <h1>Hello</h2> <section>Content here</section> </body> </html>
Solution
Step 1: Check tag matching in body content
The opening tag is <h1> but the closing tag is </h2>, which is incorrect and breaks HTML structure.Step 2: Verify other tags and meta placement
The viewport meta tag is correctly placed in head, and section is valid inside body. Missing charset is not a structural error.Final Answer:
Mismatched closing tag: </h2> instead of </h1> -> Option CQuick Check:
Matching tags must open and close the same [OK]
- Ignoring mismatched tags
- Thinking meta tags cause structure errors
- Believing section can't be inside body
Solution
Step 1: Identify required meta tags for clean structure
Using <meta charset='UTF-8'> and viewport meta ensures correct character encoding and responsive design.Step 2: Use semantic tags and language attribute
Including <html lang='en'> and semantic tags like <header>, <main>, <footer> improves accessibility and clarity.Final Answer:
<!DOCTYPE html>, <html lang='en'>, <meta charset='UTF-8'>, <meta name='viewport' content='width=device-width, initial-scale=1.0'>, semantic tags like <header>, <main>, <footer> -> Option BQuick Check:
Best practice = doctype + lang + charset + viewport + semantic tags [OK]
- Omitting doctype or lang attribute
- Using non-semantic tags for all content
- Missing viewport meta for responsiveness
Ready to prove it?
Pass the test and this pattern moves unknown
