At what point in the parsing/rendering process do HTML elements get assigned a box model?

56 Views Asked by At

Is it during the construction of the CSSOM (where possibly default padding/border/margin is applied to all nodes)?

1

There are 1 best solutions below

0
On

An element's box is (re)calculated in what is called the "update layout" phase, which is currently specified* as happening (at least) inside the next "update the rendering" step of the event-loop, at sub-step 14:

  1. For each fully active Document doc in docs:
  • Recalculate styles and update layout for doc

but it can also be forced synchronously when calling some getters.

*Though this is a quite recent addition to the specs and not all browsers do follow it exactly, for instance I know from experience that to do this layout update Safari will not wait for the next "painting frame", but just some idle time.