What is the reason for the absence of absolutely positioned elements in the render tree?

Recently, I came across some information about the render tree:

As the DOM tree is being created, the browser simultaneously generates a separate tree known as the render tree. This tree consists of visual elements arranged in the order they will appear on the screen. It serves as the visual representation of the document. The render tree does not include elements with display:none, absolute positioning, or those found within the HEAD section.

I find the last part somewhat perplexing. Shouldn't the render tree contain all visible elements, including those with absolute positioning? How exactly does the browser handle rendering these types of elements (display:none, positioned absolutely, located in the HEAD)? Can someone provide more detailed clarification on this matter?

Answer №1

I'm not entirely certain where you came across that information, but elements with position: absolute are indeed rendered (without question).

The rendering process involves two trees: the DOM and CSSOM. When combined, these trees generate the render tree responsible for constructing the visible page layout.

According to insights from Google Developers, while elements with display: none will not be rendered, there is no definitive indication that elements with position: absolute suffer the same fate.

Google Developers - Render-tree construction, layout, and paint

A few crucial points highlighted in the article:

  • The combination of CSSOM and DOM trees results in a render tree used to determine the layout of every visible element, which then informs the painting process responsible for displaying content on screen. (emphasis added)

  • The merge of DOM and CSSOM trees forms the render tree that exclusively contains the necessary nodes to render the page effectively.

  • The initial browser step involves merging the DOM and CSSOM into a "render tree" which encompasses all visible DOM content on the page, alongside all associated CSSOM style details. (emphasis added)

  • To build the render tree, the browser broadly follows these steps:

    • Starting at the root of the DOM tree, iterate through each accessible node.

      • Certain nodes remain invisible (e.g., script tags, meta tags, etc.) and are excluded as they don't contribute to the final output.

      • Nodes hidden via CSS rules are also left out from the render tree – for instance, a span node featuring a display: none rule won't be included.

    • For each visible node, apply the applicable CSSOM rules and incorporate them.

    • Emit visible nodes along with their content and computed styles.

  • The result is a render reflecting both the content and style specifications for all observable content on the display. (emphasis added)

For further reading, check out the complete article here: Render-tree construction, layout, and paint

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for accessing the following element within an array using a for loop with the syntax for (let obj of objects)

Is there a way to access the next element in an array while iterating through it? for (let item of list) { // accessing the item at index + 1 } Although I am aware that I could use a traditional for loop, I would rather stick with this syntax. for (i ...

Best Placement for Socket.io Server in WebStorm Express Template

Trying to integrate socket.io into an express server generated by WebStorm. Should the setup of the server and socket.on events all be placed inside /bin/www, or is it better practice to create separate controllers like index and users pages? https://i.ss ...

Managing class values with Selenium - Manipulating and updating classes

In the program I'm working on, there is a need to toggle which element receives the class value of "selected". <div class="countryValues"> <div data-val="" >USA and Canada</div> <div data-val="US" >USA - All< ...

Learn how to access the `$root` instance in Vue.js 3 setup() function

When working with Vue 2, accessing this.$root is possible within the created hook. However, in Vue 3, the functionality that would normally be placed within the created hook is now handled by setup(). The challenge arises when trying to access properties ...

Can an <option> element in WebKit be customized by adding an icon to it?

I have integrated a WebView into one of my software applications, and within the HTML page it is rendering, there is a <select> tag. I am interested in enhancing the <option> elements within this select tag by adding icons to them: (The shadow ...

Unit test produced an unforeseen outcome when executing the function with the setTimeout() method

When manually testing this code in the browser's console, it performs as expected. The correct number of points is displayed with a one-second delay in the console. const defer = (func, ms) => { return function() { setTimeout(() => func.ca ...

Issues with IE8 compatibility on the website

I'm in the process of developing a website and I'm facing some issues specifically with IE8 or later versions. For reference, here is a temporary link to the site: . 1 The problems I am encountering are as follows: The login/register form disp ...

Creating a timer implementation in Node.js using Socket.IO

In the process of developing a drawing and guessing game using node.js and socket.io, I have a structure consisting of a Room class, a Game class (which is an extension of Room), and a Round class where each game consists of 10 rounds. During each round, a ...

Connecting Documents Together

I'm looking to learn how to link files together, specifically creating a button that when clicked takes you to another site or the next page of reading. I apologize if this is a simple question, as I am new to coding and only familiar with password-ba ...

CSS - Help! Seeing different results on Internet Explorer

I'm currently handling an OSCommerce website, and I'm trying to figure out why this issue is occurring. You can view the website at this link: The layout looks completely different on Internet Explorer, and I'm puzzled as everything should ...

Encountering Typescript errors when trying to destructure a forEach loop from the output of

There are different types categorized based on mimetypes that I am currently working with. export type MimeType = 'image' | 'application' | 'text'; export type ApplicationMimeType = '.pdf' | '.zip'; expor ...

What is the best way to obtain the output produced by a function when a button is clicked

When I click on a button, the desired action is to trigger a function that adds a new property inside an object within a large array of multiple objects. This function then eventually returns a new array. How can I access and utilize this new array? I am ...

What location is most ideal for incorporating JavaScript/Ajax within a document?

Sorry for the seemingly simple question, but I would appreciate some clarification from the experts. When it comes to the three options of placing JavaScript - head, $(document).ready, or body, which would be the optimal location for ajax that heavily rel ...

Function for masking phone numbers is adding additional "x's" to the input field

My phone number formatting script is supposed to add dashes after the third and sixth characters, as well as insert an "x" after the 10th character for extensions. However, it is adding extra "x's" after the 12th character, resulting in the incorrect ...

Tips for adding transparent images (such as logos) to an HTML website: I'm struggling with getting rid of the white background that appears on the website. Does anyone know how

Seeking guidance as a beginner web developer. I am currently working on adding a transparent logo to my website, but the white background is showing up behind the logo. How can I fix this issue? Here is the link to the image - Here is the HTML & ...

Tips for assigning an AngularJS data-bound value to the href attribute of an anchor tag

I need to include multiple email ids separated by commas from an angularjs binded value in the mailto field of an anchor tag. The team.emails variable can contain either a single email id or multiple email ids separated by commas. <tr ng-repeat="team ...

Issue with ChartJs version 2.8.0: The custom tooltip remains visible even when clicking outside the chart canvas or moving the mouse pointer

I am utilizing ChartJs to display a line chart with a custom tooltip that appears upon the click event of the data points. The challenge I am facing is that the custom tooltip remains visible even when the mouse pointer is outside the chart canvas area. ...

Express.js throwing an unexpected 404 error

I'm really struggling to understand why Node (express) only renders the index page and returns a 404 error for other pages, like "comproAffitto" in this example. In my app.js file: var index = require('./routes/index'); var comproAffitto= ...

An error was encountered in compiler.js at line 1021, stating that an unexpected value 'UserService' was imported by the module 'UserModule'. It is recommended to add a @NgModule annotation to resolve this issue

As a PHP programmer new to Angular, I am facing an issue while trying to retrieve user properties from a Laravel API. When attempting this, I encountered the following error: compiler.js:1021 Uncaught Error: Unexpected value 'UserService' importe ...

When the last character in the route is a forward slash, the Express server will load the HTML page with CSS and JavaScript. Conversely, if the last route character

On my second html page model.html, I noticed the following issue: When I include a '/' at the end of my route address in the browser like this: http://localhost:3002/home/model/, the correct html page is loaded, but the css/js files do not load. ...