Every HTML page has a <head> section that users never see directly—yet it shapes the browser tab title, mobile scaling, styling, scripts, and how search engines summarize your site.
Understanding the head is one of the first skills every web developer needs. This tutorial walks through structure, essential meta tags, linked resources, SEO basics, and six hands-on examples you can edit live.
What You’ll Learn
01
head
Metadata.
02
title
Tab text.
03
meta
Charset SEO.
04
link
CSS fonts.
05
style
Inline CSS.
06
SEO
Social tags.
Fundamentals
What Is the HTML <head> Element?
The <head> element is a container for document metadata. It sits inside <html>, before <body>, and holds information about the page rather than visible content.
Browsers use head data to set the tab title, apply CSS, run JavaScript, and scale the page on mobile. Search engines and social platforms read meta tags to build snippets and link previews.
💡
Invisible but essential
Nothing inside head renders as page content. When you click View Output in the examples below, you see the body content that the head influences—styled text, layout, and notes about the tab title.
See the head tag reference for the full attribute list and browser notes.
Foundation
Basic Structure of the <head> Element
Every HTML5 document follows this skeleton. The head comes first; the body holds everything users see:
Meta tags provide name-value pairs that describe your page to browsers, search engines, and social platforms.
Essential meta tags
charset — ensures correct text rendering. Learn more in the HTML Charset tutorial.
viewport — required for responsive mobile layouts.
description — a concise summary (roughly 150–160 characters) often shown in search results. Write a unique description per page.
html
<meta name="description" content="Learn the HTML head element: title, charset, viewport, CSS, and SEO meta tags.">
<meta name="author" content="Your Name">
Meta keywords—limited value today
You may still see <meta name="keywords"> in older tutorials. Major search engines largely ignore it now because it was spammed. Focus your effort on a clear title and description instead.
html
<!-- Low SEO value today — prefer description instead -->
<meta name="keywords" content="html, head, tutorial">
Resources
Including External Resources
The head is where you connect stylesheets, fonts, and scripts to your page.
CSS Stylesheets
Link external CSS with rel="stylesheet". Styles in head apply to the entire document:
html
<link rel="stylesheet" href="styles.css">
You can also embed CSS inline with a <style> block—useful for small pages or critical above-the-fold styles.
Fonts
Load web fonts from services like Google Fonts using link with rel="preconnect" for faster DNS/TLS, then the font stylesheet:
External scripts belong in head with defer so HTML parsing is not blocked and scripts run in order after the document is ready:
html
<script src="app.js" defer></script>
Use async instead when the script is independent and order does not matter (analytics snippets, for example).
Discoverability
SEO and the <head> Element
Search engines and social networks read head metadata to understand and promote your page:
Unique title — include the page topic and site name; avoid duplicate titles across pages.
meta description — write a human-readable summary; it may appear as the snippet below your link in results.
link rel="canonical" — tells search engines the preferred URL when duplicate content exists.
Open Graph (og:) — controls title, description, and image when shared on Facebook, LinkedIn, and similar platforms.
Twitter Card tags — customize previews on X (Twitter).
html
<title>HTML Head Tutorial | CodeToFun</title>
<meta name="description" content="Learn metadata, charset, viewport, and linked resources in the HTML head.">
<link rel="canonical" href="https://example.com/html/head">
<meta property="og:title" content="HTML Head Tutorial">
<meta property="og:description" content="Metadata and SEO for beginners.">
<meta property="og:type" content="website">
<meta name="twitter:card" content="summary_large_image">
Caution
Common Pitfalls
Missing viewport meta — pages look zoomed out and tiny on mobile without width=device-width.
Duplicate or empty titles — every page needs a unique, descriptive title.
Blocking scripts in head — scripts without defer or async delay page rendering.
Visible content in head — headings, paragraphs, and images belong in body, not head.
Relying on meta keywords — invest in title and description instead; keywords alone won’t rank your page.
Charset too late — place meta charset within the first few lines of head.
Cheat Sheet
⚡ Quick Reference
Element / Attribute
Purpose
<title>
Browser tab and bookmark title
meta charset
Character encoding (UTF-8)
meta viewport
Mobile responsive scaling
meta description
Search snippet summary
link rel="stylesheet"
External CSS file
<style>
Inline CSS in the document
script defer
Non-blocking JS after parse
og:* / twitter:*
Social sharing previews
Hands-On
Examples Gallery
Six examples from a minimal head to a complete metadata setup. Head content is invisible—each View Output shows the body affected by the head (tab title note, styling, and layout).
📤 Body renders as (head sets tab title “My First Page”):
🔖 Browser tab title from <title>: My First Page
Hello, world!
Check the browser tab — the title comes from the head.
How It Works
Charset, viewport, and title are the three tags every new page should start with. The visible heading lives in body; the tab text comes from title in head.
Example 2 — Meta Description and Author
html
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="A beginner-friendly guide to the HTML head element.">
<meta name="author" content="Alex Developer">
<title>HTML Head Tutorial</title>
</head>
The style block in head styles this page without an external file.
How It Works
A <style> element embeds CSS directly in the document. Good for small demos; large sites usually use external stylesheets.
Example 5 — Open Graph and Twitter Meta
html
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Learn the HTML head element step by step.">
<title>HTML Head — Social Preview</title>
<meta property="og:title" content="HTML Head Tutorial">
<meta property="og:description" content="Learn metadata, SEO, and linked resources.">
<meta property="og:type" content="website">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="HTML Head Tutorial">
</head>
📤 Body styled by head CSS (script.js loads with defer):
🔖 Tab title: HTML Head Example | ⚡ script.js uses defer
HTML Head Example
The head holds metadata and linked resources. This visible content lives in body.
How It Works
Combines every technique from this tutorial: encoding, mobile viewport, SEO meta, external and internal CSS, and non-blocking JavaScript with defer.
Pro Tips
Best Practices
✅ Do
Put meta charset and viewport first in head
Write a unique title and meta description per page
Use link rel="stylesheet" for main CSS files
Add defer to non-critical scripts in head
Include Open Graph tags for pages you expect to be shared
❌ Don’t
Put visible headings or paragraphs inside head
Rely on meta keywords for SEO ranking
Load blocking scripts without defer or async
Reuse the same title on every page
Skip the viewport meta on responsive sites
Compatibility
Universal Browser Support
<head>, <title>, <meta>, <link>, and <style> work in every browser. meta viewport, defer, and Open Graph tags are supported in all modern browsers. Always test mobile scaling on real devices.
✓ Baseline · Since HTML
HTML head + viewport + defer
<head>, <title>, <meta>, <link>, and <style> work in every browser. meta viewport, defer, and Open Graph tags are supported in all modern browsers. Always test mobile scaling on real devices.
98%Modern browser support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
HTML head + viewport + deferModern browsers
Bottom line: Core head elements are universal; viewport and deferred scripts cover virtually all users today.
Wrap Up
Conclusion
The HTML head is the control center for every page. Charset and viewport keep text readable and mobile-friendly; title and description shape how users and search engines discover your content; linked CSS and scripts power the experience users see in the body.
The head element holds metadata about the document—title, charset, viewport, SEO meta tags, linked CSS, and scripts. Nothing in head is visible on the page itself; browsers and search engines read it to configure how the page behaves and appears elsewhere.
Put document metadata and linked resources in head: title, meta, link, style, and script tags. Put all visible content in body: headings, paragraphs, images, links, and interactive UI. Never put h1 or p tags inside head.
It tells the browser which character encoding to use when reading the file. UTF-8 is the standard. Place meta charset early in head so text renders correctly before other resources load.
Major search engines largely ignore meta keywords today because they were abused. Focus on a unique title, a clear meta description, semantic HTML, and quality content instead.
It tells mobile browsers how to scale the page width. width=device-width, initial-scale=1.0 prevents tiny unreadable text on phones and is required for responsive layouts.
You can, but use defer on external scripts so HTML parsing is not blocked. defer runs scripts after the document is parsed, in order. For critical scripts that must run immediately, place them at the end of body or use async when order does not matter.
Did you know?
The <title> in head is reused in many places beyond the browser tab: bookmark names, browser history entries, and the default text search engines show for your page. A clear, unique title helps users find your site again.