HTML Head

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 6 Examples + 6 Try It
head / meta / title

Introduction

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.

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.

Basic Structure of the <head> Element

Every HTML5 document follows this skeleton. The head comes first; the body holds everything users see:

html
<!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>
  <!-- Visible content goes here -->
</body>
</html>
  • charset — declare UTF-8 encoding as early as possible.
  • viewport — enable proper mobile scaling.
  • title — sets the browser tab, bookmark, and default search result title.
  • body — separate from head; holds headings, text, images, and UI.

Common <head> Elements

These tags appear in almost every professional HTML page:

  • <title> — required for valid HTML; one per document.
  • <meta> — charset, viewport, description, author, robots, Open Graph, and more.
  • <link> — connect external CSS, favicons, and web fonts.
  • <style> — embed CSS rules directly in the document.
  • <script> — load or define JavaScript; use defer for non-blocking external scripts.
  • <base> — optional; sets a default URL for relative links (use sparingly).
html
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="Short summary for search engines.">
  <title>My Website</title>
  <link rel="stylesheet" href="styles.css">
  <link rel="icon" href="favicon.ico">
  <script src="app.js" defer></script>
</head>

Importance of Meta Tags

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">

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:

html
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap">

JavaScript

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).

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">

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.

⚡ Quick Reference

Element / AttributePurpose
<title>Browser tab and bookmark title
meta charsetCharacter encoding (UTF-8)
meta viewportMobile responsive scaling
meta descriptionSearch snippet summary
link rel="stylesheet"External CSS file
<style>Inline CSS in the document
script deferNon-blocking JS after parse
og:* / twitter:*Social sharing previews

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).

Example 1 — Minimal Head

html
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My First Page</title>
</head>
<body>
  <h1>Hello, world!</h1>
</body>
Open in Tab

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>
Open in Tab

How It Works

meta description does not appear on the page itself. Search engines may show it under your link in results. Author is optional metadata.

Example 3 — Linked Stylesheet

html
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Styled Page</title>
  <link rel="stylesheet" href="styles.css">
</head>
Try It Yourself

How It Works

link rel="stylesheet" fetches an external CSS file. Rules in that file style every matching element in body.

Example 4 — Internal Style Block

html
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Internal CSS</title>
  <style>
    body { font-family: Georgia, serif; max-width: 560px; margin: 2rem auto; }
    h1 { color: #7c3aed; border-bottom: 2px solid #ddd6fe; }
  </style>
</head>
Try It Yourself

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>
Open in Tab

How It Works

Open Graph and Twitter Card meta tags control link previews on social platforms. They never appear as visible page content.

Example 6 — Complete Head Example

Well-structured head with charset, viewport, SEO meta, CSS, and a deferred script:

html
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="A simple webpage with a well-structured head section.">
  <meta name="author" content="Your Name">
  <title>HTML Head Example</title>
  <link rel="stylesheet" href="styles.css">
  <style>
    body { font-family: system-ui, sans-serif; padding: 2rem; max-width: 640px; }
    h1 { color: #1e40af; }
    .note { background: #eff6ff; border-left: 4px solid #3b82f6; padding: 12px 16px; }
  </style>
  <script src="script.js" defer></script>
</head>
Try It Yourself

How It Works

Combines every technique from this tutorial: encoding, mobile viewport, SEO meta, external and internal CSS, and non-blocking JavaScript with defer.

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

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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
HTML head + viewport + defer Modern browsers

Bottom line: Core head elements are universal; viewport and deferred scripts cover virtually all users today.

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.

Next, pick a tool to write HTML with HTML Editors, or dive into HTML Charset and the head tag reference.

Key Takeaways

🔤 02

charset

UTF-8 first.

Encoding
📱 03

viewport

Mobile scale.

Responsive
🔍 04

description

SEO snippet.

Not keywords
05

defer

Safe scripts.

Performance

❓ Frequently Asked Questions

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.

Build a page head in the editor

Add charset, viewport, title, meta description, CSS, and deferred scripts, then preview live.

Open Try It editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful