<?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" version="2.0"><channel><title><![CDATA[CSS flex&gird layout]]></title><description><![CDATA[CSS flex&gird layout]]></description><link>https://css-flexandgird-layout.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 01 Sep 2026 16:50:33 GMT</lastBuildDate><atom:link href="https://css-flexandgird-layout.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[CSS Grid and flex box]]></title><description><![CDATA[CSS Grid arranges items in rows and columns (2-Dimension), while Flexbox aligns items in a single row or column (1-Dimension).
CSS Grid Layout
CSS Grid Layout, is a two-dimensional grid-based layout system with rows and columns. It makes easier to de...]]></description><link>https://css-flexandgird-layout.hashnode.dev/css-grid-and-flex-box</link><guid isPermaLink="true">https://css-flexandgird-layout.hashnode.dev/css-grid-and-flex-box</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[CSS]]></category><category><![CDATA[flexbox]]></category><category><![CDATA[grid]]></category><dc:creator><![CDATA[Ashu Suhail]]></dc:creator><pubDate>Mon, 05 May 2025 11:55:37 GMT</pubDate><content:encoded><![CDATA[<p>CSS Grid arranges items in rows and columns (2-Dimension), while Flexbox aligns items in a single row or column (1-Dimension).</p>
<h2 id="heading-css-grid-layout"><strong>CSS Grid Layout</strong></h2>
<p>CSS <a target="_blank" href="https://www.geeksforgeeks.org/css-grid-property/"><strong>Grid Layout</strong></a>, is a two-dimensional grid-based layout system with rows and columns. It makes easier to design web pages without having to use floats and positioning. Like tables, grid layout allow us to align elements into columns and rows.</p>
<p>To get started, you have to define a container element as a grid with <a target="_blank" href="https://www.geeksforgeeks.org/css-grid-property/"><strong>display: grid</strong></a><strong>,</strong> set the column and row sizes with grid-template-columns and grid-template-rows, and then place its child elements into the grid with grid-column and grid-row.</p>
<pre><code class="lang-plaintext">&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;

&lt;head&gt;
    &lt;style&gt;
        .main{
            display: grid; 
            grid: auto auto / auto auto auto auto; 
            grid-gap: 10px; 
            background-color: green; 
            padding: 10px; 
        }
        .gfg { 
            background-color: rgb(255, 255, 255); 
            text-align: center; 
            padding: 25px 0; 
            font-size: 30px; 
        } 
    &lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;h2 style="text-align: center;"&gt;
          Welcome To GeeksForGeeks
      &lt;/h2&gt;
    &lt;div class="main"&gt;
        &lt;div class="gfg"&gt;Home&lt;/div&gt;
        &lt;div class="gfg"&gt;Read&lt;/div&gt;
        &lt;div class="gfg"&gt;Write&lt;/div&gt;
        &lt;div class="gfg"&gt;About Us&lt;/div&gt;
        &lt;div class="gfg"&gt;Contact Us&lt;/div&gt;
        &lt;div class="gfg"&gt;Privacy Policy&lt;/div&gt;
    &lt;/div&gt;
&lt;/body&gt;

&lt;/html&gt;
</code></pre>
<p><strong>Output</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746444693445/a1b0de92-c196-4668-b7c8-7759635cd54f.png" alt class="image--center mx-auto" /></p>
<h1 id="heading-css-grid-property">CSS grid Property</h1>
<p>It is a CSS property that offers a grid-based layout system, with rows and columns, making it easier to design web pages without floats and positioning. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746445311547/6be83b79-535b-4460-91ea-9114095f044b.png" alt class="image--center mx-auto" /></p>
<p><strong>Syntax :</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746445545154/ccc95bd7-87c5-4d2e-939b-850de743724a.png" alt class="image--center mx-auto" /></p>
<p><strong>Property values:</strong></p>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Value</strong></td><td><strong>Description</strong></td></tr>
</thead>
<tbody>
<tr>
<td>none</td><td>It is default value no specific size mentioned for row and column.</td></tr>
<tr>
<td>grid-template-rows / grid-template-columns</td><td>It is used to specifies the size of rows and columns.</td></tr>
<tr>
<td>grid-template-areas</td><td>It is used to specifies the grid layout using named items.</td></tr>
<tr>
<td>grid-template-rows / grid-auto-columns</td><td>It is used to specifies the auto size(height) and sets the auto size columns.</td></tr>
<tr>
<td>grid-auto-rows / grid-template-columns</td><td>It is used to specifies the auto size and sets the auto grid size columns.</td></tr>
<tr>
<td>grid-template-rows / grid-auto-flow grid-auto-columns</td><td>It is used to specifies how to place items and auto size row and columns.</td></tr>
<tr>
<td>grid-auto-flow grid-auto-rows / grid-template-columns</td><td>It is used to specifies how to place items and auto size row and grid-template columns.</td></tr>
</tbody>
</table>
</div><p><strong>Example 1:</strong> Grid with 2-rows and 4-column. </p>
<pre><code class="lang-plaintext">&lt;!DOCTYPE html&gt; 
&lt;html&gt; 

&lt;head&gt; 
    &lt;title&gt; 
        CSS | grid Property 
    &lt;/title&gt; 
    &lt;style&gt; 
        .main { 
            display: grid; 
            grid: auto auto / auto auto auto auto; 
            grid-gap: 10px; 
            background-color: green; 
            padding: 10px; 
        } 

        .gfg { 
            background-color: lightgrey; 
            text-align: center; 
            padding: 25px 0; 
            font-size: 30px; 
        } 
    &lt;/style&gt; 
&lt;/head&gt; 

&lt;body&gt; 

    &lt;h1&gt;Welcome to GFG &lt;/h1&gt; 
    &lt;h3&gt;This tutorial is on CSS grid property&lt;/h3&gt; 

    &lt;div class="main"&gt; 
        &lt;div class="gfg"&gt;1&lt;/div&gt; 
        &lt;div class="gfg"&gt;2&lt;/div&gt; 
        &lt;div class="gfg"&gt;3&lt;/div&gt; 
        &lt;div class="gfg"&gt;4&lt;/div&gt; 
        &lt;div class="gfg"&gt;5&lt;/div&gt; 
        &lt;div class="gfg"&gt;6&lt;/div&gt; 
        &lt;div class="gfg"&gt;7&lt;/div&gt; 
        &lt;div class="gfg"&gt;8&lt;/div&gt; 
    &lt;/div&gt; 

&lt;/body&gt; 

&lt;/html&gt;
</code></pre>
<p><strong>Output :</strong> </p>
<p><img src="https://media.geeksforgeeks.org/wp-content/uploads/output-299.png" alt class="image--center mx-auto" /></p>
<p><strong>This can be used as a shorthand property for :</strong> </p>
<ul>
<li><p><strong>grid-template-rows :</strong> Specifies the size of the rows.</p>
</li>
<li><p><strong>grid-template-columns :</strong> This specifies the size of the columns.</p>
</li>
<li><p><strong>grid-template-areas :</strong> This specifies the grid layout using named items.</p>
</li>
<li><p><strong>grid-auto-rows :</strong> This specifies the auto size of the rows.</p>
</li>
<li><p><strong>grid-auto-columns :</strong> This specifies the auto size of the columns.</p>
</li>
<li><p><strong>grid-auto-flow :</strong> This specifies how to place auto-placed items, and the auto size of the row.</p>
</li>
</ul>
<p><strong>Example 2:</strong> This is example for the <strong>grid-template-rows</strong> and <strong>grid-template-columns</strong>. </p>
<pre><code class="lang-plaintext">&lt;!DOCTYPE html&gt; 
&lt;html&gt; 

&lt;head&gt; 
    &lt;title&gt; 
        CSS | grid Property 
    &lt;/title&gt; 
    &lt;style&gt; 
        .main { 
            display: grid; 
            grid-template-columns: 156px 156px 156px 156px; 
            grid-template-rows: 100px 200px; 
            grid-gap: 5px; 
            background-color: green; 
            padding: 5px; 
        } 

        .gfg { 
            background-color: lightgrey; 
            text-align: center; 
            padding: 20px 0; 
            font-size: 30px; 
        } 
    &lt;/style&gt; 
&lt;/head&gt; 

&lt;body&gt; 
    &lt;h1&gt;Welcome to GFG &lt;/h1&gt; 
    &lt;h3&gt;This tutorial is on CSS grid property&lt;/h3&gt; 

    &lt;div class="main"&gt; 
        &lt;div class="gfg"&gt;1&lt;/div&gt; 
        &lt;div class="gfg"&gt;2&lt;/div&gt; 
        &lt;div class="gfg"&gt;3&lt;/div&gt; 
        &lt;div class="gfg"&gt;4&lt;/div&gt; 
        &lt;div class="gfg"&gt;5&lt;/div&gt; 
        &lt;div class="gfg"&gt;6&lt;/div&gt; 
        &lt;div class="gfg"&gt;7&lt;/div&gt; 
        &lt;div class="gfg"&gt;8&lt;/div&gt; 
    &lt;/div&gt; 

&lt;/body&gt; 

&lt;/html&gt;
</code></pre>
<p><strong>Output :</strong> Height of the first row is set to <strong>100px</strong> and height of the second row is set to <strong>200px</strong> and width of every column is set to <strong>156px</strong>. </p>
<p><img src="https://media.geeksforgeeks.org/wp-content/uploads/output-301.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-css-flexbox"><strong>CSS Flexbox</strong></h2>
<p>The <a target="_blank" href="https://www.geeksforgeeks.org/introduction-to-css-flexbox/"><strong>CSS Flexbox</strong></a> offers one-dimensional layout. It is helpful in allocating and aligning the space among items in a container (made of grids). It works with all kinds of display devices and screen sizes. To get started you have to define a container element as a grid with <a target="_blank" href="https://www.geeksforgeeks.org/introduction-to-css-flexbox/"><strong>display: flex</strong></a><strong>;</strong></p>
<pre><code class="lang-plaintext">&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;

&lt;head&gt;
    &lt;style&gt;
        .main{
            display: flex; 
            grid: auto auto / auto auto auto auto; 
            grid-gap: 10px; 
            background-color: green; 
            padding: 10px; 
        }
        .gfg { 
            background-color: rgb(255, 255, 255); 
            text-align: center; 
            padding: 25px 0; 
            font-size: 30px; 
        } 
    &lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;h2 style="text-align: center;"&gt;
          Welcome To GeeksForGeeks
      &lt;/h2&gt;
    &lt;div class="main"&gt;
        &lt;div class="gfg"&gt;Home&lt;/div&gt;
        &lt;div class="gfg"&gt;Read&lt;/div&gt;
        &lt;div class="gfg"&gt;Write&lt;/div&gt;
        &lt;div class="gfg"&gt;About Us&lt;/div&gt;
        &lt;div class="gfg"&gt;Contact Us&lt;/div&gt;
        &lt;div class="gfg"&gt;Privacy Policy&lt;/div&gt;
    &lt;/div&gt;
&lt;/body&gt;

&lt;/html&gt;
</code></pre>
<p><strong>Output</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746445906598/d0a5cc32-1cad-48f7-9d57-40a3eecf13ee.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-difference-between-css-grid-and-flexbox"><strong>Difference Between CSS Grid and Flexbox</strong></h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Property</strong></td><td><strong>Grid</strong></td><td><strong>Flexbox</strong></td></tr>
</thead>
<tbody>
<tr>
<td>Dimension</td><td>Two – Dimensional</td><td>One – Dimensional</td></tr>
<tr>
<td>Features</td><td>Can flex combination of items through space-occupying Features</td><td>Can push content element to extreme alignment</td></tr>
<tr>
<td>Support Type</td><td>Layout First</td><td>Content First</td></tr>
<tr>
<td>Primary Use Case</td><td>Creating complex layouts with rows and columns</td><td>Aligning items in a row or column</td></tr>
<tr>
<td>Performance</td><td>Can be less in performance due to very complex grids</td><td>Generally faster for simple layouts</td></tr>
</tbody>
</table>
</div><p><strong>CSS Flexbox</strong>, short for the Flexible Box Layout module, is a powerful layout tool designed to simplify web page layouts by arranging items in rows or columns with ease.</p>
<ul>
<li><p>Flexbox eliminates the need for floats or complex positioning, enabling responsive and dynamic layouts.</p>
</li>
<li><p>It aligns items efficiently, distributing space within a container, even when their sizes are dynamic or unknown.</p>
</li>
<li><p>Flexbox is supported in all modern browsers, making it a reliable choice for creating flexible designs.</p>
</li>
</ul>
<h2 id="heading-what-is-css-flexbox">What is CSS Flexbox?</h2>
<p>The Flexible Box Layout module introduces a one-dimensional layout system that handles space distribution and item alignment effectively. It works seamlessly for horizontal (row) or vertical (column) arrangements, making it a go-to solution for responsive designs.</p>
<h3 id="heading-key-features-of-css-flexbox">Key Features of CSS Flexbox</h3>
<ul>
<li><p><strong>Alignment:</strong> Easily aligns items along the main axis (row/column) or cross-axis (perpendicular direction).</p>
</li>
<li><p><strong>Space Distribution:</strong> Distributes space among items or gaps dynamically within a container.</p>
</li>
<li><p><strong>Responsive Design</strong>: Adapts to screen sizes without extra effort, perfect for modern web layouts.</p>
</li>
</ul>
]]></content:encoded></item></channel></rss>