HTML & CSSEasy
What is <head> vs <body>?
<head> contains information about the document that is mostly not displayed: metadata, the title, links to stylesheets and icons, scripts and SEO or social tags. <body> contains all the content users see and interact with: text, images, links, forms and media. Every HTML document has exactly one of each inside <html>.
<head> contents
<meta charset>,<meta name="viewport">,<meta name="description">.<title>(required).<link rel="stylesheet">,<link rel="icon">,<link rel="preload">,<link rel="preconnect">,<link rel="canonical">,<link rel="manifest">.<style>for critical inline CSS.<script>(preferably withdeferortype="module").<base>(rare), Open Graph and structured data (<script type="application/ld+json">).
<body> contents
- Landmarks and content:
<header>,<nav>,<main>,<footer>, headings, text, images, forms. - Scripts at the end of the body (an older pattern from before
defer).
Performance details
- Stylesheets in
<head>are render-blocking, so the page does not flash unstyled. - Classic scripts without
defer/asyncblock HTML parsing; place them carefully. - Preload critical resources (hero image, fonts) with
<link rel="preload">or usefetchpriority="high"on the image.
Parser behavior
If you omit <head> or <body> tags, the browser inserts them automatically. Elements that cannot be in the head (like a <div>) implicitly close it and start the body.
Frameworks
React 19 lets components render <title>, <meta> and <link> anywhere and hoists them into <head>.
Code example
html
1<!doctype html>2<html lang="en">3 <head>4 <!-- Not displayed: information about the page -->5 <meta charset="utf-8">6 <meta name="viewport" content="width=device-width, initial-scale=1">7 <title>Head vs body</title>8 <link rel="preconnect" href="https://picsum.photos">9 <style>10 body { font-family: system-ui; }11 .note { background: #fef9c3; padding: 8px; }12 </style>13 <script type="module">14 // Module scripts are deferred automatically15 document.querySelector(".note").textContent += " (script ran after parsing)";16 </script>17 </head>18 <body>19 <!-- Displayed: what users see -->20 <h1>Visible content lives in body</h1>21 <p class="note">The title above appears only in the browser tab</p>22 <img src="https://picsum.photos/200/80" alt="Example image" width="200" height="80">23 </body>24</html>
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the HTML & CSS set.