Using Materialize CSS’s Flexbox Grid for Responsive Layouts
Learn how Materialize CSS’s Flexbox‑based 12‑column grid lets you create responsive, equal‑height layouts with only breakpoint classes, and how to customize its gutter and column width via Sass.
27 Sept 2025, 09:50 UTC

Problem: Building a layout that adapts without writing custom media queries
When a UI must look good on phones, tablets, and desktops, writing separate CSS rules for each breakpoint quickly becomes tedious and error‑prone. Teams often need a reliable, opinionated grid that handles column widths, offsets, and vertical alignment out of the box.
Thesis: Materialize CSS’s 12‑column Flexbox grid solves this by offering breakpoint‑specific classes that produce fluid, equal‑height rows with minimal HTML changes.
1. How the grid works
Materialize CSS (v1.0.0+) builds its grid on Flexbox. The container .row becomes a flex container, and direct children that receive column classes (.col, .s1‑s12, .m1‑m12, .l1‑l12) become flex items. The framework defines three breakpoints:
- Small (
s):<600px - Medium (
m):600px‑992px - Large (
l):≥992px
You can combine classes to specify different widths at each breakpoint, e.g., .s12 .m6 .l4 means “full width on small, half on medium, one‑third on large”.
2. Offsets, push, and pull
Sometimes you need to shift a column without changing the source order. Modifiers .offset‑s2, .push‑m3, and .pull‑l4 add left margin or change the flex order using margin-left and order properties. Because they rely on Flexbox, the shifted column still participates in equal‑height row calculations.
3. Worked example: three‑column card layout that stacks
Assume you want a row of cards that shows three columns on desktop, two on tablet, and one on phone. The following markup uses only Materialize classes:
<div class="row">
<div class="col s12 m6 l4">
<div class="card">
<div class="card-content">
<span class="card-title">Card 1</span>
<p>Content…</p>
</div>
</div>
<div class="col s12 m6 l4">
<div class="card">
<div class="card-content">
<span class="card-title">Card 2</span>
<p>Content…</p>
</div>
</div>
<div class="col s12 m6 l4">
<div class="card">
<div class="card-content">
<span class="card-title">Card 3</span>
<p>Content…</p>
</div>
</div>
</div>
Resize the browser: at widths <600px each card takes the full row (s12); between 600px and 992px they sit two per row (m6); above 992px three per row (l4). No custom CSS is required.
4. Tailoring the grid with Sass
Materialize’s default gutter is 1rem and column width is calculated as 100% / 12. If your design calls for a different spacing, adjust the Sass variables before compiling:
// _variables.scss
$grid-column-width: 6rem; // desired column width
$grid-gutter-width: 1.5rem; // desired gutter
Then rebuild the stylesheet:
sass src/materialize.scss dist/materialize.css
After recompilation, inspect the generated CSS (e.g., grep -A2 '\.row' dist/materialize.css) to confirm the new margin-left and width values match your variables.
5. Trade‑offs and limitations
- Opinionated defaults: The fixed 12‑column layout and gutter may not fit every design system; overriding requires a Sass rebuild or risky
!importantoverrides. - Browser support: Flexbox‑based grid is not available in Internet Explorer 10 and earlier. For those browsers you need a fallback grid or a polyfill.
- Namespace collisions: Because Materialize prefixes its classes with generic names (
.row,.col), mixing it with another framework can cause conflicts. Scoping the stylesheet or renaming via Sass (@import 'materialize' with ($__prefix: 'mz-');) mitigates this.
Actionable closing
Start with the default Sass build, prototype your layout using the breakpoint classes, and only adjust $grid-column-width and $grid-gutter-width when the design specification demands it. Verify the output by checking the compiled CSS for the updated values and by resizing the browser to observe the expected column changes. This approach gives you a responsive, equal‑height grid without writing custom media queries, while keeping the workflow straightforward and maintainable.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.