Differences between Document and Window Objects (original) (raw)

Last Updated : 23 Jul, 2025

In this article, we will see the Document object & Window object, their various properties & methods, along with knowing their implementation & the differences between them.

**Document Object:

The document object represents a web page that is loaded in the browser. By accessing the document object, we can access the element in the HTML page. With the help of document objects, we can add dynamic content to our web page. The document object can be accessed with a **window.document or just document.

**Syntax:

document.property_name;

The properties of document objects that are commonly used are listed in the below table:

**Properties of document:

**Methods of Document

**Syntax:

document.method_name;

The lists of most commonly used methods are listed below:

**Example: This example describes the implementation of the document.object.

HTML `

document's Properties

GeeksforGeeks

CLICK ME

<script>
    function myFunction() {
        let title = document.title;
        let domain = document.domain;
        let body = document.body;
        document.getElementById("demo").innerHTML =
            "the title of the document is : "
            + title
            + "<br>"
            + "domain : "
            + domain
            + "<br>"
            + "body : "
            + body;
    }
</script>

`

**Output:

**Window Object

The window object is the topmost object of the DOM hierarchy. It represents a browser window or frame that displays the contents of the webpage. Whenever a window appears on the screen to display the contents of the document, the window object is created.

**Syntax:

window.property_name;

The properties of Window objects that are commonly used are listed in the below table:

**Properties of the window:

**Methods of Window:

**Syntax:

window.method_name;

The methods of Window objects that are commonly used are listed in the below table:

**Example: This example describes the implementation of the window.object.

HTML `

Window's Properties

GeeksforGeeks

Check

<script>
    function show() {
        let h = window.innerHeight;
        let w = window.innerWidth;
        let l = window.location;
        let c = window.closed;
        document.getElementById("prop").innerHTML =
            "Frame's Height: "
            + h + "<br>"
            + "Frame's Width: "
            + w + "<br>"
            + "Window location:"
            + l
            + "<br>"
            + "Window Closed: "
            + c;
    }
</script>

`

**Output:

**Difference between document and window:

**document **window
It represents any HTML document or web page that is loaded in the browser. It represents a browser window or frame that displays the contents of the webpage.
It is loaded inside the window. It is the very first object that is loaded in the browser.
It is the object of window property. It is the object of the browser.
All the tags, elements with attributes in HTML are part of the document. Global objects, functions, and variables of JavaScript are members of the window object.
We can access the document from a window using the window. document We can access the window from the window only. i.e. window.window
The document is part of BOM (browser object model) and dom (Document object model) The window is part of BOM, not DOM.
Properties of document objects such as title, body, cookies, etc can also be accessed by a window like this window. document.title Properties of the window object cannot be accessed by the document object.
syntax: document.propertyname; syntax: window.propertyname;
example: document.title : will return the title of the document example: window.innerHeight : will return the height of the content area of the browser