Skip to main content

Understanding Reflow and Repaint

Reflow and repaint are two important processes in the browser rendering pipeline that impact the performance of your web applications. Understanding these processes can help you optimize your applications for better performance and user experience.


Reflow, also known as layout, is the process of calculating the layout and position of elements on a web page. When an element's dimensions, position, or content changes, the browser may need to recalculate the layout of the entire page, or a part of it. This can be a time-consuming process and can impact the performance of your application.

Some common actions that can trigger a reflow include:

  • Changing an element's width, height, or position
  • Adding or removing elements from the DOM
  • Changing the font size or style

To minimize reflows, consider the following best practices:

  1. Batch DOM changes: Group your DOM changes together and apply them at once to minimize the number of reflows.
  2. Avoid forced synchronous layout: Read layout properties before making changes to the DOM, to prevent the browser from recalculating the layout multiple times.
  3. Use CSS transitions: Instead of changing element styles directly in JavaScript, use CSS transitions for smoother animations and reduced reflow.


Repaint, also known as redrawing, is the process of updating the screen with the new styles and layout after a reflow. Repaints can be triggered by changes in an element's color, background, or visibility. Like reflows, repaints can also impact the performance of your application.

To minimize repaints, consider the following best practices:

  1. Use layers: Promote elements to their own layer using CSS properties like will-change, transform, or opacity. This can help reduce the area that needs to be repainted.
  2. Optimize animations: When animating elements, use CSS properties that are less likely to trigger repaints, such as transform and opacity.

Here's a simple example to demonstrate how you can optimize an animation:

<!DOCTYPE html>
.box {
width: 100px;
height: 100px;
background-color: red;
position: absolute;
transition: transform 1s;
window.addEventListener('DOMContentLoaded', () => {
const box = document.querySelector('.box');
box.addEventListener('click', () => { = 'translateX(200px)';
<div class="box"></div>

In this example, we use the transform property to move the element smoothly on click, minimizing reflows and repaints.

By understanding reflow and repaint, and applying optimization techniques, you can improve the performance and user experience of your web applications.