PageSourceSearch

https://www.frontendreference.com/flexbox-vs-grid.html

html frontendreference.com collected 2026-09-26 14:57:34 UTC 8,411 bytes, 9 lines download raw bytes

1<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width"><title>Flexbox Vs. Grid: Understanding the Differences </title> <meta name="description" content="Learn what developer experience is and why it's so important to the web development process. "> <meta property="og:title" content="Flexbox Vs. Grid: Understanding the Differences "/> <meta property="og:type" content="website"/> <meta property="og:image" content="https://www.frontendreference.com/assets/images/og.png"/> <meta property="og:site_name" content="Front-end Reference"/> <meta property="og:description" content="Learn what developer experience is and why it's so important to the web development process. "/> <meta property="og:url" content="https://www.frontendreference.com/flexbox-vs-grid.html"/> <meta name="theme-color" content="#000000"><meta property="article:published_time" content="2023-05-11 14:16:00 +0000"/><meta property="article:modified_time" content="2023-05-12 03:45:03 +0000"/><link rel="stylesheet" type="text/css" href="/assets/css/main.css?v=1759294443670556731"> <link rel="canonical" href="https://www.frontendreference.com/flexbox-vs-grid.html">
vendor: 64 bytes, line 1
1 <script async src="https://www.googletagmanager.com/gtag/js?id=
1G-SE1RDCMJ1D
vendor: 12 bytes, line 1
1"></script> 
1<script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","G-SE1RDCMJ1D");</script>
1 </head> <body class=""> <main class="max-w-3xl px-20 mx-auto py-30 md:px-40 md:py-60"> <div class="border-b pb-30"> <div class="flex items-center"> <a href="/" class="block font-bold no-underline">Learn the Front-end</a> <span class="table py-5 ml-10 text-xs leading-none tracking-wider text-gray-600 uppercase border rounded-full px-15">Beta</span> <a class="flex items-center gap-1 ml-auto" href="/search.html"> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" width="20px" height="20px"> <path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z"/> </svg> <span class="block">Search</span> </a> </div> </div> <div class="mt-40 md:mt-60 lg:mt-80"> <section> <header class="pr-40 lg:text-xl lg:pr-0"> <h1 class="text-4xl font-bold">Flexbox Vs. Grid: Understanding the Differences</h1> <div class="flex items-center mt-30"> <img src="/assets/images/dangold.jpg" alt="Dan Gold" width="40" height="40" class="block mr-10 rounded-full"> <p class="text-base">Written by Dan</p> </div> </header> <article class="text-xl prose mt-60 post-content"> <p>CSS is a powerful language for designing and building layouts in web development. Among its various features, <a href="/css/flex.html">Flexbox</a> and <a href="/css/grid.html">CSS Grid</a> are two layout models that have revolutionized the way we design web interfaces. In this post, we will discuss the differences between Flexbox and Grid, their advantages, and when to use each one.</p> <h2 id="introduction-to-flexbox">Introduction to Flexbox</h2> <p>Flexbox, or Flexible Box Module, is a one-dimensional layout model. It’s a way to lay out items in a container and change their alignment, direction, order, and size to best fill available space.</p> <p><strong>Here’s an example of a basic flex container:</strong></p> <div class="language-css highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nc">.container</span> <span class="p">{</span>
2  <span class="nl">display</span><span class="p">:</span> <span class="n">flex</span><span class="p">;</span>
3<span class="p">}</span>
4</code></pre></div></div> <p>With this simple declaration, child elements of <code class="language-plaintext highlighter-rouge">.container</code> will lay out in a row from left to right.</p> <h2 id="introduction-to-grid">Introduction to Grid</h2> <p>CSS Grid, on the other hand, is a two-dimensional layout system. It’s meant for laying out content in rows and columns at the same time. You can control the widths of columns and the heights of rows, something you can’t do with Flexbox.</p> <p>Here’s an example of a basic grid container:</p> <div class="language-css highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nc">.container</span> <span class="p">{</span>
5  <span class="nl">display</span><span class="p">:</span> <span class="n">grid</span><span class="p">;</span>
6  <span class="py">grid-template-columns</span><span class="p">:</span> <span class="nb">repeat</span><span class="p">(</span><span class="m">3</span><span class="p">,</span> <span class="m">1</span><span class="n">fr</span><span class="p">);</span>
7  <span class="py">grid-template-rows</span><span class="p">:</span> <span class="nb">repeat</span><span class="p">(</span><span class="m">3</span><span class="p">,</span> <span class="m">1</span><span class="n">fr</span><span class="p">);</span>
8<span class="p">}</span>
9</code></pre></div></div> <p>This grid container will have 3 equally sized columns and 3 equally sized rows.</p> <h2 id="main-differences">Main Differences</h2> <p>Here are the differences and the things that make each of these CSS properties unique.</p> <h3 id="dimension">Dimension</h3> <p>The primary difference between Flexbox and Grid lies in their dimension. Flexbox is primarily for one-dimensional layouts - either a row or a column. Grid is for two-dimensional layouts, where both rows and columns might be of concern.</p> <p>
9The application in which you’d use these properties depends mostly on your content.</p> <h3 id="content-driven-vs-container-driven">Content-Driven vs. Container-Driven</h3> <p>Flexbox is content-driven. This means it best serves when the size of the content or the number of items will dictate the final layout.</p> <p>Grid is container-driven. It is more suited to laying out a larger scale layout where the placement and proportion of the grid and items are known ahead of time.</p> <h3 id="alignment">Alignment</h3> <p>Both Flexbox and Grid offer a variety of alignment capabilities. However, because Grid is two-dimensional, it provides more alignment options and can handle both columns and rows simultaneously, which can’t be done with Flexbox.</p> </article> </section> <div class="mx-auto max-w-article mt-90"> <p class="mb-5 text-xs font-bold tracking-wider text-gray-800 uppercase">Last updated</p> <p class="mt-0 text-gray-600">May 12th, 2023</p> </div> </div> </main> <footer class="max-w-3xl px-20 mx-auto py-30"> <nav class="border-t md:flex md:flex-1 md:gap-4 pt-30"> <a class="block" href="/">Home</a> <a class="block" href="/blog.html">Blog</a> <a class="block" href="/css/">CSS Properties</a> <a class="block" href="/html-elements/">HTML Elements</a> <a class="block" href="/tailwind-css/">Tailwind CSS</a> <a class="block" href="/resources.html">Resources</a> <a class="block" href="/jobs/">Jobs</a> <a class="block ml-auto" href="/jobs/submit.html">Submit a job</a> </nav> </footer> 
9<script>const imgElements=document.querySelectorAll(".random-unsplash-image");imgElements.forEach(e=>{const t=e.getAttribute("width")||1e3,r=e.getAttribute("height")||1e3;fetch(`/.netlify/functions/unsplash-images?width=${t}&height=${r}&query=random`).then(e=>e.json()).then(t=>{if(t.error)throw new Error(t.error);const r=document.createElement("div");e.src=t.imageUrl;const n=e.cloneNode(!0);r.appendChild(n),r.classList.add("relative");const o=document.createElement("p");o.classList.add("unsplash-photo-attribution"),o.innerHTML=`\n              Photo by <a href="${t.photographer.link}" target="_blank">${t.photographer.name}</a> on <a href="${t.unsplashLink}" target="_blank">Unsplash</a>\n            `,r.appendChild(o),e.replaceWith(r),fetch(t.downloadUrl)["catch"](e=>console.error("Error triggering download:",e))})["catch"](e=>console.error("Error fetching image:",e))});</script>
9 
9<script data-grow-initializer="">!function(){window.growMe||(window.growMe=function(e){window.growMe._.push(e)},window.growMe._=[]);var e=document.createElement("script");e.type="text/javascript",e.src="https://faves.grow.me/main.js",e.defer=!0,e.setAttribute("data-grow-faves-site-id","U2l0ZTowNzlmZmJiNy1kNzFjLTQ3ZDctYTJmNS1kY2QwMWU1OTc3NTE=");var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}();</script>
9 </body> </html>

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.