document.rootElement returns the document’s root Element when that root is an SVG <svg> element; otherwise it returns null (MDN). Learn it for legacy SVG code — new work should use document.documentElement.
Read the notes below before you get or set this property. Prefer feature detection when support is limited.
Syntax
Use document.rootElement. Start with this line.
JavaScript
document.rootElement
Call
What it does
document.rootElement
Primary signature.
Built into the browser. Read or assign document.rootElement — no import required.
Library declarations
JavaScript
document.rootElement
Parameters
Parameter
Description
Writable?
Optional. Read-only
Replacement
Required. document.documentElement
Return Value
Return Value
Description
*
SVG root Element, or null
JavaScript Examples
Example 1 — Read rootElement
On an HTML page, MDN-style behavior is null.
JavaScript
console.log(document.rootElement);
// null on HTML; SVGSVGElement on SVG documents
Read documentElement — one API for every document type (MDN).
Use tagName (or other Element APIs) on the root.
Keep legacy reads only when maintaining old SVG code.
Compatibility
Browser Support
Document.rootElement is a legacy SVG Document extension. MDN marks it Deprecated. Engines may still expose it; new code should use document.documentElement.
✓ Deprecated · Legacy
Document.rootElement
SVG root Element or null. Prefer documentElement for all documents.
LegacyDeprecated
Google ChromeLegacy support
Yes*
Microsoft EdgeLegacy support
Yes*
Mozilla FirefoxLegacy support
Yes*
Apple SafariLegacy support
Yes*
OperaLegacy support
Yes*
Internet ExplorerLegacy
Yes*
rootElementLegacy
Bottom line: Still present in many browsers for compatibility, but deprecated. See the MDN rootElement reference.
Frequently Asked Questions
MDN: for SVG documents, the Element that is the document root (often an SVGSVGElement); otherwise null. It is deprecated in favor of document.documentElement.
Yes. MDN marks Document.rootElement as Deprecated. Prefer document.documentElement, which returns the root element for all document types.
MDN scopes rootElement to SVG roots. On a typical HTML document it returns null. Use document.documentElement for the <html> element.
MDN: for a non-empty SVG document, rootElement is an SVGSVGElement identical to documentElement.
Always use document.documentElement. It is the standard property for the document’s root Element.
No. It is read-only. New code should read document.documentElement instead.