Document.head is a read-only instance property that returns the <head> element as an HTMLHeadElement. Learn MDN’s id / querySelector example, how to append meta and link tags, how it differs from document.body, and five examples with try-it labs.
01
Kind
Read-only
02
Returns
HTMLHeadElement
03
HTML
<head>
04
vs
document.body
05
Common
meta / link
06
Status
Baseline widely
Fundamentals
Introduction
Every HTML page has a <head> section for metadata: <title>, <meta>, stylesheets, and scripts. In JavaScript, that node is document.head.
MDN: the read-only property returns the <head> element of the current document as an HTMLHeadElement. It is the standard shortcut instead of always calling document.querySelector("head").
💡
Head vs body
Use document.head for page metadata and resources loaded from the head. Use document.body for visible content the user sees on the page.
Libraries and SPAs often inject link or script tags this way instead of editing static HTML.
Example 4 — Read the Page Title from Head
Access the <title> inside document.head.
JavaScript
const titleEl = document.head.querySelector("title");
console.log(titleEl ? titleEl.textContent : "(no title)");
// You can also use document.title for the same string
console.log(document.title);
Document.head is marked Baseline Widely available on MDN (since June 2018). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
Document.head
Read-only reference to the HTML head element — standard for metadata, styles, and scripts.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported in legacy IE
Full support
Document.headExcellent
Bottom line: Use document.head to access and update head contents. Prefer appendChild for meta, link, and script tags instead of replacing the entire head.
Wrap Up
Conclusion
Document.head is the standard handle for the <head> element. Use it to read metadata, append meta/link/script tags, and inspect head resources—while remembering the property itself is read-only.
Use document.head instead of repeated querySelector("head")
Append meta, link, and script tags when loading resources dynamically
Check for existing tags before duplicating meta or link entries
Pair with document.body for full page structure
Use document.title for quick title reads/writes
❌ Don’t
Assign to document.head — it is read-only (MDN)
Put visible page content in the head
Append duplicate viewport or charset meta tags blindly
Confuse head with document.documentElement (the <html> root)
Replace the entire head unless you fully control the document
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about document.head
Your shortcut to the document’s metadata section.
5
Core concepts
📄01
Returns
HTMLHeadElement
API
📝02
HTML
<head>
Metadata
🔒03
Read-only
ref only
MDN
➕04
Append
meta / link
Contents OK
⚖️05
vs
body
Head vs content
❓ Frequently Asked Questions
The HTMLHeadElement of the current document — the DOM node for the <head> element (MDN).
No. MDN marks Document.head as Baseline Widely available (since June 2018). It is a standard, widely used DOM property.
No. MDN notes the property is read-only. Assigning fails silently in non-strict mode, or throws a TypeError in strict mode.
For normal HTML documents, yes — MDN's example shows document.head === document.querySelector('head') is true.
document.head is the <head> section (metadata, title, styles, scripts). document.body is the visible page content container.
When you need to add or read meta tags, link stylesheets, inject scripts, or update the document title from JavaScript.
Did you know?
Browsers create a <head> element even if your HTML omits it. That means document.head is almost always available on HTML documents, though you should still write explicit head markup for charset, viewport, and title.