Skip to content

How reflow and repaint work

Posted on:March 9, 2023 at 10:40 AM

First off, what are Repaint and Reflow in the Browser

Repaint
It occurs when changes are made to the appearance of the elements that changes visibility, but doesn't effect the layout

Reflow
It re-calculates the position and geometries of the elements in the document. Reflow happens when changes are made to the elements, that effects partial or the whole page.

Most importantly Reflow of the element will cause the subsequent reflow of all the child and ancestor elements in the DOM

to understand this concept we need to get into how browser renders the website forehead


This is a brief explanation of how browser renders the website.

Browser rendering


So, Why reflow and repaint is so important ??

Reflows are very expensive in terms of performance, and is one of the main causes of slow DOM scripts, especially on devices with low processing power, such as phones. In many cases, they are equivalent to laying out the entire page again.

Basically, most reflows essentially cause page to be re-rendered

which is very expensive work for browser to do if it happens so many times and so often as well as repaint ( not exactly the same tho )

These are the lists of what causes browser to reflow and repaint

In the following post we are going to get into

How we minimize reflow and repaint