Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

CSS for Performance – Avoiding Layout Th | CSS Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. CSS Course

Lesson 48 of 50

·css

CSS for Performance – Avoiding Layout Thrash

9 mins

Course progress96%

What you'll learn

Keep this idea in mind as you work through the lesson.

1 point
  • `contain` tells the browser the element’s layout, style, and paint are self‑contained, reducing repaint cost. * Animate only `transform`/`opacity` for smooth 60 fps experience. * Minimize the number of **recalculations** in scroll‑heavy pages.

Layout thrashing occurs when JavaScript reads layout properties (offsetWidth) then writes styles that cause a reflow.

  • Prefer transform and opacity for animations (GPU‑accelerated).
  • Batch DOM reads/writes using requestAnimationFrame.
  • Use contain to limit reflow scope.

Example: Containment

.widget { contain:layout style; }
Make it stickPractice what you've learned1 quiz · 6 practical tests · Optional activities from CSS CourseBrowse activities
Previous lessonCSS Grid + Flexbox Hybrid LayoutsContinue to lesson 49CSS Testing – Visual Regression & LintingBack to CSS Course curriculum