<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: koushikmaya</title>
    <description>The latest articles on DEV Community by koushikmaya (@koushikmaya).</description>
    <link>https://dev.to/koushikmaya</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4070584%2F8788dbe1-1fd5-41f3-aca8-d6c2f70af4ab.jpg</url>
      <title>DEV Community: koushikmaya</title>
      <link>https://dev.to/koushikmaya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/koushikmaya"/>
    <language>en</language>
    <item>
      <title>Also added my Handwritten notes at the end .please do check it out.</title>
      <dc:creator>koushikmaya</dc:creator>
      <pubDate>Mon, 10 Aug 2026 09:52:42 +0000</pubDate>
      <link>https://dev.to/koushikmaya/also-added-my-handwritten-notes-at-the-end-please-do-check-it-out-6ae</link>
      <guid>https://dev.to/koushikmaya/also-added-my-handwritten-notes-at-the-end-please-do-check-it-out-6ae</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/koushikmaya/understanding-the-browser-rendering-pipeline-dom-cssom-layout-paint-compositing-layout-pi9" class="crayons-story__hidden-navigation-link"&gt;Understanding the Browser Rendering Pipeline: DOM, CSSOM, Layout, Paint, Compositing &amp;amp; Layout Thrashing&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/koushikmaya" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4070584%2F8788dbe1-1fd5-41f3-aca8-d6c2f70af4ab.jpg" alt="koushikmaya profile" class="crayons-avatar__image" width="800" height="450"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/koushikmaya" class="crayons-story__secondary fw-medium m:hidden"&gt;
              koushikmaya
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                koushikmaya
                
              
              &lt;div id="story-author-preview-content-4359394" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/koushikmaya" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4070584%2F8788dbe1-1fd5-41f3-aca8-d6c2f70af4ab.jpg" class="crayons-avatar__image" alt="" width="800" height="450"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;koushikmaya&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/koushikmaya/understanding-the-browser-rendering-pipeline-dom-cssom-layout-paint-compositing-layout-pi9" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Aug 10&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/koushikmaya/understanding-the-browser-rendering-pipeline-dom-cssom-layout-paint-compositing-layout-pi9" id="article-link-4359394"&gt;
          Understanding the Browser Rendering Pipeline: DOM, CSSOM, Layout, Paint, Compositing &amp;amp; Layout Thrashing
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/css"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;css&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/performance"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;performance&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/frontend"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;frontend&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/koushikmaya/understanding-the-browser-rendering-pipeline-dom-cssom-layout-paint-compositing-layout-pi9" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;1&lt;span class="hidden s:inline"&gt;&amp;nbsp;reaction&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/koushikmaya/understanding-the-browser-rendering-pipeline-dom-cssom-layout-paint-compositing-layout-pi9#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              &lt;span class="hidden s:inline"&gt;Add&amp;nbsp;Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            7 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>css</category>
      <category>frontend</category>
      <category>html</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Understanding the Browser Rendering Pipeline: DOM, CSSOM, Layout, Paint, Compositing &amp; Layout Thrashing</title>
      <dc:creator>koushikmaya</dc:creator>
      <pubDate>Mon, 10 Aug 2026 09:39:27 +0000</pubDate>
      <link>https://dev.to/koushikmaya/understanding-the-browser-rendering-pipeline-dom-cssom-layout-paint-compositing-layout-pi9</link>
      <guid>https://dev.to/koushikmaya/understanding-the-browser-rendering-pipeline-dom-cssom-layout-paint-compositing-layout-pi9</guid>
      <description>&lt;h1&gt;
  
  
  Understanding the Browser Rendering Pipeline: From DOM to Pixels 🚀
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;A beginner-friendly look at DOM, CSSOM, Render Tree, Layout, Paint, Compositing, Critical Rendering Path, and Layout Thrashing.&lt;/p&gt;
&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;While working on my &lt;strong&gt;Week 2 frontend tasks in my training&lt;/strong&gt;, I wanted to understand what actually happens inside the browser when we load a webpage.&lt;br&gt;
I had heard terms like &lt;strong&gt;DOM, CSSOM, reflow, repaint, and compositing&lt;/strong&gt;, but I didn't fully understand how they were connected.&lt;br&gt;
So I decided to learn the &lt;strong&gt;browser rendering pipeline&lt;/strong&gt; and use &lt;strong&gt;Chrome DevTools Performance&lt;/strong&gt; to see some of these concepts in practice.&lt;/p&gt;
&lt;h2&gt;
  
  
  This post covers what I learned and the small experiment I performed on &lt;strong&gt;layout thrashing&lt;/strong&gt;.
&lt;/h2&gt;
&lt;h2&gt;
  
  
  📌 What I Learned
&lt;/h2&gt;

&lt;p&gt;In this learning session, I covered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;DOM Construction&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CSSOM Construction&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Render Tree&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Style Calculation&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Layout / Reflow&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Paint / Repaint&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Compositing&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Critical Rendering Path&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Layout Thrashing&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Batching DOM Reads and Writes&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  - &lt;strong&gt;Chrome DevTools Performance&lt;/strong&gt;
&lt;/h2&gt;
&lt;h1&gt;
  
  
  🔄 Browser Rendering Pipeline
&lt;/h1&gt;

&lt;p&gt;At a high level, the browser goes through something like this:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTML
  ↓
DOM
  ↓
CSS
  ↓
CSSOM
  ↓
Style Calculation
  ↓
Render Tree
  ↓
Layout
  ↓
Paint
  ↓
Compositing
  ↓
Screen
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's understand each stage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's understand each stage.
&lt;/h2&gt;

&lt;h1&gt;
  
  
  1️⃣ DOM Construction
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;DOM&lt;/strong&gt; stands for &lt;strong&gt;Document Object Model&lt;/strong&gt;.&lt;br&gt;
When the browser receives HTML, it parses it and creates a tree-like structure.&lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Welcome&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The browser creates something conceptually like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Document
└── html
    └── body
        ├── h1
        └── p
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the &lt;strong&gt;DOM tree&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Simple way to remember
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;DOM = What elements exist?&lt;/strong&gt;
&lt;/h2&gt;
&lt;h1&gt;
  
  
  2️⃣ CSSOM Construction
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;CSSOM&lt;/strong&gt; stands for &lt;strong&gt;CSS Object Model&lt;/strong&gt;.&lt;br&gt;
The browser also parses CSS and creates a representation of the CSS rules.&lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;32px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;gray&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The CSSOM helps the browser understand how the elements should be styled.&lt;/p&gt;

&lt;h3&gt;
  
  
  Simple way to remember
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DOM   → What exists?
CSSOM → How should it look?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  3️⃣ Style Calculation
&lt;/h1&gt;

&lt;p&gt;Now the browser needs to figure out which styles actually apply to each element.&lt;br&gt;
It considers things such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CSS selectors&lt;/li&gt;
&lt;li&gt;Cascade&lt;/li&gt;
&lt;li&gt;Specificity&lt;/li&gt;
&lt;li&gt;Inheritance&lt;/li&gt;
&lt;li&gt;Browser default styles&lt;/li&gt;
&lt;li&gt;Media queries&lt;/li&gt;
&lt;li&gt;CSS variables
For example:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.article&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  4️⃣ Render Tree
&lt;/h1&gt;

&lt;p&gt;The browser combines the DOM and CSSOM to determine what actually needs to be rendered.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DOM + CSSOM
     ↓
Style Calculation
     ↓
Render Tree
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;Render Tree&lt;/strong&gt; isn't exactly the same as the DOM.&lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.hidden&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The element still exists in the DOM, but it doesn't participate in the normal rendered layout.&lt;/p&gt;

&lt;h3&gt;
  
  
  Simple way to remember
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Render Tree = What actually participates in rendering?&lt;/strong&gt;
&lt;/h2&gt;
&lt;h1&gt;
  
  
  5️⃣ Layout / Reflow
&lt;/h1&gt;

&lt;p&gt;Once the browser knows what needs to be rendered, it needs to calculate the size and position of the elements.&lt;br&gt;
This is the &lt;strong&gt;Layout&lt;/strong&gt; stage.&lt;br&gt;
It calculates things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Width&lt;/li&gt;
&lt;li&gt;Height&lt;/li&gt;
&lt;li&gt;Position&lt;/li&gt;
&lt;li&gt;Margin&lt;/li&gt;
&lt;li&gt;Padding&lt;/li&gt;
&lt;li&gt;Text positioning
For example:
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.card&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;300px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The browser needs to calculate where the card is and how much space it occupies.&lt;/p&gt;

&lt;h3&gt;
  
  
  Simple way to remember
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Layout = Where is everything and how big is it?&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Layout is also commonly referred to as &lt;strong&gt;reflow&lt;/strong&gt;.
&lt;/h2&gt;
&lt;h1&gt;
  
  
  6️⃣ Paint / Repaint
&lt;/h1&gt;

&lt;p&gt;After calculating the layout, the browser needs to draw the page.&lt;br&gt;
This is the &lt;strong&gt;Paint&lt;/strong&gt; stage.&lt;br&gt;
Paint deals with things such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Text&lt;/li&gt;
&lt;li&gt;Backgrounds&lt;/li&gt;
&lt;li&gt;Borders&lt;/li&gt;
&lt;li&gt;Images&lt;/li&gt;
&lt;li&gt;Shadows&lt;/li&gt;
&lt;li&gt;Gradients
For example:
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.card&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#ddd&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;box-shadow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;4px&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt; &lt;span class="no"&gt;gray&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These visual details need to be painted.&lt;/p&gt;

&lt;h3&gt;
  
  
  Simple way to remember
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Paint = Draw what the user should see.&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  If something visual changes, the browser may need to paint that area again. This is commonly called a &lt;strong&gt;repaint&lt;/strong&gt;.
&lt;/h2&gt;
&lt;h1&gt;
  
  
  7️⃣ Compositing
&lt;/h1&gt;

&lt;p&gt;After painting, the browser may have different painted surfaces or layers that need to be combined.&lt;br&gt;
That's where &lt;strong&gt;Compositing&lt;/strong&gt; comes in.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Layer 1
   +
Layer 2
   +
Layer 3
   ↓
Compositing
   ↓
Screen
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Properties such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;transform&lt;/span&gt;
&lt;span class="nt"&gt;opacity&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;can often be handled efficiently by the compositor.&lt;br&gt;
This is one reason these properties are commonly used for animations.&lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.box&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  8️⃣ Critical Rendering Path
&lt;/h1&gt;

&lt;p&gt;Now we can put everything together.&lt;br&gt;
The simplified &lt;strong&gt;Critical Rendering Path&lt;/strong&gt; looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTML
  ↓
DOM

CSS
  ↓
CSSOM

DOM + CSSOM
  ↓
Style Calculation
  ↓
Render Tree
  ↓
Layout
  ↓
Paint
  ↓
Compositing
  ↓
Screen
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript can modify the DOM or CSS, which may cause parts of this process to run again.&lt;/p&gt;

&lt;h2&gt;
  
  
  This is where &lt;strong&gt;frontend performance&lt;/strong&gt; becomes important.
&lt;/h2&gt;

&lt;h1&gt;
  
  
  🧪 Practical Experiment With Chrome DevTools
&lt;/h1&gt;

&lt;p&gt;Learning the theory was useful, but I wanted to actually see what was happening.&lt;br&gt;
So I used my &lt;strong&gt;Week 2 responsive landing page&lt;/strong&gt; and opened:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Chrome DevTools
→ Performance
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I recorded the page load and inspected the &lt;strong&gt;Main&lt;/strong&gt; thread.&lt;br&gt;
I found rendering-related activities such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Recalculate Style
Layout
Paint
Composite / Commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This helped me connect the theory with what the browser was actually doing.&lt;br&gt;
Instead of just reading:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"The browser performs layout and paint."&lt;/p&gt;
&lt;h2&gt;
  
  
  I could actually see rendering activity in DevTools.
&lt;/h2&gt;
&lt;h1&gt;
  
  
  🔥 Layout Thrashing Experiment
&lt;/h1&gt;

&lt;p&gt;The most interesting part of the experiment was &lt;strong&gt;layout thrashing&lt;/strong&gt;.&lt;br&gt;
I created a simple page with multiple boxes and used JavaScript to change their height and immediately read their height.&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;box&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;boxes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;100px&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;offsetHeight&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;100px&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is a &lt;strong&gt;write&lt;/strong&gt; because I'm changing the style.&lt;br&gt;
And:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;offsetHeight&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is a &lt;strong&gt;layout read&lt;/strong&gt; because I'm asking the browser for the current height.&lt;br&gt;
So the pattern becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WRITE
  ↓
READ
  ↓
WRITE
  ↓
READ
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When layout has been invalidated, reading layout information such as &lt;code&gt;offsetHeight&lt;/code&gt; can require the browser to synchronously update layout.&lt;/p&gt;

&lt;h2&gt;
  
  
  Doing this repeatedly can lead to &lt;strong&gt;layout thrashing&lt;/strong&gt;.
&lt;/h2&gt;

&lt;h1&gt;
  
  
  🤔 Why Is &lt;code&gt;offsetHeight&lt;/code&gt; Important?
&lt;/h1&gt;

&lt;p&gt;Some properties require the browser to provide up-to-date layout information.&lt;br&gt;
Examples include:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;offsetWidth&lt;/span&gt;
&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;offsetHeight&lt;/span&gt;
&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;clientWidth&lt;/span&gt;
&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;clientHeight&lt;/span&gt;
&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBoundingClientRect&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  If we've just changed something that affects layout and then immediately request one of these values, the browser may need to perform layout work before returning the result.
&lt;/h2&gt;

&lt;h1&gt;
  
  
  ❌ The Problem: Layout Thrashing
&lt;/h1&gt;

&lt;p&gt;The problematic pattern is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;box&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;boxes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;100px&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;offsetHeight&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WRITE → READ
WRITE → READ
WRITE → READ
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  This can cause unnecessary synchronous layout work
&lt;/h2&gt;

&lt;h1&gt;
  
  
  ✅ Fixing Layout Thrashing
&lt;/h1&gt;

&lt;p&gt;The basic solution is to &lt;strong&gt;separate reads and writes&lt;/strong&gt;.&lt;br&gt;
Instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WRITE → READ
WRITE → READ
WRITE → READ
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we can do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;READ
READ
READ
  ↓
WRITE
WRITE
WRITE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The optimized version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// READ&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;box&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;boxes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;offsetHeight&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// WRITE&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;box&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;boxes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;100px&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  This gives the browser a better opportunity to batch the rendering work.
&lt;/h2&gt;

&lt;h1&gt;
  
  
  📊 Before vs After
&lt;/h1&gt;

&lt;h2&gt;
  
  
  ❌ Before
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;box&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;boxes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;100px&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;offsetHeight&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pattern:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WRITE → READ
WRITE → READ
WRITE → READ
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ✅ After
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;box&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;boxes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;offsetHeight&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;box&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;boxes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nx"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;100px&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pattern:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;READ
READ
READ
   ↓
WRITE
WRITE
WRITE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  🔍 What I Observed in DevTools
&lt;/h1&gt;

&lt;p&gt;I recorded both versions using the &lt;strong&gt;Performance&lt;/strong&gt; panel.&lt;br&gt;
I was able to inspect:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;JavaScript execution&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Recalculate Style&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Layout activity&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Paint&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compositing / Commit&lt;/strong&gt;
One thing I learned during the experiment is that Chrome is heavily optimized, so we shouldn't expect to see one separate &lt;code&gt;Layout&lt;/code&gt; event for every single operation.
The important part was understanding &lt;strong&gt;why alternating layout writes and reads can cause synchronous rendering work&lt;/strong&gt;.
---
# 💡 Key Takeaways
| Concept | What I learned |
| --- | --- |
| &lt;strong&gt;DOM&lt;/strong&gt; | Represents the structure of the HTML document. |
| &lt;strong&gt;CSSOM&lt;/strong&gt; | Represents the CSS rules. |
| &lt;strong&gt;Render Tree&lt;/strong&gt; | Determines what participates in rendering. |
| &lt;strong&gt;Layout&lt;/strong&gt; | Calculates the size and position of elements. |
| &lt;strong&gt;Paint&lt;/strong&gt; | Draws the visual appearance. |
| &lt;strong&gt;Compositing&lt;/strong&gt; | Combines painted surfaces/layers into the final frame. |
| &lt;strong&gt;Layout Thrashing&lt;/strong&gt; | Can happen when layout-affecting writes and layout reads are repeatedly mixed. |
| &lt;strong&gt;Performance Optimization&lt;/strong&gt; | Batch DOM/layout reads and writes when possible. |
| &lt;strong&gt;DevTools&lt;/strong&gt; | Performance tools are useful for understanding what the browser is actually doing instead of simply guessing. |
---
# 🎯 What I Learned From This
Before doing this experiment, I mostly thought about HTML, CSS, and JavaScript as separate parts of frontend development.
Now I have a better understanding of how they connect:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTML
 ↓
DOM
 ↓
CSSOM
 ↓
Render Tree
 ↓
Layout
 ↓
Paint
 ↓
Compositing
 ↓
Screen
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also learned that &lt;strong&gt;the way JavaScript interacts with the DOM can affect browser rendering performance&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The layout-thrashing experiment was especially useful because I could see how a simple operation like reading &lt;code&gt;offsetHeight&lt;/code&gt; can become important when it is repeatedly mixed with style changes.
&lt;/h2&gt;

&lt;h1&gt;
  
  
  🏁 Conclusion
&lt;/h1&gt;

&lt;p&gt;This was one of those topics that made much more sense after actually experimenting with it.&lt;br&gt;
Instead of only reading about &lt;strong&gt;reflow, repaint, and compositing&lt;/strong&gt;, I used &lt;strong&gt;Chrome DevTools&lt;/strong&gt; to observe the browser's rendering work.&lt;br&gt;
The biggest lesson I took from this experiment is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Don't just learn how the browser works. Use DevTools to see it working.&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  This experiment gave me a better understanding of what happens behind the scenes when the browser turns our HTML, CSS, and JavaScript into pixels.
&lt;/h2&gt;
&lt;h1&gt;
  
  
  🛠️ Practical Work
&lt;/h1&gt;

&lt;p&gt;As part of my Week 2 learning, I worked on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Responsive landing page&lt;/li&gt;
&lt;li&gt;✅ Chrome DevTools Performance analysis&lt;/li&gt;
&lt;li&gt;✅ Layout, Paint and Compositing investigation&lt;/li&gt;
&lt;li&gt;✅ Layout thrashing experiment&lt;/li&gt;
&lt;li&gt;✅ Batched DOM reads and writes&lt;/li&gt;
&lt;li&gt;✅ Before/after performance comparison
## Tools Used&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;HTML&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CSS&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JavaScript&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Chrome DevTools&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  - &lt;strong&gt;VS Code&lt;/strong&gt;
&lt;/h2&gt;
&lt;h1&gt;
  
  
  📚 Final Note
&lt;/h1&gt;

&lt;p&gt;I'm still learning frontend performance, but this experiment helped me understand that &lt;strong&gt;writing frontend code isn't only about making the page look correct — it's also about understanding how the browser processes that code.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  📝 My Handwritten Notes
&lt;/h2&gt;

&lt;p&gt;I also made handwritten notes while learning these concepts. They helped me understand the browser rendering pipeline and remember the key points.&lt;br&gt;
Here are my notes:&lt;br&gt;
Handwritten notes - Browser Rendering Pipeline&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F86mn9wk0p5cjllov3lx1.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F86mn9wk0p5cjllov3lx1.jpeg" alt=" " width="800" height="1217"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuz6g54e4szzup4zeptr7.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuz6g54e4szzup4zeptr7.jpeg" alt=" " width="800" height="751"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc0jznf7hgsuiys4v5sub.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc0jznf7hgsuiys4v5sub.jpeg" alt=" " width="800" height="1122"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftjw6es64606r5j4vd51y.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftjw6es64606r5j4vd51y.jpeg" alt=" " width="800" height="997"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fg9nd67550r3lqpzplmb7.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fg9nd67550r3lqpzplmb7.jpeg" alt=" " width="800" height="1526"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fptpnh0kr9eumw09fdq5t.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fptpnh0kr9eumw09fdq5t.jpeg" alt=" " width="800" height="968"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>performance</category>
      <category>frontend</category>
    </item>
    <item>
      <title>CSS Architecture</title>
      <dc:creator>koushikmaya</dc:creator>
      <pubDate>Mon, 10 Aug 2026 06:21:17 +0000</pubDate>
      <link>https://dev.to/koushikmaya/css-architecture-257i</link>
      <guid>https://dev.to/koushikmaya/css-architecture-257i</guid>
      <description>&lt;h1&gt;
  
  
  Responsive CSS: From Mobile-First Design to Modern Styling
&lt;/h1&gt;

&lt;p&gt;Responsive design is about creating websites that work well across mobile, tablet, and desktop screens. In this post, I learned some important techniques for building responsive and maintainable CSS.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Mobile-First Media Queries
&lt;/h2&gt;

&lt;p&gt;Mobile-first means writing the base CSS for smaller screens first and then enhancing the layout for larger screens.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Mobile */&lt;/span&gt;
&lt;span class="nc"&gt;.card&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Tablet */&lt;/span&gt;
&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;768px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;.card&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;70%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Desktop */&lt;/span&gt;
&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1024px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;.card&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The main idea is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mobile → Tablet → Desktop&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;min-width&lt;/code&gt; is commonly used for mobile-first development because styles are progressively added as the screen gets larger.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;min-width&lt;/code&gt; vs &lt;code&gt;max-width&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;min-width&lt;/code&gt;: applies styles when the screen is at least the specified width.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;max-width&lt;/code&gt;: applies styles when the screen is at most the specified width.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;768px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  One important lesson I learned: &lt;strong&gt;CSS media queries belong inside &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; or a CSS file, not inside &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt;.&lt;/strong&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  2. Fluid Typography
&lt;/h2&gt;

&lt;p&gt;Fixed font sizes don't always work well across different screen sizes. Fluid typography allows text to adapt to the viewport.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;rem&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;rem&lt;/code&gt; is relative to the root font size.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the root size is 16px, &lt;code&gt;2rem&lt;/code&gt; is 32px.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;vw&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;vw&lt;/code&gt; is relative to the viewport width.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5vw&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, using only &lt;code&gt;vw&lt;/code&gt; can make text too small or too large.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;clamp()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;clamp()&lt;/code&gt; provides a minimum, flexible value, and maximum:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;clamp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.5rem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4vw&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3rem&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  This allows the font size to grow smoothly while keeping it within limits.
&lt;/h2&gt;

&lt;h2&gt;
  
  
  3. Responsive Images
&lt;/h2&gt;

&lt;p&gt;Images can consume a lot of bandwidth, so responsive images help browsers choose an appropriate image for the device.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;srcset&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt;
    &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"small.jpg"&lt;/span&gt;
    &lt;span class="na"&gt;srcset=&lt;/span&gt;&lt;span class="s"&gt;"
        small.jpg 400w,
        medium.jpg 800w,
        large.jpg 1200w"&lt;/span&gt;
    &lt;span class="na"&gt;sizes=&lt;/span&gt;&lt;span class="s"&gt;"100vw"&lt;/span&gt;
    &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Mountain"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;srcset&lt;/code&gt; provides multiple image sizes, allowing the browser to choose an appropriate resource.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;&amp;lt;picture&amp;gt;&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;picture&lt;/code&gt; is useful when different images should be displayed at different screen sizes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;picture&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;source&lt;/span&gt;
        &lt;span class="na"&gt;media=&lt;/span&gt;&lt;span class="s"&gt;"(min-width: 1000px)"&lt;/span&gt;
        &lt;span class="na"&gt;srcset=&lt;/span&gt;&lt;span class="s"&gt;"desktop.jpg"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;source&lt;/span&gt;
        &lt;span class="na"&gt;media=&lt;/span&gt;&lt;span class="s"&gt;"(min-width: 600px)"&lt;/span&gt;
        &lt;span class="na"&gt;srcset=&lt;/span&gt;&lt;span class="s"&gt;"tablet.jpg"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"mobile.jpg"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Nature"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/picture&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  4. BEM Naming Convention
&lt;/h2&gt;

&lt;p&gt;BEM stands for:&lt;br&gt;
&lt;strong&gt;Block → Element → Modifier&lt;/strong&gt;&lt;br&gt;
It helps keep CSS class names organized and reduces naming conflicts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card card--dark"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card__image"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card__title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        Product
    &lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card__text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        Description
    &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The structure is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Block
.card
Element
.card__title
Modifier
.card--dark
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  BEM makes larger CSS projects easier to understand and maintain.
&lt;/h2&gt;

&lt;h2&gt;
  
  
  5. Utility-First Styling
&lt;/h2&gt;

&lt;p&gt;Utility-first CSS uses small, reusable classes to build a component.&lt;br&gt;
A popular example is Tailwind CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"bg-blue-500 text-white p-4 rounded"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Submit
&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each utility generally performs a specific styling job.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Fast development&lt;/li&gt;
&lt;li&gt;Reusable utility classes&lt;/li&gt;
&lt;li&gt;Consistent styling&lt;/li&gt;
&lt;li&gt;Less custom CSS
### Disadvantage
HTML can become crowded with many classes.
---
## 6. Component-Scoped Styling
CSS Modules are an example of component-scoped styling.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Button.module.css */&lt;/span&gt;
&lt;span class="nc"&gt;.button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then in a component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styles&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./Button.module.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            Submit
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The styles are scoped to the component, which helps prevent global CSS conflicts.
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Utility-First vs CSS Modules
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Utility-First&lt;/th&gt;
&lt;th&gt;CSS Modules&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Styling&lt;/td&gt;
&lt;td&gt;Utility classes&lt;/td&gt;
&lt;td&gt;Component CSS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;HTML&lt;/td&gt;
&lt;td&gt;More classes&lt;/td&gt;
&lt;td&gt;Cleaner&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scope&lt;/td&gt;
&lt;td&gt;Utilities&lt;/td&gt;
&lt;td&gt;Component-scoped&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Development&lt;/td&gt;
&lt;td&gt;Very fast&lt;/td&gt;
&lt;td&gt;Structured&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best for&lt;/td&gt;
&lt;td&gt;Rapid UI development&lt;/td&gt;
&lt;td&gt;Component-based applications&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Neither approach is universally better. The choice depends on the project's requirements, team preferences, and architecture.
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;p&gt;From this topic, I learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start responsive designs with a &lt;strong&gt;mobile-first approach&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;min-width&lt;/code&gt; to progressively enhance layouts.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;rem&lt;/code&gt;, &lt;code&gt;vw&lt;/code&gt;, and especially &lt;code&gt;clamp()&lt;/code&gt; for flexible typography.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;srcset&lt;/code&gt; for different image sizes.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;&amp;lt;picture&amp;gt;&lt;/code&gt; when different image sources are needed.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;BEM&lt;/strong&gt; to create structured and predictable CSS class names.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Utility-first CSS&lt;/strong&gt; focuses on composing designs from small utility classes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CSS Modules&lt;/strong&gt; provide component-scoped styling.&lt;/li&gt;
&lt;li&gt;Media queries are &lt;strong&gt;CSS&lt;/strong&gt;, so they belong in &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; or &lt;code&gt;.css&lt;/code&gt; files, not &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt;.
Responsive CSS is not just about making a website "fit" on different screens. It's about building layouts that &lt;strong&gt;adapt, remain accessible, perform well, and are easy to maintain&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>responsive</category>
      <category>css</category>
      <category>mobilefirst</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
