<?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: locionic</title>
    <description>The latest articles on DEV Community by locionic (@locionic).</description>
    <link>https://dev.to/locionic</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%2F4115384%2F6103b0f7-04b3-4da9-a581-796574c35455.png</url>
      <title>DEV Community: locionic</title>
      <link>https://dev.to/locionic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/locionic"/>
    <language>en</language>
    <item>
      <title>I still see developers using Flexbox for grids (and why you should stop)</title>
      <dc:creator>locionic</dc:creator>
      <pubDate>Tue, 08 Sep 2026 09:30:19 +0000</pubDate>
      <link>https://dev.to/locionic/i-still-see-developers-using-flexbox-for-grids-and-why-you-should-stop-5bpl</link>
      <guid>https://dev.to/locionic/i-still-see-developers-using-flexbox-for-grids-and-why-you-should-stop-5bpl</guid>
      <description>&lt;p&gt;A few days ago, I reviewed a pull request with something like this:&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;.card&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="n"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;33.333%&lt;/span&gt; &lt;span class="n"&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="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.75rem&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;It "worked." Until someone added a 4th card, and it stretched all the way across the second row like a giant billboard. &lt;/p&gt;

&lt;p&gt;To fix that, the developer added an invisible dummy element at the end to balance the flex row. Then another media query to reset widths on tablet. Suddenly, a basic 3-column card grid was 45 lines of CSS and two weird DOM hacks.&lt;/p&gt;

&lt;p&gt;This happens all the time because most of us learned Flexbox first, got comfortable with it, and started treating it like a hammer for every layout nail.&lt;/p&gt;

&lt;p&gt;CSS Grid has been supported in 100% of modern browsers for over half a decade. You don't need to fight &lt;code&gt;flex-wrap&lt;/code&gt; and &lt;code&gt;calc()&lt;/code&gt; anymore.&lt;/p&gt;

&lt;p&gt;Here is how I actually decide between them in real production work.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Rule of Thumb: Content-Out vs. Layout-In
&lt;/h2&gt;

&lt;p&gt;You don't need a 20-page specification to decide. You only need to answer one question:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Who decides the sizing? The content, or the container?&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Flexbox is "Content-Out" (1D)
&lt;/h3&gt;

&lt;p&gt;In Flexbox, the items inside dictate how things look. A button with a long label gets wider. An icon sits snugly next to some text. The items push and flex along &lt;strong&gt;one axis at a time&lt;/strong&gt; (either a row or a column).&lt;/p&gt;

&lt;p&gt;Use Flexbox when you want items to flow naturally and distribute leftover space based on what’s inside them.&lt;/p&gt;

&lt;h3&gt;
  
  
  CSS Grid is "Layout-In" (2D)
&lt;/h3&gt;

&lt;p&gt;In Grid, the parent container holds all the power. You carve out rows and columns first, and whatever you drop inside has to conform to those slots.&lt;/p&gt;

&lt;p&gt;Use Grid when you want strict alignment across &lt;strong&gt;both rows AND columns&lt;/strong&gt;, regardless of what content is inside the cards.&lt;/p&gt;




&lt;h2&gt;
  
  
  Example 1: Where Flexbox is King (Navbars)
&lt;/h2&gt;

&lt;p&gt;Navbars are classic 1D layouts. You have a logo on the left, some links in the middle, and maybe an avatar or CTA button on the right.&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;header&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"navbar"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&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;"logo"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Acme&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;nav&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav-links"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/docs"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Docs&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/pricing"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Pricing&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/blog"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Blog&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&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;"btn-primary"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Sign in&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/header&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.navbar&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="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;space-between&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;gap&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="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.nav-links&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="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&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;Why Flexbox here?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"Docs" is shorter than "Pricing". We don't care about equal widths; we just want natural spacing between words.&lt;/li&gt;
&lt;li&gt;If the brand name changes, the layout doesn't break. The items flex according to their own size.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Trying to build this header with CSS Grid would force you into rigid columns you don't actually want.&lt;/p&gt;




&lt;h2&gt;
  
  
  Example 2: Where Grid Destroys Flexbox (Cards &amp;amp; Galleries)
&lt;/h2&gt;

&lt;p&gt;Now look at a product grid or photo gallery:&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;ul&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card-grid"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Card 1&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Card 2&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Card 3&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Card 4&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With Flexbox, you end up doing math: &lt;code&gt;calc(25% - gap)&lt;/code&gt; and babysitting the last row so orphans don't stretch.&lt;/p&gt;

&lt;p&gt;With Grid, it’s one declaration:&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;.card-grid&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="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;auto-fill&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;240px&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="py"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.25rem&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;Look at what this does:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Zero media queries:&lt;/strong&gt; On a phone (360px), it fits 1 column. On an iPad, 2 or 3 columns. On an ultrawide monitor, 5 columns. It adapts automatically.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No orphan stretching:&lt;/strong&gt; Card 4 stays in column 1 of row 2. It doesn't blow up to fill the whole screen.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Equal height rows for free:&lt;/strong&gt; If Card 2 has 4 lines of text and Card 1 has 1 line, both cards in that row automatically match height.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  The "Last Item" Test
&lt;/h2&gt;

&lt;p&gt;If you're ever stuck choosing, test what happens when your data count changes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you have 5 items in a 3-column layout:

&lt;ul&gt;
&lt;li&gt;Do you want items 4 &amp;amp; 5 to expand and split the bottom row evenly? &lt;strong&gt;Use Flexbox.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Do you want items 4 &amp;amp; 5 to stay the exact same width as items 1–3 and leave the 3rd spot empty? &lt;strong&gt;Use Grid.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;90% of the time, for dashboards, galleries, and product cards, you want the second behavior.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Real Best Practice: Nest Them
&lt;/h2&gt;

&lt;p&gt;You don't pick a team. You use both in the same component:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Grid for the skeleton:&lt;/strong&gt; The page layout, the sidebar/main content split, the product card grid.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexbox for the organs:&lt;/strong&gt; Inside the card (aligning an author avatar next to a timestamp), inside a button (centering an icon next to text).
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Outer skeleton: CSS Grid */&lt;/span&gt;
&lt;span class="nc"&gt;.dashboard-layout&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="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;260px&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;min-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Inner component detail: Flexbox */&lt;/span&gt;
&lt;span class="nc"&gt;.user-badge&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="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.5rem&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;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;Next time you catch yourself typing &lt;code&gt;calc()&lt;/code&gt; inside a &lt;code&gt;flex-basis&lt;/code&gt; or adding empty &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tags just to make items line up vertically, hit backspace. &lt;/p&gt;

&lt;p&gt;Define a grid on the parent, give it a &lt;code&gt;gap&lt;/code&gt;, and let the browser do the heavy lifting.&lt;/p&gt;

&lt;p&gt;What's your biggest layout pet peeve in CSS? Let me know in the comments!&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
