HTML <head> Tag

Beginner
6 min read
Updated: Oct 2026
4 examples
Live preview

Definition and Usage

The <head> element holds document metadata — information for browsers, search engines, and other tools. Typical children include <title>, <meta>, <link>, <style>, <script>, <base>, and <noscript>.

There is only one <head> per document, as the first child of <html>. Visible content belongs in <body>. Do not confuse <head> with <header>, which is a visible landmark inside the body.

Baseline · Widely available.

Core <head> support has been stable across browsers since about July 2015 (and much earlier in practice).

Deprecated · Obsolete attribute.

Do not use profile on <head>. It is obsolete — omit it and use <meta> / <link> instead.

HTML Syntax

syntax.html
<head> metadata…</head>

Start and end tags may be omitted in some cases, but beginners should always write both. A normal document needs exactly one <title> inside <head>.

Attributes

Besides globals, MDN still documents one legacy attribute. Do not use it in new work.

AttributeDescriptionTry it
profileDeprecated · Obsolete. Old metadata profile URIs — omit entirelyDo not use

Focus on children instead: title, meta (charset, viewport, description), and link for stylesheets and icons.

Global Attributes

The <head> tag also supports the Global Attributes in HTML.

Live Preview

Change the document title and see how a browser tab label would look. <head> itself is not painted on the page.

Simulated tab title from <title> inside <head>.

Browser chrome (demo)
My First Page

Visible <body> content would appear here.

<title>My First Page</title>

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Minimal Useful <head>

Charset, viewport, and title — the usual starter trio.

HTML
<!DOCTYPE html>
<html lang="en">
<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</h1>
</body>
</html>
Try It Yourself

How It Works

  1. Open <head> right after <html>.
  2. Set charset first so the rest of the document is decoded correctly.
  3. Add viewport so phones do not zoom the page oddly.
  4. Add one <title> for the tab and search snippet title.

Example 2 — Meta Description

A short summary for search and social previews (when platforms use it).

HTML
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>About CodeToFun</title>
  <meta name="description" content="Learn HTML tags with clear, beginner-friendly examples.">
</head>
Try It Yourself

How It Works

  1. Keep charset and viewport at the top of <head>.
  2. Write a clear <title> that matches the page topic.
  3. Add meta name="description" with one or two honest sentences.
  4. Learn more on the <meta> page.

Example 4 — <head> vs <header>

Metadata stays in <head>. Visible intro content uses <header> in the body.

HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Site Home</title>
</head>
<body>
  <header>
    <p>CodeToFun</p>
    <nav><a href="/">Home</a></nav>
  </header>
  <main><h1>Welcome</h1></main>
</body>
</html>
Try It Yourself

How It Works

  1. <head> sets the tab title and other metadata (invisible).
  2. <header> shows branding and nav inside <body>.
  3. Both can exist — they solve different jobs.
  4. Study <header> next on the header tutorial.

Edge Cases & Pitfalls

Most head mistakes are putting visible content there, or confusing it with header.

structure

Only one <head>

A document has a single head as the first child of <html>. Do not nest or duplicate it.

content

No visible UI in head

Paragraphs, headings, and layout markup belong in <body>. Head is for metadata and resources.

naming

head ≠ header

<header> is a visible landmark. <head> never replaces it.

charset

Charset early

Place <meta charset="UTF-8"> within the first 1024 bytes so encoding is detected correctly.

obsolete

Skip profile

The profile attribute on head is obsolete. Omit it completely.

Browser Support

The <head> element is core HTML in every browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

<head>

Widely available since about July 2015 (and long before). Chrome, Firefox, Safari, Edge, and Opera fully support the head metadata container.

98% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer All
Supported
<head> Widely supported

Bottom line: Safe everywhere. Always include a clear title, charset, and viewport in new pages.

Key Takeaways

  • Role: <head> holds metadata and resource links — not visible UI.
  • Starter trio: charset, viewport, and one <title>.
  • Naming: <head> ≠ <header>.
  • Skip profile: obsolete — omit it.

One line: put metadata in <head>, put what users see in <body>.

Default CSS Settings

<head> is not rendered as page content. Typical user-agent treatment:

default.css
head {
  display: none;
}

Do not try to style head for layout. Style elements inside body instead.

Frequently Asked Questions

The head element holds machine-readable metadata about the document — title, meta tags, stylesheets, scripts, and related resource links — before the visible body content.
Common children are title, meta, link, style, script, base, and noscript. Put visible content in body, not head.
Yes for normal HTML documents: include exactly one title inside head. It shows in the browser tab and often in search results.
head is invisible document metadata. header is a visible landmark inside body for introductory content such as a logo or navigation.
Set lang on the html element (for example html lang="en"). Do not put lang only on head.
No. profile on head is obsolete. Omit it. Use meta and link for modern metadata needs.

Next: header

Learn the visible landmark for logos, titles, and page intro content.

header tutorial →

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.

18 people found this page helpful