Element.firstElementChild is a read-only instance property that returns the first child element, or null when none exist. Learn how it differs from firstChild, how it relates to children, and how to use it safely—with five examples and try-it labs.
01
Kind
Instance property
02
Access
Read-only
03
Type
Element or null
04
Skips
Text & comments
05
Status
Baseline widely
06
Same as
children[0]
Fundamentals
Introduction
When you need the first nested tag inside a parent—not a text node from whitespace— firstElementChild is the direct read.
It is ideal for grabbing the first list item, table row, or card section without filtering childNodes yourself.
JavaScript
const list = document.getElementById("list");
console.log(list.firstElementChild.textContent);
💡
Beginner tip
Need the very first node including text? Use firstChild. Need only the first tag? Use firstElementChild.
Concept
Understanding the Property
MDN: the read-only firstElementChild property returns the element’s first child element, or null if there is no such child.
Read-only — re-read after DOM changes to get the current first element.
Element or null — never returns text or comment nodes.
Element-only view — same first item as children[0] when present.
Baseline — widely available since July 2015 (MDN).
Foundation
📝 Syntax
JavaScript
firstElementChild
Value
An Element reference for the first child element, or null when the parent has no element children. Always check for null before reading properties like textContent.
Pretty-printed HTML often puts a text node first. Prefer firstElementChild when you need the first tag, not whitespace.
Example 3 — null When No Element Children
A parent with only text (or no children) returns null.
JavaScript
const empty = document.getElementById("empty");
console.log(empty.firstElementChild); // null
console.log(empty.firstChild !== null); // may still have a text node
firstElementChild is a convenience read. When no elements exist, children[0] is undefined while firstElementChild is null.
Example 5 — Support Snapshot
Feature-detect and remember the null-check tip.
JavaScript
console.log({
supported: "firstElementChild" in Element.prototype,
returns: "Element or null",
tip: "Check for null before reading properties",
status: "Baseline Widely available (MDN)"
});
Element.firstElementChild is Baseline Widely available (MDN: across browsers since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline Widely available
Element.firstElementChild
Read-only — returns the first child Element or null (skips text/comment nodes).
BaselineWidely available
Google ChromeSupported
Yes
Microsoft EdgeSupported
Yes
Mozilla FirefoxSupported
Yes
Apple SafariSupported
Yes
OperaSupported
Yes
Internet ExplorerSupported (IE 9+)
Yes
firstElementChildBaseline
Bottom line: Use firstElementChild to read the first nested tag. Prefer it over firstChild when whitespace text nodes would get in the way. Always check for null on empty containers.
Wrap Up
Conclusion
firstElementChild is the element-only shortcut to the first nested tag. It skips text and comments, returns null when no elements exist, and matches children[0] when they do.
Use it when you need every node type—use firstChild
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about firstElementChild
Read-only Element or null—first tag child only.
5
Core concepts
📄01
Get only
on Element
Kind
📝02
Element|null
not text
Type
🔍03
First tag
lists & rows
Use
✅04
Baseline
widely available
Status
🎯05
Null check
empty parents
Tip
❓ Frequently Asked Questions
It returns the first child element of the element, or null if there is no element child. Text and comment nodes are skipped.
No. MDN marks Element.firstElementChild as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
An Element reference, or null when the parent has no element children (including when it only has text or comment nodes).
firstChild returns the first node of any type (element, text, comment). firstElementChild returns only the first Element child, skipping text and comments.
When element children exist, yes — firstElementChild equals children[0]. When there are no element children, firstElementChild is null and children[0] is undefined.
It comes from the ParentNode mixin, so Document and DocumentFragment also expose firstElementChild.
Did you know?
Like children, firstElementChild comes from the ParentNode mixin—so Document and DocumentFragment expose it too.