MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Critical Rendering Path & Reflow/Repaint0%
Study Materials
JavaScript for AdvancedProgress 0%
1.1Higher-Order Functions & Currying1.2Function Composition & Pipelining1.3Memoization & Pure Functions1.4Execution Context & Call Stack Deep Dive1.5Scope Chain & Lexical Environment
13.1Critical Rendering Path & Reflow/Repaint13.2requestAnimationFrame & Smooth Animations13.3Memory Management & Garbage Collection13.4Core Web Vitals & JavaScript Impact
HomeTutorialsJavaScript for AdvancedCritical Rendering Path & Reflow/Repaint
requestAnimationFrame & Smooth Animations

Critical Rendering Path & Reflow/Repaint

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study Materials

Understanding how browsers convert HTML, CSS, and JavaScript into pixels on the display screen is the hallmark of senior frontend engineers. The Critical Rendering Path (CRP) dictates rendering performance, and careless DOM manipulation triggers devastating Reflows (Layout) and Repaints.


1. The 5 Steps of the Critical Rendering Path

1 1. DOM Construction (HTML ──► DOM Tree)
2 │
3 2. CSSOM Construction (CSS ──► CSS Object Model)
4 │
5 ▼
6 3. Render Tree (Combines visible DOM nodes with matched CSS rules)
7 │
8 ▼
9 4. Layout (Reflow) (Computes exact pixel geometry, coordinates, and size of every box)
10 │
11 ▼
12 5. Paint & Composite (Fills pixels on raster layers; GPU composites layers onto screen)

2. Reflow vs. Repaint

OperationTriggered ByCostDescription
Reflow (Layout)Changes affecting geometry, dimensions, or positions (width, height, margin, font-size, adding/removing nodes)Extremely ExpensiveRecomputes layout geometry of target node and all affected ancestors/descendants!
Repaint (Paint)Changes affecting appearance only without changing dimensions (color, background-color, box-shadow, visibility)ModerateRedraws pixels on affected layers without recalculating layout coordinates.
Composite OnlyChanges using transform and opacityCheapest (Ideal)GPU composites layers directly with zero CPU reflow and zero CPU repaint!

3. The Performance Killer: Forced Synchronous Layout (Layout Thrashing)

Normally, browsers batch DOM mutations and execute Reflow asynchronously at the end of the frame. However, if code reads geometric properties immediately after writing styles, the browser is forced to flush layout synchronously:

1// DANGER: Layout Thrashing (Forces 100 Reflows in a single frame!)
2const cards = document.querySelectorAll('.card');
3 
4cards.forEach(card => {
5 // READ: Forces synchronous layout calculation!
6 const height = card.offsetHeight;
7
8 // WRITE: Invalidates layout!
9 card.style.height = `${height + 10}px`;
10});

Properties that Trigger Forced Reflow:

  • element.offsetWidth, offsetHeight, clientWidth, clientHeight
  • element.getBoundingClientRect()
  • window.scrollY, window.getComputedStyle()

The Fix: Batch Reads First, Writes Second

1// SAFE: Batch all READS first, then execute all WRITES
2const heights = [...cards].map(c => c.offsetHeight); // All Reads batch together
3 
4cards.forEach((card, i) => {
5 card.style.height = `${heights[i] + 10}px`; // All Writes batch together!
6});

4. Hardware Acceleration with CSS will-change

Promoting an element to its own GPU compositor layer bypasses CPU painting:

1/* Informs browser to promote element to a dedicated GPU layer */
2.animated-sidebar {
3 will-change: transform, opacity;
4 transform: translate3d(0, 0, 0);
5}

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Which step in the Critical Rendering Path computes the exact physical pixel dimensions and screen coordinates of elements?
Question 2
Which pair of CSS properties is processed entirely on the GPU compositor layer, bypassing both Reflow and Repaint?
Question 3
What causes "Forced Synchronous Layout" (Layout Thrashing)?
Question 4
How should a developer restructure code to eliminate layout thrashing?
Question 5
What does the CSS property will-change: transform hint to the browser?
Next Lesson

requestAnimationFrame & Smooth Animations

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Streaming JSON & NDJSONrequestAnimationFrame & Smooth Animations

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Advanced with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext