The root element containing head and body. Learn more →
<head> ElementThe <head> element contains machine-readable information (metadata) about the document, including its title, scripts, style sheets, and other meta information. Content inside <head> is not displayed on the page but tells browsers and search engines important details about your document.
<head> <!-- Metadata elements go here --></head>The <head> element has no element-specific attributes.
This element supports all global attributes, though they’re rarely used on <head>.
Every HTML document should have these core elements in the <head>:
For better search engine optimization, include descriptive metadata:
Add Open Graph and Twitter Card metadata for better social sharing:
Include stylesheets, fonts, and icons:
Include JavaScript files with proper loading strategies:
The <head> element can contain these elements:
<title> - Required, defines document title (exactly one)<meta> - Defines metadata<link> - Links to external resources<style> - Contains CSS styles<script> - Contains or references JavaScript<base> - Specifies base URL for relative URLs<noscript> - Alternative content when scripts are disabledWhile not strictly enforced, follow this recommended order for better performance:
<meta charset>)<meta name="viewport">)<title>)<style>)<meta> tags)<link rel="stylesheet">)<script>)<head> <!-- 1. Character encoding first --> <meta charset="UTF-8">
<!-- 2. Viewport --> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 3. Title --> <title>Page Title</title>
<!-- 4. Resource hints --> <link rel="preconnect" href="https://fonts.googleapis.com">
<!-- 5. Critical CSS --> <style>/* critical styles */</style>
<!-- 6. Preload critical resources --> <link rel="preload" href="hero.jpg" as="image">
<!-- 7. Other metadata --> <meta name="description" content="...">
<!-- 8. Stylesheets --> <link rel="stylesheet" href="styles.css">
<!-- 9. Scripts --> <script defer src="app.js"></script></head>Keep the <head> section lean. Every byte in the <head> delays page rendering:
Always include a viewport meta tag for responsive design:
<meta name="viewport" content="width=device-width, initial-scale=1.0">The <title> element is announced by screen readers and appears in browser tabs. Make it descriptive and unique:
<!-- Good: Specific and descriptive --><title>Shopping Cart - 3 items | MyStore</title>
<!-- Avoid: Too generic --><title>Page</title>Proper character encoding and language declaration help assistive technologies:
<head> <meta charset="UTF-8"> <!-- Language set on <html> element --></head>| Browser | Version |
|---|---|
| Chrome | All versions |
| Firefox | All versions |
| Safari | All versions |
| Edge | All versions |
| IE | All versions |
The root element containing head and body. Learn more →
Contains the visible content of the document. Learn more →
Defines the document title shown in browser tabs. Learn more →
Defines metadata about the HTML document. Learn more →
<!-- Wrong: Missing title --><head> <meta charset="UTF-8"></head>
<!-- Correct: Include title --><head> <meta charset="UTF-8"> <title>My Page</title></head><!-- Wrong: Visible content belongs in body --><head> <title>My Page</title> <h1>Welcome</h1></head>
<!-- Correct: Only metadata in head --><head> <title>My Page</title></head><body> <h1>Welcome</h1></body>