The <head> and <body> sections organize your webpage. The head holds important info for the browser, and the body shows what users see.
Head and body sections in HTML
<!DOCTYPE html> <html lang="en"> <head> <!-- Metadata, title, links go here --> </head> <body> <!-- Visible content goes here --> </body> </html>
The <head> section is for information that helps the browser but is not shown directly on the page.
The <body> section contains everything the user sees and interacts with.
<head> <title>My Page</title> </head>
<head> <meta charset="UTF-8"> <link rel="stylesheet" href="styles.css"> </head>
<body> <h1>Welcome!</h1> <p>This is the main content.</p> </body>
This webpage has a head with metadata and a title, and a body with visible content including a heading and paragraph.
<!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>Hello, world!</h1> </header> <main> <p>This is a simple webpage with head and body sections.</p> </main> </body> </html>
Always include the <meta charset="UTF-8"> tag in the head to support all characters.
The <title> tag inside the head is important for SEO and user experience.
Content inside the body is what users see and interact with on the page.
The <head> section holds page info for the browser, not visible content.
The <body> section contains all the visible parts of the webpage.
Separating head and body helps organize your webpage clearly.
Practice
<head> section in an HTML document?Solution
Step 1: Understand the role of the <head> section
The <head> contains metadata like the page title, links to stylesheets, and scripts, which the browser uses but does not show directly.Step 2: Compare with <body> section
The <body> holds visible content like text and images, unlike the <head> which is for behind-the-scenes info.Final Answer:
To hold information for the browser like title and styles, not visible content -> Option AQuick Check:
<head> = browser info, not visible [OK]
- Thinking <head> shows content on the page
- Confusing <head> with <body>
- Believing <head> holds images or text visible to users
Solution
Step 1: Recall the correct order of HTML tags
The <html> tag wraps the whole document. Inside it, <head> comes first, then <body>.Step 2: Check each option's tag order
<html><head>...</head><body>...</body></html> correctly places <head> before <body> inside <html>. Others have wrong order or nesting.Final Answer:
<html><head>...</head><body>...</body></html> -> Option AQuick Check:
HTML structure = html > head > body [OK]
- Placing body before head
- Nesting html inside head or body
- Missing closing tags
<html>
<head>
<title>My Page</title>
</head>
<body>
<h1>Welcome!</h1>
</body>
</html>Solution
Step 1: Identify visible content in <body>
The <body> contains <h1>Welcome!</h1>, which is visible on the page.Step 2: Understand <title> role in <head>
The <title> sets the browser tab's title, not page content.Final Answer:
The text 'Welcome!' as a heading on the page -> Option BQuick Check:
Body content visible, title shown in tab [OK]
- Thinking title text appears on page
- Expecting both title and body text visible
- Ignoring difference between head and body
<html>
<head>
<title>Page</title>
<body>
<h1>Hello</h1>
</body>
</html>Solution
Step 1: Check tag closures in the snippet
The <head> tag is opened but not closed before <body> starts, which is invalid.Step 2: Confirm other tags
The <html> tag is properly closed, and <title> is correctly inside <head>.Final Answer:
Missing closing <head> tag before <body> -> Option DQuick Check:
Head must close before body starts [OK]
- Forgetting to close head tag
- Thinking title can be inside body
- Ignoring tag nesting rules
<style> tag and why?Solution
Step 1: Understand where styles belong
CSS styles are usually placed inside <style> tags within the <head> so the browser loads them before showing content.Step 2: Evaluate other options
Placing styles in <body> or outside tags is invalid or causes delayed styling, which is not best practice.Final Answer:
Inside the <head> section, so styles load before the page content -> Option CQuick Check:
Styles in head load early for proper display [OK]
- Placing style tags inside body
- Leaving style tags outside html structure
- Loading styles too late causing flicker
Ready to prove it?
Pass the test and this pattern moves unknown
