Document.children is a read-only instance property (from the ParentNode mixin) that returns a live HTMLCollection of the document’s direct element children. Learn MDN’s usual [<html>] result, how to access items, how it differs from childNodes, and when to use Element.children instead—with five examples and try-it labs.
01
Kind
Read-only
02
Returns
HTMLCollection
03
Contains
Elements only
04
Typical
[<html>]
05
Live
Updates with DOM
06
Status
Baseline widely
Fundamentals
Introduction
The Document node sits at the top of the DOM. Its direct children can include a doctype, comments, and element nodes. document.children filters that list down to element children only.
MDN notes that for HTML documents this collection usually contains just the root <html> element—the document’s only direct element child. That is why document.children.length and document.childElementCount are both typically 1.
💡
Document vs Element
To list items inside a <ul>, <div>, or <body>, use Element.children. This page covers the same property on Document itself.
A read-only instance property from the ParentNode interface, exposed on Document. Its value is a live, ordered HTMLCollection of direct child Element nodes.
Value — HTMLCollection (live).
Access — document.children[i] or document.children.item(i).
Elements only — excludes doctype, comments, and text nodes.
Direct children — does not include descendants inside <html>.
Empty case — if there are no element children, length is 0.
Foundation
📝 Syntax
JavaScript
document.children
Value
An HTMLCollection of the document’s direct element children. On a typical HTML page this is usually just the root <html> element.
MDN example
JavaScript
document.children;
// HTMLCollection [<html>]
// Usually only contains the root <html> element
Compare
⚖️ Document child APIs compared
API
What it returns
Typical HTML page
document.children
Live HTMLCollection of element children
[<html>]
document.childElementCount
Number of those element children
1
document.childNodes
NodeList of all child node types
Often doctype + html
document.documentElement
The root html element
Usually same as children[0]
document.body.children
Element children of body
Varies by page content
Cheat Sheet
⚡ Quick Reference
Goal
Code / note
Get element children
document.children
Count them
document.children.length or childElementCount
First element child
document.children[0] or document.documentElement
item() access
document.children.item(0)
Children of body
document.body.children
MDN status
Baseline Widely available
Snapshot
🔍 At a Glance
Four facts about document.children.
Type
HTMLCollection
Live list
Scope
direct only
Not descendants
Typical
[<html>]
One root
Status
baseline
ParentNode
Compare
📋 children vs childNodes
document.children
document.childNodes
Node types
Elements only
Elements, text, comments, doctype, etc.
Collection type
HTMLCollection
NodeList
On Document
Usually one html
Often doctype + html
Use when
You want element children only
You need every child node type
Hands-On
Examples Gallery
Examples follow MDN Document: children. Use View Output or Try It Yourself for each case.
📚 Getting Started
Inspect the document-level element children collection.
Example 1 — MDN: Inspect document.children
Log the collection and the first child’s tag name.
Prefer children when you only care about element children at the document root.
Example 5 — Document vs body.children
Document children are almost always just html; body children reflect page structure.
JavaScript
console.log("document:", document.children.length);
console.log("body:", document.body.children.length);
for (const el of document.body.children) {
console.log(el.tagName.toLowerCase());
}
Document.children is marked Baseline Widely available on MDN (since October 2017). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
Document.children
Live HTMLCollection of direct element children on Document — typically just the html root.
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.childrenExcellent
Bottom line: Use document.children for document-root element children. For lists and containers inside the page, use Element.children on the specific parent node.
Wrap Up
Conclusion
Document.children gives you a live list of element nodes directly under the document—almost always just <html> on standard pages. Use it to understand document-root structure; use Element.children for everyday container listing.
Use document.documentElement when you only need the html root
Use element.children for container/list children
Prefer children over filtering childNodes manually
Check length before indexing if the document may be unusual
Teach beginners the document vs element distinction clearly
❌ Don’t
Expect a large collection from document.children on normal pages
Confuse document children with every element in the page tree
List menu items via document.children
Assume doctype is included in the collection
Try to assign a new array to document.children
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about document.children
Live element-child collection — usually just the html root.
5
Core concepts
📄01
Returns
HTMLCollection
API
✓02
Status
baseline
Standard
🏠03
Typical
[<html>]
MDN
🔍04
vs
childNodes
Compare
📦05
Containers
Element.children
Use case
❓ Frequently Asked Questions
A live HTMLCollection of the document's direct child elements only. On a typical HTML page it usually contains just the root html element.
No. MDN marks Document.children as Baseline Widely available (since October 2017). It comes from the ParentNode mixin on Document.
Same property name and behavior, different node: document.children lists the document's direct element children; element.children lists an element's direct element children. Use Element.children for lists, cards, and containers inside the page.
children includes only Element nodes. childNodes includes every node type — elements, text, comments, and often the doctype on Document.
On a normal HTML page, children[0] is usually the same node as document.documentElement (the html element). documentElement is the convenient shortcut to that root.
No. It is read-only. You can read length and items, but you change the collection by adding or removing direct element children of the document (rare in normal apps).
Did you know?
children is a live collection: if the document’s direct element children change, the same HTMLCollection object updates automatically. You do not need to re-query document.children to see the new length.