Differences between Document and Window Objects Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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: activeElement: It returns the currently active elements in the document.body: It returns the contents of the body element.anchors: It returns all <a> elements that have a name attribute.baseURI: It returns a string value that represents the base URI of the document.cookie: It returns the cookie of the current document.charSet: It returns a string, representing the document’s character encoding.defaultView: It returns the current Window Object.designMode: It is used to set documents as editable or read-only.domain: It returns the domain name of the document server.doctype: It returns the document's doctype.embeds: It returns the collection of all embedded elements.URL: It returns the complete URL of the document.forms: It returns all the elements of the form.fullScreenElement: It returns the element that is currently present in full-screen mode.title: It returns the title element of the document.head: It returns the head element of the document.links: It returns all <area> and <a> elements that have a href attribute.lastModified: It returns the date and time of the current document that was last modified.images: It returns the collection of <img> elements in the document.implementation: It returns the DOMImplementation object associated with the current document.readyState: It returns the loading status of the current document.referrer: It returns the URI of the page that is linked to the current page.scripts: It returns all script elements present in the document.strictErrorChecking: It sets or returns whether strict error checking can be enforced on a document or not.Methods of DocumentSyntax: document.method_name;The lists of most commonly used methods are listed below: addEventListener(): It is used to attach an event handler to the specified element.adoptNode(): It is used to adopt a node from another document and it returns a node object, representing the adopted node.close(): It is used to close the output stream.createAttribute(): It is used to create an attribute node with the specified name and returns the attribute object.createComment(): It is used to create a comment node with some text.createDocumentFragment(): It is used to create the document fragment to change the content of the document.createElement(): It is used to create HTML element .createEvent(): It is used to create a new events object.createTextNode(): It is used to create a textnode.execCommand(): It is used to execute a command specified by the user on the editable selected section. It returns a Boolean value.fullscreenEnabled(): It is used to check whether the document can be viewed in fullscreen mode or not. It returns a boolean value.getElementById(): It returns the object of the given ID. If no object with that id exists then it returns null.getElementsByClassName(): It returns an object containing all the elements with the specified class names in the document as objects.getElementsByName(): It returns an object containing all the elements with the specified name in the document as objects.getElementsByTagName(): It returns an object containing all the elements with the specified tag names in the document as objects.hasFocus(): It returns a boolean value that indicates whether the document or element has focus or not.importNode(): It imports the copy of a node from another document in the current document.normalize(): It flushes out the empty nodes and merges the adjacent text nodes with the first text node andnormalizeDocument(): It is used to normalize an HTML document by removing any empty text nodes and joining the adjacent text nodes.open(): It is used to open the output stream to collect the output.querySelector(): It returns the first element that matches a specified CSS selector(s) in the document.querySelectorAll(): It returns a collection of an element's child elements that matches a specified CSS selector(s) in the documentremoveEventListener(): It removes the event handler from an element that has an attached event.renameNode(): It is used to rename the node.write(): It is used to write some content or javascript code in the document.writeln(): It is used to write a document with a newline character after each statement.Example: This example describes the implementation of the document.object. HTML <!DOCTYPE html> <html> <head> <title>document's Properties</title> <style> h1 { color: green; } </style> </head> <body> <h1> GeeksforGeeks</h1> <button onclick="myFunction()">CLICK ME</button> <p id="demo"></p> <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> </body> </html> 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: Closed: It holds a Boolean value that represents whether the window is closed or not.console: It returns a reference to the console object which provides access to the browser’s debugging console.defaultStatus: It is used to define the default message that will be displayed in the status bar when no activity is carried on by the browser.controllers: It returns the XUL controller objects for the current Chrome window.customElements: It returns a reference to the CustomElementRegistry object, which can be used to register new custom elements and also get information about already registered custom elements.crypto: It returns the browser crypto object.devicePixelRatio: It returns the ratio between physical pixels and device-independent pixels in the current display.Document: It returns a reference to the document object of that window.DOMMatrix: It returns a reference to a DOMMatrix object, which represents 4×4 matrices, suitable for 2D and 3D operations.frames[]: It represents an array that contains all the frames of a given window.DOMPoint: It returns a reference to a DOMPoint object, which represents a 2D or 3D point in a coordinate system.History: It provides information on the URLs visited in the current window.Length: It represents the number of frames in the current window.DOMRect: It returns a reference to a DOMRect object, which represents a rectangle.fullScreen: This property indicates whether the window is displayed on full screen or not.Location: It contains the URL of the current window.innerHeight: It is used to get the height of the content area of the browser window.innerWidth: It is used to get the width of the content area of the browser window.Name: It contains the name of the referenced window.Window: It returns the current window or frame.Navigator: It returns a reference to the navigator object.outerHeight: It will get the height of the outside of the browser window.outerWidth: It will get the width of the outside of the browser window.Status: It overrides the default status and places a message in the status bar.Top: It returns a reference to the topmost window containing a frame if many windows are opened.Toolbar: It will result in the toolbar object, whose visibility can be toggled in the window.Opener: It contains a reference to the window that opened the current window.Parent: It refers to the frameset in which the current frame is contained.Screen: It refers to the screen objectSelf: It provides another way to refer to the current window.Methods of Window: Syntax: window.method_name;The methods of Window objects that are commonly used are listed in the below table: alert(): It is used to display an alert box. It displays a specified message along with an OK button and is generally used to make sure that the information comes through the user.atob(): It is used for decoding a base-64 encoded string. It is used to decode a string of data that has been encoded using the btoa() method.blur(): It is used to remove focus from the current window.btoa(): It is used for encoding a string in base-64 format.clearInterval(): It clears the interval which has been set by the setInterval() function before that.clearTimeout(): It clears the timeout which has been set by the setTimeout()function before that.close(): It is used for closing a certain window or tab of the browser which was previously opened.confirm(): It is used to display a modal dialog with an optional message and two buttons i.e. OK and Cancel. It returns true if the user clicks “OK”, and false otherwise.focus(): It is used to give focus to an element in the current window.getComputedStyle(): It is used to get all the computed CSS properties and values of the specified element.getSelection(): It returns a Selection object representing the range of text selected by the usermatchMedia(): It is used to return a MediaQueryList object which represents the result of the specified CSS media query string.open(): It is used to open a new tab or window with the specified URL and name.moveBy(): It is used for moving a window with a specified number of pixels relative to its current coordinates.moveTo(): It is used in the window to move the window from the left and top coordinates.prompt(): It is used to display a dialog with an optional message prompting the user to input some textresizeBy(): It is used to resize a window by the specified amount.resizeTo(): It is used to resize a window to the specified width and height.scrollBy(): It is used to scroll the document by the given number of pixels.scrollTo(): It is used to scroll to a particular set of coordinates in the document.setInterval(): It repeats a given function at every given time interval.setTimeout(): It executes a function, after waiting a specified number of milliseconds.stop(): It is used to stop the window from loading resources in the current browsing context.Example: This example describes the implementation of the window.object. HTML <!DOCTYPE html> <html> <head> <title> Window's Properties</title> <style> h1 { color: green; } </style> </head> <body> <h1>GeeksforGeeks</h1> <button onclick="show()">Check</button> <p id="prop"></p> <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> </body> </html> Output: Difference between document and window: documentwindowIt 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 Comment More infoAdvertise with us Next Article HTML Introduction A archnabhardwaj Follow Improve Article Tags : HTML javascript-object HTML-Questions Similar Reads HTML Tutorial HTML stands for HyperText Markup Language. It is the standard language used to create and structure content on the web. It tells the web browser how to display text, links, images, and other forms of multimedia on a webpage. HTML sets up the basic structure of a website, and then CSS and JavaScript 11 min read BasicsHTML IntroductionHTML stands for Hyper Text Markup Language, which is the core language used to structure content on the web. It organizes text, images, links, and media using tags and elements that browsers can interpret. As of 2025, over 95% of websites rely on HTML alongside CSS and JavaScript, making it a fundam 6 min read HTML EditorsAn HTML Editor is a software application designed to help users create and modify HTML code. It often includes features like syntax highlighting, tag completion, and error detection, which facilitate the coding process. There are two main types of HTML editors: Text-Based Editors - Allow direct codi 5 min read HTML BasicsHTML (HyperText Markup Language) is the standard markup language used to create and structure web pages. It defines the layout of a webpage using elements and tags, allowing for the display of text, images, links, and multimedia content. As the foundation of nearly all websites, HTML is used in over 7 min read HTML Structure & ElementsHTML ElementsAn HTML Element consists of a start tag, content, and an end tag, which together define the element's structure and functionality. Elements are the basic building blocks of a webpage and can represent different types of content, such as text, links, images, or headings.For example, the <p> ele 5 min read HTML AttributesHTML Attributes are special words used within the opening tag of an HTML element. They provide additional information about HTML elements. HTML attributes are used to configure and adjust the element's behavior, appearance, or functionality in a variety of ways. Each attribute has a name and a value 8 min read HTML HeadingsHTML headings are used to define the titles and subtitles of sections on a webpage. They help organize the content and create a structure that is easy to navigate.Proper use of headings enhances readability by organizing content into clear sections.Search engines utilize headings to understand page 4 min read HTML ParagraphsA paragraph in HTML is simply a block of text enclosed within the <p> tag. The <p> tag helps divide content into manageable, readable sections. Itâs the go-to element for wrapping text in a web page that is meant to be displayed as a distinct paragraph.Syntax:<p> Some Content... 5 min read HTML Text FormattingHTML text formatting refers to the use of specific HTML tags to modify the appearance and structure of text on a webpage. It allows you to style text in different ways, such as making it bold, italic, underlined, highlighted, or struck-through. Table of ContentCategories of HTML Text FormattingLogic 4 min read HTML Block and Inline ElementsHTML elements are either block-level, which structure the layout and span full width (like <div> or <p>), or inline, which styles content within blocks without breaking the flow (like <span> or <a>). This distinction covers 80â90% of common HTML usage.Inline and Block Level E 3 min read HTML CharsetsHTML charsets define how characters are represented in a web document. The character encoding ensures that text appears correctly across different devices and platforms.The <meta> tag's charset attribute is used to specify which character encoding the HTML document uses. By setting the charset 4 min read HTML ListHTML ListsAn HTML List allows you to organize data on web pages into an ordered or unordered format to make the information easier to read and visually appealing. HTML Lists are very helpful for creating structured, accessible content in web development.Types of HTML ListsThere are three main types of lists i 5 min read HTML Ordered ListsAn HTML Ordered List is created using the <ol> tag to display items in a specific sequence, typically numbered or alphabetically ordered. Each list item is defined using the <li> (list item) tag. Ordered lists are widely used for instructions, rankings, and step-by-step guidesâappearing 5 min read HTML Unordered ListsAn unordered list in HTML is used to group a set of list items that don't need to be in a specific order. The items in an unordered list are usually displayed with bullet points by default. Here are the some key features of HTML unordered lists:No Order: Lists items without a specific sequence.Custo 4 min read HTML Description ListsAn HTML Description List is not as commonly used as unordered or ordered lists but serves an important purpose for displaying name-value pairs. This type of list is marked up using three tags: <dl>, <dt>, and <dd>.<dl> (Description List): This tag defines the description list 3 min read HTML Visuals & MediaHTML ColorsHTML Colors can be applied to text, backgrounds, borders, links, forms, tables, etc. This article provides an in-depth look at how colors can be applied to various elements such as text, backgrounds, borders, links, forms, and tables in HTML. We will explore different color formats including hexadec 11 min read HTML Links HyperlinksHTML Links, also known as hyperlinks, are defined by the <a> tag in HTML, which stands for "anchor." These links are essential for navigating between web pages and directing users to different sites, documents, or sections within the same page. The basic attributes of the <a> tag include 3 min read HTML ImagesThe HTML <img> tag is used to embed an image in web pages by linking them. It creates a placeholder for the image, defined by attributes like src, width, height, and alt, and does not require a closing tag.There are two ways to insert the images into a webpage:By providing a full path or addre 7 min read HTML FaviconA favicon (short for "favorite icon") is a small yet important image that appears next to your websiteâs title in the browser tab. Also known as a tab icon or bookmark icon, it helps users quickly identify and return to your site. Studies show that over 85% of users rely on visual cues like favicons 4 min read HTML VideoThe <video> element in HTML is used to show video content on web pages. It supports various video formats, including MP4, WebM, and Ogg. It is introduced in HTML5.Scroll down to the End, there is a Tutorial Video which is a live example of the Video Element displaying on this webpage.Syntax: 4 min read HTML Layout & DesignHTML TablesHTML (HyperText Markup Language) is the standard markup language used to create and structure web pages. It defines the layout of a webpage using elements and tags, allowing for the display of text, images, links, and multimedia content. As the foundation of nearly all websites, HTML is used in over 10 min read HTML IframesAn iframe, or Inline Frame, is an HTML element represented by the <iframe> tag. It functions as a 'window' on your webpage through which visitors can view and interact with another webpage from a different source.Iframes are used for various purposes like:Embedding Multimedia: Easily integrate 4 min read HTML LayoutHTML layouts are a technique used to divide a web page into multiple sections, making it easier to apply styles, organize content, and manage operations efficiently. This division improves readability, accessibility, and overall user experience.HTML layout is achieved through elements like <heade 4 min read HTML File PathsHTML file paths specify the location of files or resources that a webpage needs to access, such as images, videos, scripts, or other HTML documents. These paths tell the web browser where to find the files required to display the content correctly or to execute scripts as intended. To insert a file 3 min read HTML Projects& Advanced TopicsHTML FormsHTML forms, defined using the <form> Tags are essential for collecting user input on web pages. They incorporate a variety of interactive controls such as text fields, numeric inputs, email fields, password fields, checkboxes, radio buttons, and submit buttons. Over 85% of websites rely on for 5 min read HTML5 SemanticsHTML5 introduced a range of semantic elements that clearly describe their purpose in human and machine-readable language. Unlike non-semantic elements, which provide no information about their content, semantic elements clearly define their content. For instance, <form>, <table>, and 6 min read HTML URL EncodingA Uniform Resource Locator (URL) is simply the address of a website to access the website content. Web browsers retrieve pages from web servers using a URL (Uniform Resource Locator).What is URL Encoding?URL Encoding is the process of converting the URL into a valid format that is accepted by web br 4 min read HTML Responsive Web DesignHTML Responsive Web Design is a modern approach to web development that ensures web pages look great on any device, from phones and tablets to desktop computers. It focuses on making HTML elements automatically adjustâresizing, hiding, or repositioning based on the screen size. This approach guarant 11 min read Top 10 Projects For Beginners To Practice HTML and CSS SkillsLearning to code is an exciting journey, especially when stepping into the world of programming with HTML and CSSâthe foundation of every website you see today. For most beginners, these two building blocks are the perfect starting point to explore the creative side of web development, designing vis 8 min read HTML Tutorial ReferencesHTML Tags - A to Z ListHTML Tags are fundamental elements used to structure and format content on web pages. They provide instructions to web browsers on how to render text, images, links, and other media.HTML tags are enclosed in angle brackets < > and usually come in pairs: an opening tag and a closing tag. The cl 15+ min read HTML Attributes Complete ReferenceHTML attributes are special words placed inside the opening tag of an HTML element to define its characteristics. Each attribute has two parts:Attribute nameAttribute value (separated by an equal sign = and enclosed in double quotes " ").Syntax:<tag_name attribute_name="value"> Contents... 8 min read HTML Global AttributesHTML attributes provide additional information about an element and define its properties. Global attributes are special types of attributes that can be used with any HTML element, offering common functionality to enhance behavior and presentation.Global attributes can be applied to any HTML element 5 min read HTML5 Complete ReferenceHTML (HyperText Markup Language) is the standard language used to create and design web pages. It defines the structure and layout of a webpage using a series of elements and tags.HTML5 is the latest version of HTML, bringing significant improvements for building modern web applications.It introduce 8 min read HTML5 MathML Complete ReferenceThe MathML comes in HTML5. The current MathML version is 3. It was introduced in the year 2015. MathML stands for Mathematics Markup Language. It is used to represent mathematical equations or expressions in web browsers, like other HTML elements. MathML is used to describe mathematics as a basis fo 3 min read HTML DOM Complete ReferenceHTML DOM (Document Object Model) is a programming interface that represents the elements of an HTML document in a tree-like structure.Allows developers to change content and layout using JavaScript.Enables dynamic updates and user interaction on websites.Facilitates the addition, removal, or modific 15+ min read HTML DOM Audio/Video Complete ReferenceHTML DOM Audio/Video properties and methods allow developers to control audio and video elements programmatically.These controls include playing, pausing, stopping, and adjusting volume.DOM methods enable dynamic interaction and customization of media elements.They enhance the user experience by off 2 min read SVG Element Complete ReferenceSVG stands for Scalable Vector Graphic. It can be used to make graphics and animations like in HTML canvas. It is a type of vector graphic that may be scaled up or down. Elements are the core things that is required to work with SVGs.List of SVG Elements:SVG ElementsDescription<a>The <a> 5 min read SVG Attribute Complete ReferenceSVG stands for Scalable Vector Graphic. It can be used to make graphics and animations like in HTML canvas. It is a type of vector graphic that may be scaled up or down. Attributes are the things that give the SVG shape, color, etc it will make the SVGs as attractive as you need.List of SVG Attribut 8 min read SVG Property Complete ReferenceSVG stands for Scalable Vector Graphic. It can be used to make graphics and animations like in HTML canvas. It is a type of vector graphic that may be scaled up or down. Properties are used for passing the value to the element, there are lots of properties that can be used in SVG elements. table{ di 7 min read HTML Canvas Complete ReferenceThe HTML âcanvasâ element is used to draw graphics via JavaScript. The âcanvasâ element is only a container for graphics. One must use JavaScript to actually draw the graphics. Canvas has several methods for drawing paths, boxes, circles, text, and adding images.Example: This example shows the basic 4 min read Like