DEV Community

Jaligama Satyaveer
Jaligama Satyaveer

Posted on

How Browsers Render Webpages: A Deep Dive into Reflow, Paint, and Repaint

If you’ve ever built a webpage and noticed things getting a bit laggy after adding styles or dynamic elements, you’ve likely triggered something under the hood - like reflow, repaint, or paint.

Don’t worry - these terms might sound complex at first, but they’re actually pretty straightforward once you get the hang of them. Let’s break them down together with real-world examples you can relate to.

The Big Picture: How a Web Page is Rendered
When a browser loads a webpage, it follows a process:

  1. Parses HTML → Creates the DOM Tree
  2. Parses CSS → Builds the CSSOM Tree
  3. Combines DOM + CSSOM → Builds the Render Tree
  4. Performs Layout → Decides the size and position of each element
  5. Paints → Fills in colors, borders, text, shadows
  6. Composites → Draws everything on the screen

Reflow (aka Layout)

Reflow happens when the browser needs to figure out where and how elements should appear on the page - basically recalculating the layout.

Any time you change something that affects an element’s size or position - boom, reflow kicks in.

Example
Imagine you have a blog post with a Read more button. When someone clicks it, more content shows up, pushing the rest of the page down. The browser has to recalculate the layout to fit everything in - that’s reflow.


Paint

Paint is the step where the browser actually fills in the pixels - adding colors, borders, shadows, images, text… basically everything you see.


Repaint

Repaint is a type of paint that happens when an element’s visual appearance changes, but its size or position doesn’t.

So, if you change something like the color, opacity, or visibility of an element, the browser can skip layout calculations and just update the pixels.

Example
Think about switching your website from light mode to dark mode. Text becomes white, backgrounds turn black, but nothing shifts in layout. That’s repaint.


Think of your browser as an artist:

  • Reflow is sketching where everything goes.
  • Paint is coloring in those sketches.
  • Repaint is touching up the colors without redrawing everything.

When you understand what triggers these processes, you start to write better, faster code - and your users feel the difference.

Top comments (0)