<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ web layout - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ web layout - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sun, 31 May 2026 09:39:06 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/web-layout/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ What is CSS Subgrid? A Practical Tutorial ]]>
                </title>
                <description>
                    <![CDATA[ When designers create layouts in their mockups, everything including the content typically looks perfectly aligned and consistent. But in the real world, user-generated content varies wildly. For example, one testimonial card might have a brief sente... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-css-subgrid/</link>
                <guid isPermaLink="false">66c62f1ff3f170bad73e8630</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ webdev ]]>
                    </category>
                
                    <category>
                        <![CDATA[ web layout ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ophy Boamah ]]>
                </dc:creator>
                <pubDate>Wed, 21 Aug 2024 18:17:03 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1724227015705/f55ae862-c81f-4453-af92-cb96acf0d13d.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>When designers create layouts in their mockups, everything including the content typically looks perfectly aligned and consistent.</p>
<p>But in the real world, user-generated content varies wildly. For example, one testimonial card might have a brief sentence, while another has an entire paragraph. This makes it challenging to maintain a perfect alignment.</p>
<p>CSS Subgrid can easily handle these web layout inconsistencies. It allows nested elements to align with their parent grid, ensuring a consistent look regardless of the content.</p>
<p>In this tutorial, we’ll explore how to use CSS Subgrid to create a products section that stays flexible and looks great. You can move along to see what we'll build <a class="post-section-overview" href="#heading-building-a-products-section-with-subgrid">here</a>.</p>
<h3 id="heading-table-of-contents">Table of Contents</h3>
<ul>
<li><p><a class="post-section-overview" href="#heading-limitations-of-css-grid">Limitations of CSS Grid</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-build-a-products-section-with-subgrid">How to Build a Products Section with Subgrid</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-does-subgrid-work">How Does Subgrid Work?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-use-subgrid">How to Use Subgrid</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-subgrid-in-browser-devtools">Subgrid in Browser DevTools</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></p>
</li>
</ul>
<h2 id="heading-limitations-of-css-grid">Limitations of CSS Grid</h2>
<p>Adding a display of Grid to a container means that only the direct children become grids. If these direct children also have children, they are not a part of the main grid – so they display in their normal flow.</p>
<p>This is problematic because without a direct link to one another, each will take up the space it needs and not care about its siblings. This leads to misaligned content you can see on the left of the image below.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724192748056/e6d99008-5a04-4a83-927d-0d46be2e17a5.png" alt="An image showing an example grid with and without subgrid" class="image--center mx-auto" width="1875" height="684" loading="lazy"></p>
<p>The project we'll build explores a Subgrid solution in a few lines of CSS code that will help us achieve the desired alignment seen on the right of the image above.</p>
<h2 id="heading-how-to-build-a-products-section-with-subgrid">How to Build a Products Section with Subgrid</h2>
<h3 id="heading-what-were-going-to-build">What We’re Going to Build</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724225971840/767e1b9e-bd54-4505-b3ad-2c39901b28c3.png" alt="An image of the final project to be built in this tutorial" class="image--center mx-auto" width="2074" height="1275" loading="lazy"></p>
<p>Check it out on <a target="_blank" href="https://codepen.io/ophyboamah/pen/OJevpQP">Codepen</a>.</p>
<h3 id="heading-prerequisites">Prerequisites</h3>
<ul>
<li><p>Basic knowledge of HTML and CSS (For a refresher on how CSS Grid works, check out <a target="_blank" href="https://www.freecodecamp.org/news/web-layouts-use-css-grid-and-flex-to-create-responsive-webpages/">my previous article on Web Layouts</a>)</p>
</li>
<li><p>An IDE (text editor)</p>
</li>
<li><p>A web browser</p>
</li>
</ul>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Since the focus of this article is Subgrid, we won't place a lot of emphasis on the starting HTML and CSS code. We'll just go through quickly first so you can set up. Then we'll dive into learning how to add Subgrid.</div>
</div>

<h3 id="heading-html-code">HTML Code:</h3>
<p>In our <code>index.html</code> file, we'll create the basic structure of the project which includes linking our CSS file and Google Fonts – all within the <code>&lt;head&gt;</code> tag. Within the <code>&lt;body&gt;</code> tag, we'll create a main container to house all the cards. Next, we'll create three individual cards as articles – each with an icon, title, text and button.</p>
<pre><code class="lang-xml"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"icon"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"image/png"</span> <span class="hljs-attr">sizes</span>=<span class="hljs-string">"32x32"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"./images/favicon-32x32.png"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"preconnect"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://fonts.googleapis.com"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"preconnect"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://fonts.gstatic.com"</span> <span class="hljs-attr">crossorigin</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">link</span>
    <span class="hljs-attr">href</span>=<span class="hljs-string">"https://fonts.googleapis.com/css2?family=Inter:wght@100..900&amp;family=Lexend+Deca:wght@100..900&amp;display=swap"</span>
    <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">link</span>
    <span class="hljs-attr">href</span>=<span class="hljs-string">"https://fonts.googleapis.com/css2?family=Big+Shoulders+Display:wght@100..900&amp;family=Inter:wght@100..900&amp;family=Lexend+Deca:wght@100..900&amp;display=swap"</span>
    <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"style.css"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Ophy's Subgrid Products Cards<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"cards-container"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">article</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"sedans"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./assets/icon-sedans.svg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"an icon showing a sedan vehicle"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>Sedans<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
        Choose a sedan for its affordability and excellent fuel economy. Ideal for cruising in the city
        or on your next road trip in and out of town - let your imaginations run.
      <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>
        Learn more
      <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">article</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">article</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"suvs"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./assets/icon-suvs.svg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"an icon showing an suv vehicle"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>SUVs<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
        Take an SUV for its spacious interior, power, and versatility.
      <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>
        Learn more
      <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">article</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">article</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"luxury"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./assets/icon-luxury.svg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"an icon showing a luxury vehicle"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>
        Extremely Luxurious
      <span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
        Cruise in the best car brands without the bloated prices. Enjoy the enhanced comfort of a luxury
        rental and arrive in style.
      <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>
        Learn more
      <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">article</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">footer</span>&gt;</span>
      Ophy's Subgrid Products Cards | <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://www.frontendmentor.io/"</span>&gt;</span>Design from Frontend Mentor <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">footer</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<h3 id="heading-css-code">CSS Code:</h3>
<p>In our <code>style.css</code> file, we'll first set our global and base styles:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Global Resets */</span>
* {
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">box-sizing</span>: border-box;
}

<span class="hljs-comment">/* Root Variables */</span>
<span class="hljs-selector-pseudo">:root</span> {
  <span class="hljs-attribute">--primary-font</span>: <span class="hljs-string">"Lexend Deca"</span>, sans-serif;
  <span class="hljs-attribute">--secondary-font</span>: <span class="hljs-string">"Big Shoulders Display"</span>, sans-serif;
  <span class="hljs-attribute">--heading-color</span>: <span class="hljs-number">#F2F2F2</span>;
  <span class="hljs-attribute">--font-color</span>: <span class="hljs-number">#FFF</span>;
  <span class="hljs-attribute">--sedans-background</span>: <span class="hljs-number">#E28625</span>;
  <span class="hljs-attribute">--suv-background</span>: <span class="hljs-number">#006971</span>;
  <span class="hljs-attribute">--luxury-background</span>: <span class="hljs-number">#004140</span>;
  <span class="hljs-attribute">--heading-font-size</span>: <span class="hljs-number">2.5rem</span>;
  <span class="hljs-attribute">--button-font-size</span>: <span class="hljs-number">0.9rem</span>;
  <span class="hljs-attribute">--default-padding</span>: <span class="hljs-number">1rem</span> <span class="hljs-number">0</span>;
}

<span class="hljs-comment">/* Base Styles */</span>
<span class="hljs-selector-tag">html</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">16px</span>;
}

<span class="hljs-selector-tag">body</span> {
  <span class="hljs-attribute">font-family</span>: <span class="hljs-built_in">var</span>(--primary-font);
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> auto;
  <span class="hljs-attribute">max-width</span>: <span class="hljs-number">920px</span>;
}

<span class="hljs-comment">/* Heading Styles */</span>
<span class="hljs-selector-tag">h3</span> {
  <span class="hljs-attribute">font-family</span>: <span class="hljs-built_in">var</span>(--secondary-font);
  <span class="hljs-attribute">color</span>: <span class="hljs-built_in">var</span>(--heading-color);
  <span class="hljs-attribute">font-size</span>: <span class="hljs-built_in">var</span>(--heading-font-size);
}
<span class="hljs-comment">/* Paragraph Styles */</span>
<span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">font-family</span>: <span class="hljs-built_in">var</span>(--primary-font);
  <span class="hljs-attribute">font-optical-sizing</span>: auto;
  <span class="hljs-attribute">font-weight</span>: <span class="hljs-number">200</span>; 
  <span class="hljs-attribute">color</span>: <span class="hljs-built_in">var</span>(--font-color);
  <span class="hljs-attribute">padding</span>: <span class="hljs-built_in">var</span>(--default-padding);
  <span class="hljs-attribute">line-height</span>: <span class="hljs-number">1.5</span>;
}
<span class="hljs-comment">/*  Footer  */</span>
  <span class="hljs-selector-tag">footer</span> {
    <span class="hljs-attribute">text-align</span>: center;
    <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">1.5rem</span>;
    a {
      <span class="hljs-attribute">text-decoration</span>: none;
    }
  }
</code></pre>
<p>Next, we'll style the main cards container and button. Note that we've specified columns and rows for the cards container using <code>grid-template-columns</code> and <code>grid-template-rows</code>, respectively.</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Container */</span>
<span class="hljs-selector-class">.cards-container</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(auto-fit, minmax(<span class="hljs-number">300px</span>, <span class="hljs-number">1</span>fr));
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">4</span>, auto);
  <span class="hljs-attribute">min-height</span>: <span class="hljs-number">31.25rem</span>;
  <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">10.688rem</span>;
  button {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-built_in">var</span>(--button-font-size);
    <span class="hljs-attribute">background</span>: <span class="hljs-built_in">var</span>(--font-color);
    <span class="hljs-attribute">border</span>: none;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">0.5rem</span> <span class="hljs-number">1.5rem</span>;
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">25px</span>;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">70%</span>;
    &amp;:hover {
      <span class="hljs-attribute">cursor</span>: pointer;
      <span class="hljs-attribute">background</span>: none;
      <span class="hljs-attribute">color</span>: <span class="hljs-built_in">var</span>(--font-color);
      <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid <span class="hljs-built_in">var</span>(--font-color);
    }
}
</code></pre>
<p>Then we'll create general card styles as well as individual card styles.</p>
<pre><code class="lang-css"><span class="hljs-comment">/* All */</span>
<span class="hljs-selector-class">.suvs</span>,
<span class="hljs-selector-class">.sedans</span>,
<span class="hljs-selector-class">.luxury</span> {
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">3rem</span>;
  h3 {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-built_in">var</span>(--heading-font-size);
    <span class="hljs-attribute">text-transform</span>: uppercase;
  }
}
<span class="hljs-comment">/* Sedans */</span>
<span class="hljs-selector-class">.sedans</span> {
  <span class="hljs-attribute">background-color</span>: <span class="hljs-built_in">var</span>(--sedans-background);
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">10px</span> <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">10px</span>;
  button {
    <span class="hljs-attribute">color</span>: <span class="hljs-built_in">var</span>(--sedans-background);
  }
}
<span class="hljs-comment">/* SUV */</span>
<span class="hljs-selector-class">.suvs</span> {
  <span class="hljs-attribute">background-color</span>: <span class="hljs-built_in">var</span>(--suv-background);
  button {
    <span class="hljs-attribute">color</span>: <span class="hljs-built_in">var</span>(--suv-background);
  }
}
<span class="hljs-comment">/* Luxury */</span>
<span class="hljs-selector-class">.luxury</span> {
  <span class="hljs-attribute">background-color</span>: <span class="hljs-built_in">var</span>(--luxury-background);
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">0</span> <span class="hljs-number">10px</span> <span class="hljs-number">10px</span> <span class="hljs-number">0</span>;
  button {
    <span class="hljs-attribute">color</span>: <span class="hljs-built_in">var</span>(--luxury-background);
  }
}
</code></pre>
<p>The image below will be the result after running the above starter code. The cards have been created as grid columns but the rows within the individual cards are not aligning properly due to the difference in content length.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724176252090/b3540574-6779-4486-8622-fbf8fe8e9a09.png" alt="An image of the products cards without Subgrid" class="image--center mx-auto" width="2136" height="1340" loading="lazy"></p>
<h2 id="heading-how-does-subgrid-work">How Does Subgrid Work?</h2>
<p>The display above will be a nightmare for designers and stakeholders until it's fixed. In the past, to fix this, developers needed to make these cards into nested grids. But that code will eventually become messy and difficult to maintain.</p>
<p>CSS Subgrid allows a grid item to inherit the grid tracks (rows or columns) of its parent grid, rather than defining its own. This is particularly useful for maintaining consistent alignment between nested grids and their parent grids.</p>
<p>In our project, instead of defining a row for the icons, titles, text and buttons, we can make them inherit the same from their parent grid (the cards container).</p>
<h2 id="heading-how-to-use-subgrid">How to Use Subgrid</h2>
<p>To create a <code>subgrid</code>, assign the keyword as a value to either a <code>grid-template-columns</code> or a <code>grid-template-rows</code> of a nested grid.</p>
<p>To implement this in our project, we'll first turn the article element into a grid container in order to place its children in a structured grid. Next, <code>grid-template-rows</code> is given a value of <code>subgrid</code>. This inherits the row structure from the cards container grid.</p>
<p>Setting <code>grid-row</code> to <code>span 4</code> basically means the element should occupy a space that covers 4 rows of the parent grid.</p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">article</span> {
    <span class="hljs-attribute">display</span>: grid;
    <span class="hljs-attribute">grid-template-rows</span>: subgrid;
    <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">4</span>;
}
</code></pre>
<h3 id="heading-optional-code">Optional Code</h3>
<p>The code below for positioning elements with <code>grid-row</code> is not necessary in this project since we're using Subgrid correctly. But it may come in handy for more complex layouts when you want explicit control over the placement of each element within the grid.</p>
<pre><code class="lang-css">    <span class="hljs-selector-tag">img</span> {
      <span class="hljs-attribute">grid-row</span>: <span class="hljs-number">1</span>/<span class="hljs-number">2</span>;
    }

    <span class="hljs-selector-tag">h3</span> {
      <span class="hljs-attribute">grid-row</span>: <span class="hljs-number">2</span>/<span class="hljs-number">3</span>;
    }

    <span class="hljs-selector-tag">p</span> {
      <span class="hljs-attribute">grid-row</span>: <span class="hljs-number">3</span>/<span class="hljs-number">4</span>;
    }

    <span class="hljs-selector-tag">button</span> {
      <span class="hljs-attribute">grid-row</span>: <span class="hljs-number">4</span>/<span class="hljs-number">5</span>;
    }
</code></pre>
<p>Once <code>subgrid</code> is applied, our cards should be perfectly aligned as shown in the image below. This alignment occurs because the child elements within each card (like titles, paragraphs, and buttons) now share the same grid structure, inherited from the parent. They are "aware" of each other and automatically adjust their positions to stay in sync.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724182833885/5d985d19-d203-4bd3-a5b2-afbf0f060fa9.png" alt="An image of the products cards aligned using subgrid" class="image--center mx-auto" width="2161" height="1272" loading="lazy"></p>
<p>For example, even if the titles for Sedans and SUVs are shorter, the grid ensures that their paragraphs and buttons start in the same rows, maintaining consistency across all cards. This leads to a cleaner, more organized layout, where each element is aligned regardless of varying content lengths.</p>
<h2 id="heading-subgrid-in-browser-devtools">Subgrid in Browser DevTools</h2>
<p>In any modern browser, right-click on the project webpage and select inspect from the list of options. Or use the shortcut (command + option + I on Mac or control + shift + I on Windows) to open the Elements tab of DevTools.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724164230096/01861ffd-27a3-4394-bf96-fefcedd890f2.png" alt="An image of an inspected subgrid in Chrome DevTools" class="image--center mx-auto" width="2257" height="1371" loading="lazy"></p>
<p>As you can see in the image above, just like we have for grid, Subgrid also has a badge. Toggle it to inspect or debug a Subgrid. It toggles an overlay that shows columns, rows, and their numbers on top of the element in the viewport.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Subgrid is a helpful tool for aligning layouts – something you had to do manually in the past. Now, nested grids can inherit properties such as rows and columns from their parent grids. This extends the abilities of CSS Grid to create consistent and perfectly aligned designs.</p>
<p>If you're ever tempted to create an unending loop of CSS grids just to get a design with differently sized content to align perfectly – instead, reach for CSS Subgrid to make your code cleaner and easier to manage.</p>
<p>Here are some helpful resources:</p>
<ul>
<li><p><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_grid_layout/Subgrid">MDN on CSS Subgrid</a></p>
</li>
<li><p><a target="_blank" href="https://www.youtube.com/watch?v=Yl8hg2FG20Q">Learn CSS Subgrid</a></p>
</li>
<li><p><a target="_blank" href="https://web.dev/articles/css-subgrid">Web Dev on CSS Subgrid</a></p>
</li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
